Exemple #1
0
        public void set_logs(String work_date, String time_logs, String status, Boolean new_logs)
        {
            int i = 0;

            if (update_log == false)
            {
                i = dgv_list.Rows.Add();
            }
            else
            {
                i = dgv_list.CurrentRow.Index;
            }

            DataGridViewRow row = dgv_list.Rows[i];

            row.Cells["work_date"].Value = gm.toDateString(work_date, "");
            row.Cells["time_log"].Value  = gm.toDateString(time_logs, "HH:mm");
            row.Cells["is_new"].Value    = new_logs;
            if (status == "I")
            {
                row.Cells["status"].Value = "IN";
            }
            else
            {
                row.Cells["status"].Value = "OUT";
            }
        }
        private void disp_list_history()
        {
            dgv_list.Rows.Clear();
            try
            {
                DataTable dt = db.QueryBySQLCode("SELECT sh.*, concat(firstname,' ',lastname) AS employee FROM rssys.hr_dtr_sum_hdr sh LEFT JOIN rssys.hr_employee e ON e.empid=sh.empid  ORDER BY date_generated DESC, time_generated DESC");

                if (dt.Rows.Count > 0)
                {
                    for (int r = 0; dt.Rows.Count > r; r++)
                    {
                        int             i   = dgv_list.Rows.Add();
                        DataGridViewRow row = dgv_list.Rows[i];

                        row.Cells["dgvl_date"].Value    = gm.toDateString(dt.Rows[r]["date_generated"].ToString(), "");
                        row.Cells["dgvl_time"].Value    = dt.Rows[r]["time_generated"].ToString();
                        row.Cells["dgvl_payroll"].Value = gm.toDateString(dt.Rows[r]["date_from"].ToString(), "") + " TO " + gm.toDateString(dt.Rows[r]["date_to"].ToString(), "");

                        row.Cells["dgvl_userid"].Value = dt.Rows[r]["empid"].ToString();
                        //cbo_employee.SelectedValue = dt.Rows[r]["empid"].ToString();
                        row.Cells["dgvl_employee"].Value = dt.Rows[r]["employee"].ToString();
                    }
                }
            }
            catch { }
        }
Exemple #3
0
        private String compute_overtime(String empid, String datein)
        {
            String result = "00:00:00";

            String   query = "";
            String   timein = "", timeout = "";
            String   time_from = "", time_to = "";
            TimeSpan total_late = new TimeSpan(0, 0, 0, 0, 0);

            DataTable ot_time = db.QueryBySQLCode("SELECT time_start FROM rssys.hr_ot_start");
            DataTable sched   = db.QueryBySQLCode("SELECT shift_sched_from,shift_sched_to FROM rssys.hr_employee WHERE empid = '" + empid + "'");

            if (sched.Rows.Count > 0)
            {
                time_from = sched.Rows[0]["shift_sched_from"].ToString();
                time_to   = sched.Rows[0]["shift_sched_to"].ToString();


                query = "SELECT DISTINCT e.empid,work_date,(SELECT MAX(time_log) FROM rssys.hr_tito2 st WHERE work_date=t.work_date AND status='O' AND empid=t.empid) AS timeout FROM rssys.hr_tito2 t LEFT JOIN rssys.hr_employee e ON t.empid=e.empid WHERE t.empid = '" + empid + "' AND t.work_date BETWEEN '" + gm.toDateString(datein, "") + "' AND '" + gm.toDateString(datein, "") + "' ORDER BY work_date";

                String   ot_time_start = ot_time.Rows[0]["time_start"].ToString();
                DateTime ot_start      = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy") + " " + ot_time_start);


                DataTable logs = db.QueryBySQLCode(query);
                if (logs != null && logs.Rows.Count > 0)
                {
                    for (int r = 0; r < logs.Rows.Count; r++)
                    {
                        timeout = logs.Rows[r]["timeout"].ToString();

                        DateTime datetime_out = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy") + " " + timeout);
                        DateTime datetime_to  = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy") + " " + time_to);


                        int ot_ok = DateTime.Compare(ot_start, datetime_out);
                        if (ot_ok < 0)
                        {
                            int res = DateTime.Compare(ot_start, datetime_out);

                            if (res < 0)
                            {
                                TimeSpan diff = datetime_out.Subtract(ot_start);
                                //   MessageBox.Show("Out Time : " + datetime_to + " Time Out : " + datetime_out + " Overtime : " + diff);
                                total_late = total_late + diff;
                                result     = total_late.ToString();
                            }
                        }
                    }
                }
            }

            return(result);
        }
