public void UpdateNotes(EmployeeDebt employeeDebt) { Transaction tx = null; try { using (var em = EntityManagerFactory.CreateInstance(ds)) { tx = em.BeginTransaction(); string[] fields = { "Notes", "ModifiedDate", "ModifiedBy" }; object[] values = { employeeDebt.Notes, DateTime.Now.ToShortDateString(), Store.ActiveUser }; Query q = new Query().Select(fields).From(tableName).Update(values) .Where("ID").Equal("{" + employeeDebt.ID + "}"); em.ExecuteNonQuery(q.ToSql(), tx); tx.Commit(); } } catch (Exception ex) { tx.Rollback(); throw ex; } }
private void GetEmployeeDebtById(Guid id) { EmployeeDebt employeeDebt = employeeDebtRepository.GetById(id); if (employeeDebt != null) { ViewEmployeeDebtDetail(employeeDebt); } }
private void GetLastEmployeeDebt() { EmployeeDebt employeeDebt = employeeDebtRepository.GetLast(); if (employeeDebt != null) { ViewEmployeeDebtDetail(employeeDebt); } }
private void ViewEmployeeDebtDetail(EmployeeDebt employeeDebt) { txtID.Text = employeeDebt.ID.ToString(); txtEmployeeId.Text = employeeDebt.EmployeeId.ToString(); dtpDate.Text = employeeDebt.DebtDate.ToShortDateString(); txtCode.Text = employeeDebt.Employee.EmployeeCode; txtName.Text = employeeDebt.Employee.EmployeeName; txtAmount.Text = employeeDebt.TotalAmount.ToString(); txtLongTerm.Text = employeeDebt.LongTerm.ToString(); txtInstallment.Text = employeeDebt.Installment.ToString(); chkStatus.Checked = employeeDebt.IsStatus; txtNotes.Text = employeeDebt.Notes; }
public EmployeeDebt GetLast() { EmployeeDebt employeeDebt = null; using (var em = EntityManagerFactory.CreateInstance(ds)) { var sql = "SELECT TOP 1 ed.*, " + "e.EmployeeCode, e.EmployeeName " + "FROM EmployeeDebt ed INNER JOIN Employee e ON ed.EmployeeId = e.ID " + "ORDER BY ed.DebtDate DESC, e.EmployeeCode ASC"; employeeDebt = em.ExecuteObject <EmployeeDebt>(sql, new EmployeeDebtMapper()); } return(employeeDebt); }
public EmployeeDebt GetById(Guid id) { EmployeeDebt employeeDebt = null; using (var em = EntityManagerFactory.CreateInstance(ds)) { var sql = "SELECT ed.*, " + "e.EmployeeCode, e.EmployeeName " + "FROM EmployeeDebt ed INNER JOIN Employee e ON ed.EmployeeId = e.ID " + "WHERE " + "ed.ID='{" + id + "}'"; employeeDebt = em.ExecuteObject <EmployeeDebt>(sql, new EmployeeDebtMapper()); } return(employeeDebt); }
public EmployeeDebt GetByEmployee(string employeeCode, int month, int year) { EmployeeDebt employeeDebt = null; using (var em = EntityManagerFactory.CreateInstance(ds)) { var sql = "SELECT ed.*, " + "e.EmployeeCode, e.EmployeeName " + "FROM EmployeeDebt ed INNER JOIN Employee e ON ed.EmployeeId = e.ID " + "WHERE " + "e.EmployeeCode like '%" + employeeCode + "%' " + "AND Month(ed.DebtDate)=" + month + " AND Year(ed.DebtDate)=" + year + " " + "ORDER BY ed.DebtDate DESC, e.EmployeeCode ASC"; employeeDebt = em.ExecuteObject <EmployeeDebt>(sql, new EmployeeDebtMapper()); } return(employeeDebt); }
private void RenderEmployeeDebt(EmployeeDebt employeeDebt) { var item = new ListViewItem(employeeDebt.ID.ToString()); item.SubItems.Add(employeeDebt.EmployeeId.ToString()); item.SubItems.Add(employeeDebt.Employee.EmployeeCode); item.SubItems.Add(employeeDebt.Employee.EmployeeName); item.SubItems.Add(employeeDebt.DebtDate.ToString("dd/MM/yyyy")); item.SubItems.Add(employeeDebt.TotalAmount.ToString("N0").Replace(",", ".")); item.SubItems.Add(employeeDebt.LongTerm.ToString()); item.SubItems.Add(employeeDebt.Installment.ToString("N0").Replace(",", ".")); if (employeeDebt.IsStatus == true) { item.SubItems.Add("LUNAS"); } else { item.SubItems.Add("-"); } lvwData.Items.Add(item); }
private void SaveEmployeeDebt() { if (txtCode.Text == "") { MessageBox.Show("Karyawan harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); } else if (formMode == FormMode.Add && employeeDebtRepository.IsExisted(new Guid(txtEmployeeId.Text), dtpDate.Value)) { MessageBox.Show("Karyawan : " + txtCode.Text + " - " + txtName.Text + "\n" + "Tanggal : " + dtpDate.Value.ToString("dd/MM/yyyy") + "\n\n" + "sudah ada ", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (txtAmount.Text == "" || decimal.Parse(txtAmount.Text.Replace(".", "")) == 0) { MessageBox.Show("Nilai harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); } else if (txtInstallment.Text == "" || decimal.Parse(txtInstallment.Text.Replace(".", "")) == 0) { MessageBox.Show("Cicilan harus diisi", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.Focus(); } else { EmployeeDebt employeeDebt = new EmployeeDebt(); employeeDebt.EmployeeId = new Guid(txtEmployeeId.Text); employeeDebt.DebtDate = dtpDate.Value; employeeDebt.TotalAmount = decimal.Parse(txtAmount.Text == "" ? "0" : txtAmount.Text.Replace(".", string.Empty)); employeeDebt.LongTerm = int.Parse(txtLongTerm.Text == "" ? "0" : txtLongTerm.Text.Replace(".", string.Empty)); employeeDebt.Installment = decimal.Parse(txtInstallment.Text == "" ? "0" : txtInstallment.Text.Replace(".", string.Empty)); employeeDebt.Notes = txtNotes.Text; employeeDebt.IsStatus = chkStatus.Checked; if (employeeDebt.TotalAmount > 0) { string amountInWords = Store.GetAmounInWords(Convert.ToInt32(employeeDebt.TotalAmount)); string firstLetter = amountInWords.Substring(0, 2).Trim().ToUpper(); string theRest = amountInWords.Substring(2, amountInWords.Length - 2); employeeDebt.AmountInWords = firstLetter + theRest + " rupiah"; } else { employeeDebt.AmountInWords = "Nol rupiah"; } if (formMode == FormMode.Add) { employeeDebtRepository.Save(employeeDebt); GetLastEmployeeDebt(); } else if (formMode == FormMode.Edit) { employeeDebt.ID = new Guid(txtID.Text); employeeDebtRepository.UpdateNotes(employeeDebt); } LoadEmployeeDebts(); DisableForm(); formMode = FormMode.View; this.Text = "Piutang Karyawan"; } }
public void Update(EmployeeDebt employeeDebt) { Transaction tx = null; try { using (var em = EntityManagerFactory.CreateInstance(ds)) { tx = em.BeginTransaction(); string[] fields = { "EmployeeId", "DebtDate", "TotalAmount", "LongTerm", "Installment", "AmountInWords", "Notes", "IsStatus", "ModifiedDate", "ModifiedBy" }; object[] values = { employeeDebt.EmployeeId, employeeDebt.DebtDate.ToShortDateString(), employeeDebt.TotalAmount, employeeDebt.LongTerm, employeeDebt.Installment, employeeDebt.AmountInWords, employeeDebt.Notes, employeeDebt.IsStatus == true?1:0, DateTime.Now.ToShortDateString(), Store.ActiveUser }; Query q = new Query().Select(fields).From(tableName).Update(values) .Where("ID").Equal("{" + employeeDebt.ID + "}"); em.ExecuteNonQuery(q.ToSql(), tx); employeeDebtItemRepository.Delete(employeeDebt.ID); int j = 1; for (int i = 1; i <= employeeDebt.LongTerm; i++) { EmployeeDebtItem debtItem = new EmployeeDebtItem(); debtItem.EmployeeDebtId = employeeDebt.ID; debtItem.InstallmentCounter = i; debtItem.AmountPerMonth = employeeDebt.Installment; debtItem.IsPaid = false; int debtDay = cutOffDate; int debtMonth = employeeDebt.DebtDate.Month; int debtYear = employeeDebt.DebtDate.Year; int nextMonth = debtMonth + i; int nextYear = 0; if (nextMonth > 12) { nextMonth = j; nextYear = debtYear + 1; j++; } else { nextMonth = debtMonth + i; nextYear = debtYear; } DateTime paymentDate = DateTime.Parse(nextMonth + "/" + debtDay + "/" + nextYear); debtItem.PaymentDate = paymentDate; employeeDebtItemRepository.Save(em, tx, debtItem); } tx.Commit(); } } catch (Exception ex) { tx.Rollback(); throw ex; } }