Exemple #4
0
        private String compute_late(String empid, String date_from, String date_to)
        {
            String result = "00:00:00";

            String   query = "";
            String   timein = "", timeout = "";
            String   time_from = "", time_to = "";
            String   sat_time_from = "";
            String   sat_time_to   = "";
            TimeSpan total_late    = new TimeSpan(0, 0, 0, 0, 0);



            DataTable sched = db.QueryBySQLCode("SELECT shift_sched_from,shift_sched_to,shift_sched_sat_from,shift_sched_sat_to FROM rssys.hr_employee WHERE empid = '" + empid + "'");

            if (sched.Rows.Count > 0)
            {
                query = "SELECT DISTINCT e.empid,work_date,(SELECT MIN(time_log) FROM rssys.hr_tito2 st WHERE work_date=t.work_date AND status='I' AND empid=t.empid) AS timein, (SELECT MAX(time_log) FROM rssys.hr_tito2 st WHERE work_date=t.work_date AND status='O' AND empid=t.empid) AS timeout FROM rssys.hr_tito2 t LEFT JOIN rssys.hr_employee e ON t.empid=e.empid WHERE t.work_date BETWEEN '" + gm.toDateString(date_from, "") + "' AND '" + gm.toDateString(date_to, "") + "' AND t.empid ='" + empid + "' ORDER BY work_date";

                DataTable logs = db.QueryBySQLCode(query);

                if (logs != null && logs.Rows.Count > 0)
                {
                    for (int r = 0; r < logs.Rows.Count; r++)
                    {
                        timein = logs.Rows[r]["timein"].ToString();

                        DateTime date        = Convert.ToDateTime(logs.Rows[r]["work_date"].ToString());
                        String   day_of_week = date.DayOfWeek.ToString();

                        if (day_of_week == "Saturday")
                        {
                            time_from = sched.Rows[0]["shift_sched_sat_from"].ToString();
                        }
                        else
                        {
                            time_from = sched.Rows[0]["shift_sched_from"].ToString();
                        }

                        DateTime datetime_in = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy") + " " + timein);

                        DateTime datetime_from = Convert.ToDateTime(DateTime.Now.ToString("M/d/yyyy") + " " + time_from);

                        int res = DateTime.Compare(datetime_from, datetime_in);

                        if (res < 0)
                        {
                            TimeSpan diff = datetime_in.Subtract(datetime_from);
                            total_late = total_late + diff;
                            result     = total_late.ToString();
                        }
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        private void disp_list()
        {
            try { dgv_list.Rows.Clear(); }
            catch (Exception) { }
            int i = 0;

            DataTable dt = db.QueryBySQLCode("SELECT * from rssys.hr_leaves WHERE COALESCE(cancel,cancel,'')<>'Y' ORDER BY d_filed DESC");

            for (int r = 0; r < dt.Rows.Count; r++)
            {
                i = dgv_list.Rows.Add();
                DataGridViewRow row = dgv_list.Rows[i];

                row.Cells["dgvl_code"].Value            = dt.Rows[r]["lvcode"].ToString();
                row.Cells["dgvl_empid"].Value           = dt.Rows[r]["empid"].ToString();
                row.Cells["dgvl_leave_type_code"].Value = dt.Rows[r]["leave_type"].ToString();

                cbo_employee.SelectedValue         = row.Cells["dgvl_empid"].Value;
                row.Cells["dgvl_employee"].Value   = cbo_employee.Text;
                cbo_leave.SelectedValue            = row.Cells["dgvl_leave_type_code"].Value;
                row.Cells["dgvl_leave_type"].Value = cbo_leave.Text;

                row.Cells["dgvl_leave_pay"].Value = dt.Rows[r]["leave_pay"].ToString();

                row.Cells["dgvl_d_filed"].Value    = gm.toDateString(dt.Rows[r]["d_filed"].ToString(), "");
                row.Cells["dgvl_leave_from"].Value = gm.toDateString(dt.Rows[r]["leave_from"].ToString(), "");
                row.Cells["dgvl_lfrm_am"].Value    = Convert.ToBoolean(dt.Rows[r]["frm_am"].ToString()) ? "✔" : "";
                row.Cells["dgvl_lfrm_pm"].Value    = Convert.ToBoolean(dt.Rows[r]["frm_pm"].ToString()) ? "✔" : "";
                row.Cells["dgvl_leave_to"].Value   = gm.toDateString(dt.Rows[r]["leave_to"].ToString(), "");
                row.Cells["dgvl_lto_am"].Value     = Convert.ToBoolean(dt.Rows[r]["to_am"].ToString()) ? "✔" : "";
                row.Cells["dgvl_lto_pm"].Value     = Convert.ToBoolean(dt.Rows[r]["to_pm"].ToString()) ? "✔" : "";


                row.Cells["dgvl_amount"].Value = gm.toNormalDoubleFormat(dt.Rows[r]["leave_amount"].ToString()).ToString("0.00");

                row.Cells["dgvl_no_of_days"].Value = dt.Rows[r]["no_of_days"].ToString();

                //✔
                i++;
            }
        }
Exemple #6
0
        private void disp_list()
        {
            try { dgv_list.Rows.Clear(); }
            catch (Exception) { }
            int i = 0;

            DataTable dt = db.QueryBySQLCode("SELECT * from rssys.hr_contri_remittance WHERE COALESCE(cancel,cancel,'')<>'Y'");

            for (int r = 0; r < dt.Rows.Count; r++)
            {
                i = dgv_list.Rows.Add();
                DataGridViewRow row = dgv_list.Rows[i];

                row.Cells["dgvl_code"].Value     = dt.Rows[r]["crcode"].ToString();
                row.Cells["dgvl_month"].Value    = dt.Rows[r]["month"].ToString();
                row.Cells["dgvl_sbr"].Value      = dt.Rows[r]["sbr"].ToString();
                row.Cells["dgvl_sbr_date"].Value = gm.toDateString(dt.Rows[r]["sbr_date"].ToString(), "");
                row.Cells["dgvl_pbr"].Value      = dt.Rows[r]["pbr"].ToString();
                row.Cells["dgvl_pbr_date"].Value = gm.toDateString(dt.Rows[r]["pbr_date"].ToString(), "");
                row.Cells["dgvl_pr"].Value       = dt.Rows[r]["pr"].ToString();
                row.Cells["dgvl_pr_date"].Value  = gm.toDateString(dt.Rows[r]["pr_date"].ToString(), "");
            }
        }
Exemple #7
0
        private void bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            String    query = "", empid = "", date_from = "", date_to = "", pay_code = "", table = "hr_rpt_files", filename = "", code = "", col = "", val = "", date_in = "";
            DataTable pay_period = null;
            Double    total = 0.00, ee = 0.00, er = 0.00, ec = 0.00;

            query = "SELECT empid, firstname, lastname,pay_rate FROM rssys.hr_employee";
            cbo_employee.Invoke(new Action(() => {
                if (cbo_employee.SelectedIndex != -1)
                {
                    empid  = cbo_employee.SelectedValue.ToString();
                    query += " WHERE empid='" + empid + "'";
                }
            }));

            query += " ORDER BY empid ASC";

            DataTable employees = db.QueryBySQLCode(query);

            cbo_payollperiod.Invoke(new Action(() => {
                pay_code = cbo_payollperiod.SelectedValue.ToString();
            }));

            pay_period = get_date(pay_code);

            if (pay_period.Rows.Count > 0)
            {
                date_from = gm.toDateString(pay_period.Rows[0]["date_from"].ToString(), "yyyy-MM-dd");
                date_to   = gm.toDateString(pay_period.Rows[0]["date_to"].ToString(), "yyyy-MM-dd");
            }

            filename  = RandomString(5) + "_" + DateTime.Now.ToString("yyyy-MM-dd");
            filename += ".pdf";


            //System.IO.FileStream fs = new FileStream("\\\\RIGHTAPPS\\RightApps\\Eastland\\payroll_reports\\hdmf_summary\\" + filename, FileMode.Create);
            System.IO.FileStream fs = new FileStream(fileloc_dtr + "\\ViewController\\RPT\\Payroll\\hdmf_summary\\" + filename, FileMode.Create);

            Document document = new Document(PageSize.LEGAL);

            PdfWriter.GetInstance(document, fs);
            document.Open();

            BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL);

            Paragraph paragraph = new Paragraph();

            paragraph.Alignment = Element.ALIGN_CENTER;
            paragraph.Font      = FontFactory.GetFont("Arial", 12);
            paragraph.SetLeading(1, 1);
            paragraph.Add("HDMF DEDUCTIONS REPORTS SUMMARY");


            Phrase line_break = new Phrase("\n");

            document.Add(paragraph);
            document.Add(line_break);

            Paragraph paragraph_2 = new Paragraph();

            paragraph_2.Alignment = Element.ALIGN_CENTER;
            paragraph_2.Font      = FontFactory.GetFont("Arial", 12);
            paragraph_2.SetLeading(1, 1);
            paragraph_2.Add("For the payroll period " + date_from + " to " + date_to);


            Phrase line_break_2 = new Phrase("\n");

            document.Add(paragraph_2);
            document.Add(line_break_2);



            PdfPTable t = new PdfPTable(1);

            float[] widths = new float[] { 100 };
            t.WidthPercentage = 100;
            t.SetWidths(widths);

            PdfPTable dis_earnings = new PdfPTable(4);

            float[] _w2 = new float[] { 70, 50, 50, 50 };
            dis_earnings.SetWidths(_w2);
            dis_earnings.AddCell(new PdfPCell(new Paragraph("Employee Name"))
            {
                Border = 2
            });
            dis_earnings.AddCell(new PdfPCell(new Paragraph("EmployeE Share"))
            {
                Border = 2
            });
            dis_earnings.AddCell(new PdfPCell(new Paragraph("EmployeR Share"))
            {
                Border = 2
            });
            dis_earnings.AddCell(new PdfPCell(new Paragraph("Total Contribution"))
            {
                Border = 2
            });

            foreach (DataRow _employees in employees.Rows)
            {
                total = 0;
                ee    = 0;
                er    = 0;
                String fname   = _employees["firstname"].ToString();
                String lname   = _employees["lastname"].ToString();
                String empno   = _employees["empid"].ToString();
                Double payrate = Convert.ToDouble(_employees["pay_rate"].ToString());
                try
                {
                    if (payrate < 5000.00)
                    {
                        if (payrate <= 1500.00)
                        {
                            ee = (1 / 100) * payrate;
                            er = (2 / 100) * payrate;
                        }
                        else if (payrate > 1500.00)
                        {
                            ee = (2 / 100) * payrate;
                            er = (2 / 100) * payrate;
                        }
                    }
                    if (payrate >= 5000.00)
                    {
                        ee = 100;
                        er = 100;
                    }
                    total = ee + er;
                    dis_earnings.AddCell(new PdfPCell(new Paragraph(fname + " " + lname))
                    {
                        Border = 0
                    });
                    dis_earnings.AddCell(new PdfPCell(new Paragraph(ee.ToString("0.00")))
                    {
                        Border = 0
                    });
                    dis_earnings.AddCell(new PdfPCell(new Paragraph(er.ToString("0.00")))
                    {
                        Border = 0
                    });
                    dis_earnings.AddCell(new PdfPCell(new Paragraph(total.ToString("0.00")))
                    {
                        Border = 0
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            document.Add(dis_earnings);
            document.Add(t);
            document.Close();

            code = db.get_pk("rpt_id");
            col  = "rpt_id,filename,date_added,rpt_type";
            val  = "'" + code + "','" + filename + "','" + DateTime.Now.ToShortDateString() + "','HDMF'";

            if (db.InsertOnTable(table, col, val))
            {
                db.set_pkm99("rpt_id", db.get_nextincrementlimitchar(code, 8)); //changes from 'hr_empid'
                MessageBox.Show("New summary reports created");
            }
            else
            {
                MessageBox.Show("Failed on saving.");
            }
            pic_loading.Invoke(new Action(() => {
                pic_loading.Visible = false;
                btn_submit.Enabled  = true;
            }));

            display_list();
        }
Exemple #8
0
        private void bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            String    query = "", dept_query = "", deptid = "", empid = "", date_from = "", date_to = "", pay_code = "", table = "hr_rpt_files", filename = "", code = "", col = "", val = "", date_in = "";
            DataTable pay_period = null;
            Double    total = 0.00, ee = 0.00, er = 0.00, ec = 0.00;

            query      = "SELECT empid, firstname, lastname,mi,pay_rate,department FROM rssys.hr_employee";
            dept_query = "SELECT deptid FROM rssys.hr_department";

            cbo_employee.Invoke(new Action(() => {
                if (cbo_employee.SelectedIndex != -1)
                {
                    empid  = cbo_employee.SelectedValue.ToString();
                    query += " WHERE empid='" + empid + "'";
                }
            }));

            cbo_department.Invoke(new Action(() =>
            {
                if (cbo_department.SelectedIndex != -1)
                {
                    deptid      = cbo_department.SelectedValue.ToString();
                    dept_query += " WHERE deptid = '" + deptid + "' LIMIT 1";
                }
            }));
            query += " ORDER BY empid ASC";

            DataTable departments = db.QueryBySQLCode(dept_query);
            DataTable employees   = db.QueryBySQLCode(query);

            cbo_payollperiod.Invoke(new Action(() => {
                pay_code = cbo_payollperiod.SelectedValue.ToString();
            }));

            pay_period = get_date(pay_code);

            if (pay_period.Rows.Count > 0)
            {
                date_from = gm.toDateString(pay_period.Rows[0]["date_from"].ToString(), "yyyy-MM-dd");
                date_to   = gm.toDateString(pay_period.Rows[0]["date_to"].ToString(), "yyyy-MM-dd");
            }

            filename  = RandomString(5) + "_" + DateTime.Now.ToString("yyyy-MM-dd");
            filename += ".pdf";


            //System.IO.FileStream fs = new FileStream("\\\\RIGHTAPPS\\RightApps\\Eastland\\payroll_reports\\payroll_summary\\" + filename, FileMode.Create);
            System.IO.FileStream fs = new FileStream(fileloc_dtr + "\\ViewController\\RPT\\Payroll\\payroll_summary\\" + filename, FileMode.Create);

            Document document = new Document(PageSize.LEGAL.Rotate());

            PdfWriter.GetInstance(document, fs);
            document.Open();

            document.Add(new Paragraph("SUGBU REALTY, INC", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 11f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_LEFT
            });

            document.Add(new Paragraph("PAYROLL PERIOD", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 11f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_LEFT
            });

            document.Add(new Chunk("\n"));

            PdfPTable _thead = new PdfPTable(13);

            _thead.WidthPercentage = 100f;
            float[] columnWidths = { 100, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 };
            _thead.SetWidths(columnWidths);



            _thead.AddCell(new PdfPCell(new Paragraph("Employee", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Rate", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Basic Pay", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Late/UT", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Overtime", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Gross Pay", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Earnings", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Deductions", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("SSS", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("PHIC", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("HDMF", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("With-Tax-C", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });
            _thead.AddCell(new PdfPCell(new Paragraph("Net Pay", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
            {
                Alignment = Element.ALIGN_CENTER
            })
            {
                HorizontalAlignment = Element.ALIGN_CENTER
            });

            cbo_employee.Invoke(new Action(() =>
            {
                if (cbo_employee.SelectedIndex != -1)
                {
                    foreach (DataRow _emp in employees.Rows)
                    {
                        DataTable emp_dept    = db.QueryBySQLCode("SELECT * FROM rssys.hr_department WHERE deptid='" + _emp["department"].ToString() + "' LIMIT 1");
                        DataTable emp_payroll = db.QueryBySQLCode("SELECT * FROM rssys.hr_emp_payroll WHERE empid = '" + _emp["empid"].ToString() + "'");

                        _thead.AddCell(new PdfPCell(new Paragraph(emp_dept.Rows[0]["dept_name"].ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLDITALIC))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_LEFT
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });


                        Double pay_rate  = Convert.ToDouble(_emp["pay_rate"].ToString());
                        Double basic_pay = Convert.ToDouble(emp_payroll.Rows[0]["basic_pay"].ToString());
                        Double late_ut   = Convert.ToDouble(emp_payroll.Rows[0]["late_ut"].ToString());



                        _thead.AddCell(new PdfPCell(new Paragraph(_emp["lastname"].ToString() + ", " + _emp["firstname"].ToString() + " " + _emp["mi"].ToString(), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.NORMAL))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_LEFT
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph(pay_rate.ToString("N", new CultureInfo("en-US")), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_RIGHT
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph(basic_pay.ToString("N", new CultureInfo("en-US")), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_RIGHT
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("-" + late_ut.ToString("N", new CultureInfo("en-US")), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        _thead.AddCell(new PdfPCell(new Paragraph("", new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10f, iTextSharp.text.Font.BOLD))
                        {
                            Alignment = Element.ALIGN_CENTER
                        })
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });


                        //DataTable _emp_payroll = db.QueryBySQLCode("SELECT ");
                    }
                }
            }));


            document.Add(_thead);


            document.Close();
            code = db.get_pk("rpt_id");
            col  = "rpt_id,filename,date_added,rpt_type";
            val  = "'" + code + "','" + filename + "','" + DateTime.Now.ToShortDateString() + "','PAYROLL_SUMMARY'";

            if (db.InsertOnTable(table, col, val))
            {
                db.set_pkm99("rpt_id", db.get_nextincrementlimitchar(code, 8)); //changes from 'hr_empid'
                MessageBox.Show("New summary reports created");
            }
            else
            {
                MessageBox.Show("Failed on saving.");
            }
            pic_loading.Invoke(new Action(() => {
                pic_loading.Visible = false;
                btn_submit.Enabled  = true;
            }));

            display_list();
        }
        private void bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            String    query = "", empid = "", date_from = "", date_to = "", pay_code = "", table = "hr_dtr_files", filename = "", code = "", col = "", val = "", date_in = "";
            DataTable pay_period = null;


            query = "SELECT empid, firstname, lastname FROM rssys.hr_employee";
            cbo_employee.Invoke(new Action(() => {
                if (cbo_employee.SelectedIndex != -1)
                {
                    empid  = cbo_employee.SelectedValue.ToString();
                    query += " WHERE empid='" + empid + "'";
                }
            }));

            query += " ORDER BY empid ASC";

            DataTable employees = db.QueryBySQLCode(query);

            cbo_payollperiod.Invoke(new Action(() => {
                pay_code = cbo_payollperiod.SelectedValue.ToString();
            }));

            pay_period = get_date(pay_code);

            if (pay_period.Rows.Count > 0)
            {
                date_from = gm.toDateString(pay_period.Rows[0]["date_from"].ToString(), "yyyy-MM-dd");
                date_to   = gm.toDateString(pay_period.Rows[0]["date_to"].ToString(), "yyyy-MM-dd");
            }
            DateTime StartDate = DateTime.Parse(date_from);
            DateTime EndDate   = DateTime.Parse(date_to);

            try
            {
                filename  = RandomString(5) + "_" + DateTime.Now.ToString("yyyy-MM-dd");
                filename += ".pdf";

                //System.IO.FileStream fs = new FileStream("\\\\RIGHTAPPS\\RightApps\\Eastland\\payroll_reports\\dtr\\" + filename, FileMode.Create);

                System.IO.FileStream fs       = new FileStream(fileloc_dtr + "\\ViewController\\RPT\\TimeKeeping\\dtr_pdf\\" + filename, FileMode.Create);
                Document             document = new Document(PageSize.LEGAL, 25, 25, 30, 30);

                PdfWriter.GetInstance(document, fs);
                document.Open();
                if (employees.Rows.Count > 0)
                {
                    for (int r = 0; r < employees.Rows.Count; r++)
                    {
                        Paragraph paragraph = new Paragraph();
                        paragraph.Alignment = Element.ALIGN_CENTER;
                        paragraph.Font      = FontFactory.GetFont("Arial", 12);
                        paragraph.SetLeading(1, 1);
                        paragraph.Add("DAILY TIME RECORD");
                        Phrase line_break = new Phrase("\n");
                        document.Add(paragraph);
                        document.Add(line_break);

                        empid = employees.Rows[r]["empid"].ToString();



                        Paragraph emp_name = new Paragraph();
                        emp_name.Alignment = Element.ALIGN_CENTER;
                        emp_name.Font      = FontFactory.GetFont("Arial", 8);
                        emp_name.SetLeading(1, 1);
                        emp_name.Add(employees.Rows[r]["firstname"].ToString() + " " + employees.Rows[r]["lastname"].ToString());
                        document.Add(emp_name);

                        Paragraph horizontal_line = new Paragraph();
                        horizontal_line.Alignment = Element.ALIGN_CENTER;
                        horizontal_line.Font      = FontFactory.GetFont("Arial", 10);
                        horizontal_line.SetLeading(1, 1);
                        horizontal_line.Add("--------------------------------------------------------------------------------------");
                        document.Add(horizontal_line);

                        Paragraph label_name = new Paragraph();
                        label_name.Alignment = Element.ALIGN_CENTER;
                        label_name.SetLeading(1, 1);
                        label_name.Font = FontFactory.GetFont("Arial", 8);
                        label_name.Add("Name");

                        document.Add(label_name);

                        Phrase line_break_1 = new Phrase("\n");
                        line_break_1.SetLeading(0.5f, 0.5f);
                        document.Add(line_break_1);

                        PdfPTable t      = new PdfPTable(9);
                        float[]   widths = new float[] { 10, 20, 20, 20, 20, 20, 20, 20, 20 };
                        t.WidthPercentage = 100;
                        t.SetWidths(widths);
                        t.AddCell(new PdfPCell(new Phrase("DATE"))
                        {
                            Colspan = 2, Rowspan = 2, HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("AM"))
                        {
                            Colspan = 2, HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("PM"))
                        {
                            Colspan = 2, HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("UT/OT"))
                        {
                            Colspan = 3, HorizontalAlignment = Element.ALIGN_CENTER
                        });



                        t.AddCell(new PdfPCell(new Phrase("IN"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("OUT"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("IN"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("OUT"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("LATE"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("UT"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });
                        t.AddCell(new PdfPCell(new Phrase("OT"))
                        {
                            HorizontalAlignment = Element.ALIGN_CENTER
                        });



                        query = "SELECT DISTINCT CONCAT(lastname,' ',firstname) AS name, t.source, e.empid, to_char(work_date, 'yyyy-MM-dd') AS work_date, (SELECT MIN(time_log) FROM rssys.hr_tito2 st WHERE work_date=t.work_date AND status='I' AND empid=t.empid) AS timein, (SELECT MAX(time_log) FROM rssys.hr_tito2 st WHERE work_date=t.work_date AND status='O' AND empid=t.empid) AS timeout FROM rssys.hr_tito2 t LEFT JOIN rssys.hr_employee e ON t.empid=e.empid WHERE e.empid = '" + empid + "' AND t.work_date BETWEEN '" + date_from + "' AND '" + date_to + "' ORDER BY work_date ";


                        DataTable dt = db.QueryBySQLCode(query);

                        String date_name = "", am_in = "", am_out = "", pm_in = "", pm_out = "", log_date = "", late = "", ut = "", ot_total = "";
                        int    index = 0;

                        foreach (DateTime day in EachDay(StartDate, EndDate))
                        {
                            if (index != dt.Rows.Count)
                            {
                                if (day.ToShortDateString() == DateTime.Parse(dt.Rows[index]["work_date"].ToString()).ToShortDateString())
                                {
                                    log_date = DateTime.Parse(dt.Rows[index]["work_date"].ToString()).ToShortDateString();
                                    am_in    = dt.Rows[index]["timein"].ToString();
                                    pm_out   = dt.Rows[index]["timeout"].ToString();
                                    index++;
                                }
                            }
                            date_name = day.ToString("MMM d, yyyy ddd", CultureInfo.InvariantCulture);

                            if (day.ToShortDateString() != log_date)
                            {
                                am_in  = "";
                                pm_out = "";
                            }

                            t.AddCell(new PdfPCell(new Phrase(date_name))
                            {
                                Colspan = 2, HorizontalAlignment = Element.ALIGN_LEFT
                            });
                            t.AddCell(new PdfPCell(new Phrase(am_in))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });
                            t.AddCell(new PdfPCell(new Phrase(""))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });
                            t.AddCell(new PdfPCell(new Phrase(""))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });
                            t.AddCell(new PdfPCell(new Phrase(pm_out))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });
                            if (am_in != "")
                            {
                                late = compute_late(empid, am_in, day.ToShortDateString());
                            }
                            else
                            {
                                late = "";
                            }


                            t.AddCell(new PdfPCell(new Phrase(late))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });
                            if (pm_out != "")
                            {
                                ut = compute_undertime(empid, pm_out, day.ToShortDateString());
                            }
                            else
                            {
                                ut = "";
                            }



                            t.AddCell(new PdfPCell(new Phrase(ut))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });

                            if (pm_out != "")
                            {
                                ot_total = compute_overtime(empid, pm_out, day.ToString("yyyy-MM-dd"));
                            }

                            t.AddCell(new PdfPCell(new Phrase(ot_total))
                            {
                                HorizontalAlignment = Element.ALIGN_CENTER
                            });
                            ut       = "";
                            late     = "";
                            am_in    = "";
                            pm_out   = "";
                            ot_total = "";
                        }

                        document.Add(t);
                        document.NewPage();
                    }
                }


                document.Close();
                code = db.get_pk("dtr_id");
                col  = "dtr_id,filename,date_created";
                val  = "'" + code + "','" + filename + "','" + DateTime.Now.ToShortDateString() + "'";

                if (db.InsertOnTable(table, col, val))
                {
                    db.set_pkm99("dtr_id", db.get_nextincrementlimitchar(code, 8)); //changes from 'hr_empid'
                    MessageBox.Show("DTR PRINTED");
                }
                else
                {
                    MessageBox.Show("Failed on saving.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Program Error. \n Please contact the software provider. \n " + ex.Message + "at Line : " + ex.StackTrace);
            }
            //bgworker.RunWorkerAsync();
            pic_loading.Invoke(new Action(() => {
                pic_loading.Visible = false;
            }));

            btn_submit.Invoke(new Action(() => {
                btn_submit.Enabled = true;
            }));
            display_list();
        }
        private void bgworker_DoWork(object sender, DoWorkEventArgs e)
        {
            String    query = "", empid = "", date_from = "", date_to = "", pay_code = "", table = "hr_other_deductions_files", filename = "", code = "", col = "", val = "", date_in = "";
            DataTable pay_period = null;


            query = "SELECT empid, firstname, lastname FROM rssys.hr_employee";
            cbo_employee.Invoke(new Action(() => {
                if (cbo_employee.SelectedIndex != -1)
                {
                    empid  = cbo_employee.SelectedValue.ToString();
                    query += " WHERE empid='" + empid + "'";
                }
            }));

            query += " ORDER BY empid ASC";

            DataTable employees = db.QueryBySQLCode(query);

            cbo_payollperiod.Invoke(new Action(() => {
                pay_code = cbo_payollperiod.SelectedValue.ToString();
            }));

            pay_period = get_date(pay_code);

            if (pay_period.Rows.Count > 0)
            {
                date_from = gm.toDateString(pay_period.Rows[0]["date_from"].ToString(), "yyyy-MM-dd");
                date_to   = gm.toDateString(pay_period.Rows[0]["date_to"].ToString(), "yyyy-MM-dd");
            }

            filename  = RandomString(5) + "_" + DateTime.Now.ToString("yyyy-MM-dd");
            filename += ".pdf";


            //System.IO.FileStream fs = new FileStream("\\\\RIGHTAPPS\\RightApps\\Eastland\\payroll_reports\\other_deductions\\" + filename, FileMode.Create);
            System.IO.FileStream fs = new FileStream(fileloc_dtr + "\\ViewController\\RPT\\Payroll\\other_deductions\\" + filename, FileMode.Create);

            Document document = new Document(PageSize.LEGAL, 25, 25, 30, 30);

            PdfWriter.GetInstance(document, fs);
            document.Open();

            BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL);

            Paragraph paragraph = new Paragraph();

            paragraph.Alignment = Element.ALIGN_CENTER;
            paragraph.Font      = FontFactory.GetFont("Arial", 12);
            paragraph.SetLeading(1, 1);
            paragraph.Add("OTHER DEDUCTIONS SUMMARY");


            Phrase line_break = new Phrase("\n");

            document.Add(paragraph);
            document.Add(line_break);

            Paragraph paragraph_2 = new Paragraph();

            paragraph_2.Alignment = Element.ALIGN_CENTER;
            paragraph_2.Font      = FontFactory.GetFont("Arial", 12);
            paragraph_2.SetLeading(1, 1);
            paragraph_2.Add("For the payroll period " + date_from + " to " + date_to);


            Phrase line_break_2 = new Phrase("\n");

            document.Add(paragraph_2);
            document.Add(line_break_2);



            PdfPTable t = new PdfPTable(1);

            float[] widths = new float[] { 100 };
            t.WidthPercentage = 100;
            t.SetWidths(widths);

            PdfPTable dis_earnings = new PdfPTable(2);

            float[] _w2 = new float[] { 50, 50 };
            dis_earnings.SetWidths(_w2);

            foreach (DataRow _employees in employees.Rows)
            {
                String fname = _employees["firstname"].ToString();
                String lname = _employees["lastname"].ToString();
                String empno = _employees["empid"].ToString();
                try
                {
                    DataTable has_earnings = db.QueryBySQLCode("SELECT emp_no FROM rssys.hr_deduction_entry WHERE emp_no = '" + empno + "'");
                    if (has_earnings != null && has_earnings.Rows.Count > 0)
                    {
                        dis_earnings.AddCell(new PdfPCell(new Paragraph(fname + " " + lname))
                        {
                            Colspan = 2, Border = 2
                        });

                        DataTable hoe = db.QueryBySQLCode("SELECT DISTINCT(od.code) as code,od.description  FROM rssys.hr_deduction_entry de  LEFT JOIN rssys.hr_other_deductions od  ON de.deduction_code = od.code WHERE de.emp_no = '" + empno + "'");

                        foreach (DataRow _hoe in hoe.Rows)
                        {
                            dis_earnings.AddCell(new PdfPCell(new Paragraph(_hoe["description"].ToString()))
                            {
                                PaddingLeft = 30f, Colspan = 2, Border = 0
                            });
                            DataTable hee = db.QueryBySQLCode("SELECT * FROM rssys.hr_deduction_entry WHERE deduction_code = '" + _hoe["code"].ToString() + "' AND payroll_period = '" + pay_code + "' AND emp_no = '" + empno + "'");
                            foreach (DataRow _hee in hee.Rows)
                            {
                                dis_earnings.AddCell(new PdfPCell(new Paragraph(_hee["amount"].ToString()))
                                {
                                    PaddingLeft = 40f, Colspan = 2, Border = 0
                                });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            document.Add(dis_earnings);
            document.Add(t);
            document.Close();

            code = db.get_pk("deductions_id");
            col  = "deductions_id,filename,date_added";
            val  = "'" + code + "','" + filename + "','" + DateTime.Now.ToShortDateString() + "'";

            if (db.InsertOnTable(table, col, val))
            {
                db.set_pkm99("deductions_id", db.get_nextincrementlimitchar(code, 8)); //changes from 'hr_empid'
                MessageBox.Show("New Other Earnings Summary added.");
            }
            else
            {
                MessageBox.Show("Failed on saving.");
            }
            pic_loading.Invoke(new Action(() => {
                pic_loading.Visible = false;
                btn_submit.Enabled  = true;
            }));

            display_list();
        }
        private void disp_schedule()
        {
            dgv_list.Rows.Clear();

            int i = 0;

            try
            {
                if (cbo_employee.SelectedIndex != -1)
                {
                    String empid     = cbo_employee.SelectedValue.ToString();
                    String date_from = dtp_frm.Value.ToString("yyyy-MM-dd");
                    String date_to   = dtp_to.Value.ToString("yyyy-MM-dd");

                    DataTable dt = db.QueryBySQLCode("SELECT * FROM rssys.hr_work_schedule WHERE wrk_date BETWEEN '" + date_from + "' AND '" + date_to + "' AND empid ='" + empid + "' ORDER BY wrk_date ASC");
                    if (dt != null)
                    {
                        for (int r = 0; r < dt.Rows.Count; r++)
                        {
                            i = dgv_list.Rows.Add();
                            DataGridViewRow row = dgv_list.Rows[i];

                            row.Cells["dgvl_code"].Value = dt.Rows[r]["code"].ToString();

                            row.Cells["dgvl_date"].Value            = gm.toDateString(dt.Rows[r]["wrk_date"].ToString(), "");
                            row.Cells["dgvl_day"].Value             = dt.Rows[r]["wrk_day"].ToString();
                            row.Cells["dgvl_dayn"].Value            = dt.Rows[r]["wrk_dayn"].ToString();
                            row.Cells["dgvl_shift_sched"].Value     = dt.Rows[r]["shift_sched"].ToString();
                            row.Cells["dgvl_shiftsched_code"].Value = dt.Rows[r]["shiftsched_code"].ToString();
                            row.Cells["dgvl_timein1"].Value         = dt.Rows[r]["timein1"].ToString();
                            row.Cells["dgvl_timein2"].Value         = dt.Rows[r]["timein2"].ToString();
                            row.Cells["dgvl_timeout1"].Value        = dt.Rows[r]["timeout1"].ToString();
                            row.Cells["dgvl_timeout2"].Value        = dt.Rows[r]["timeout2"].ToString();
                            row.Cells["dgvl_restday"].Value         = dt.Rows[r]["restday"].ToString();
                            row.Cells["dgvl_otin"].Value            = dt.Rows[r]["ot_in"].ToString();
                            row.Cells["dgvl_otout"].Value           = dt.Rows[r]["ot_out"].ToString();
                        }
                        if (dt.Rows.Count == 0)
                        {
                            MessageBox.Show("Empty schedule.");
                        }
                    }
                }
            }
            catch { MessageBox.Show("Please select an employee."); }

            /*
             * try { dgv_list.Rows.Clear(); }
             * catch (Exception) { }
             *
             * int i = 0;
             * String date_from = dtp_frm.Value.ToString("yyyy-MM-dd");
             * String date_to = dtp_to.Value.ToString("yyyy-MM-dd");
             *
             * String empid = cbo_employee.SelectedValue.ToString();
             *
             * DataTable dt = db.QueryBySQLCode("SELECT to_char(work_date, 'dd/MM/yyyy') AS work_date, time_log, status, source FROM rssys.hr_tito2 WHERE work_date BETWEEN '" + date_from + "' AND '" + date_to + "' AND empid ='" + empid + "'");
             *
             * for (int r = 0; r < dt.Rows.Count; r++)
             * {
             *  i = dgv_list.Rows.Add();
             *  DataGridViewRow row = dgv_list.Rows[i];
             *
             *  row.Cells["work_date"].Value = dt.Rows[r]["work_date"].ToString();
             *  row.Cells["time_log"].Value = dt.Rows[r]["time_log"].ToString();
             *
             *  if (dt.Rows[r]["status"].ToString() == "I")
             *  {
             *      row.Cells["status"].Value = "IN";
             *  }
             *  else
             *  {
             *      row.Cells["status"].Value = "OUT";
             *  }
             *
             *  if (dt.Rows[r]["source"].ToString() == "M")
             *  {
             *      row.Cells["source"].Value = "Manual";
             *  }
             *  i++;
             * }*/
        }