public async Task <IActionResult> Edit(int id, [Bind("Id,Date,PaymentAmount,UserId")] DebtPayment debtPayment) { if (id != debtPayment.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(debtPayment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DebtPaymentExists(debtPayment.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Address", debtPayment.UserId); return(View(debtPayment)); }
public void Update(DebtPayment debtPayment) { Transaction tx = null; try { using (var em = EntityManagerFactory.CreateInstance(ds)) { tx = em.BeginTransaction(); string[] columns = { "PaymentDate", "TotalCash", "TotalBank", "TotalGiro", "TotalCorrection", "Notes", "ModifiedDate", "ModifiedBy" }; object[] values = { debtPayment.PaymentDate, debtPayment.TotalCash, debtPayment.TotalBank, debtPayment.TotalGiro, debtPayment.TotalCorrection, debtPayment.Notes, DateTime.Now.ToShortDateString(), Store.ActiveUser }; var q = new Query().Select(columns).From(tableName).Update(values) .Where("ID").Equal("{" + debtPayment.ID + "}"); em.ExecuteNonQuery(q.ToSql(), tx); ////detail dihapus -> update status = false var list = debtPaymentItemRepository.GetByDebtPaymentId(debtPayment.ID); foreach (var debtItem in list) { purchaseRepository.UpdateStatus(em, tx, debtItem.PurchaseId, false); debtBalanceRepository.UpdateStatusFromPayment(em, tx, debtItem.Purchase.Code, false); } debtPaymentItemRepository.Delete(em, tx, debtPayment.ID); foreach (var debtPaymentItem in debtPayment.DebtPaymentItems) { debtPaymentItem.DebtPaymentId = debtPayment.ID; debtPaymentItemRepository.Save(em, tx, debtPaymentItem); //update status = lunas purchaseRepository.UpdateStatus(em, tx, debtPaymentItem.PurchaseId, true); //update status = lunas debtBalanceRepository.UpdateStatusFromPayment(em, tx, debtPaymentItem.Purchase.Code, true); } UpdateGrandTotal(em, tx, debtPayment.ID, debtPayment.GrandTotal); tx.Commit(); } } catch (Exception ex) { tx.Rollback(); throw ex; } }
private void ValidateNegativeValue(DebtPayment reg) { if (reg.Value < 0) { throw new Exception("Não é permitido valor negativo."); } }
public void Map(DebtPayment reg, DebtPaymentDto dto) { reg.DebtId = dto.DebtId; reg.Debt = Context.Debts.Find(dto.DebtId); reg.Date = dto.Date; reg.Value = dto.Value; }
private void ViewDebtPaymentDetail(DebtPayment debtPayment) { txtID.Text = debtPayment.ID.ToString(); txtDebtPaymentId.Text = debtPayment.ID.ToString(); lblCode.Text = debtPayment.PaymentCode; dtpDate.Text = debtPayment.PaymentDate.ToShortDateString(); txtNotes.Text = debtPayment.Notes; }
public void Delete(DebtPayment debtPayment) { Transaction tx = null; try { using (var em = EntityManagerFactory.CreateInstance(ds)) { tx = em.BeginTransaction(); String notes = ""; if (debtPayment.Notes != "") { notes = "DIBATALKAN - " + debtPayment.Notes; } else { notes = "DIBATALKAN"; } string[] columns = { "TotalCash", "TotalBank", "TotalGiro", "TotalCorrection", "GrandTotal", "Notes", "ModifiedDate", "ModifiedBy" }; object[] values = { 0, 0, 0, 0, 0, notes, DateTime.Now.ToShortDateString(), Store.ActiveUser }; var q = new Query().Select(columns).From(tableName).Update(values) .Where("ID").Equal(debtPayment.ID); em.ExecuteNonQuery(q.ToSql(), tx); var itemList = debtPaymentItemRepository.GetByDebtPaymentId(debtPayment.ID); foreach (var debtPaymentItem in itemList) { debtPaymentItemRepository.Delete(em, tx, debtPaymentItem); } foreach (var item in itemList) { //update status = lunas purchaseRepository.UpdateStatus(em, tx, item.PurchaseId, false); //update status = lunas debtBalanceRepository.UpdateStatusFromPayment(em, tx, item.Purchase.Code, false); } tx.Commit(); } } catch (Exception ex) { tx.Rollback(); throw ex; } }
public static DebtPaymentView New(DebtPayment reg) { return(new DebtPaymentView() { Id = reg.Id, DebtId = reg.DebtId, Date = reg.Date, Value = reg.Value, Status = reg.Status, }); }
public async Task <IActionResult> Create([Bind("Id,Date,PaymentAmount,UserId")] DebtPayment debtPayment) { if (ModelState.IsValid) { _context.Add(debtPayment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_context.Users, "Id", "Address", debtPayment.UserId); return(View(debtPayment)); }
private void PopulateDebtPayment(DebtPayment debtPayment) { var item = new ListViewItem(debtPayment.ID.ToString()); item.SubItems.Add(debtPayment.PaymentDate.ToString("dd/MM/yyyy")); item.SubItems.Add(debtPayment.PaymentCode); item.SubItems.Add(debtPayment.GrandTotal.ToString("N0").Replace(",", ".")); item.SubItems.Add(debtPayment.CreatedDate.ToString("dd/MM/yyyy")); item.SubItems.Add(debtPayment.CreatedBy); item.SubItems.Add(debtPayment.ModifiedDate.ToString("dd/MM/yyyy")); item.SubItems.Add(debtPayment.ModifiedBy); lvwDebtPayment.Items.Add(item); }
public void Save(DebtPayment debtPayment) { Transaction tx = null; try { using (var em = EntityManagerFactory.CreateInstance(ds)) { tx = em.BeginTransaction(); Guid ID = Guid.NewGuid(); string[] columns = { "ID", "PaymentCode", "PaymentDate", "TotalCash", "TotalBank", "TotalGiro", "TotalCorrection", "GrandTotal", "Notes", "CreatedDate", "CreatedBy" }; object[] values = { ID, debtPayment.PaymentCode, debtPayment.PaymentDate.ToShortDateString(), debtPayment.TotalCash, debtPayment.TotalBank, debtPayment.TotalGiro, debtPayment.TotalCorrection, debtPayment.GrandTotal, debtPayment.Notes, DateTime.Now.ToShortDateString(), Store.ActiveUser }; var q = new Query().Select(columns).From(tableName).Insert(values); em.ExecuteNonQuery(q.ToSql(), tx); foreach (var debtPaymentItems in debtPayment.DebtPaymentItems) { debtPaymentItems.DebtPaymentId = ID; debtPaymentItemRepository.Save(em, tx, debtPaymentItems); //update status = lunas purchaseRepository.UpdateStatus(em, tx, debtPaymentItems.PurchaseId, true); //update status = lunas debtBalanceRepository.UpdateStatusFromPayment(em, tx, debtPaymentItems.Purchase.Code, true); } recordCounterRepository.UpdateDebtPaymentCounter(debtPayment.PaymentDate.Month, debtPayment.PaymentDate.Year); tx.Commit(); } } catch (Exception ex) { tx.Rollback(); throw ex; } }
private void tsbDelete_Click(object sender, EventArgs e) { var userAccess = userAccessRepository.GetAll(); bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser && u.ObjectName == "Pelunasan Piutang" && u.IsDelete); if (isAllowed == false && Store.IsAdministrator == false) { MessageBox.Show("Anda tidak dapat menghapus", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (Store.IsPeriodClosed) { MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DebtPayment debtPayment = debtPaymentRepository.GetById(new Guid(txtID.Text)); if (debtPayment.Notes.Contains("DIBATALKAN")) { MessageBox.Show("Sudah pernah di hapus ", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (MessageBox.Show("Anda yakin ingin menghapus '" + lblCode.Text + "'", "Perhatian", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var debtPayment1 = new DebtPayment(); debtPayment1.ID = new Guid(txtID.Text); debtPayment1.Notes = txtNotes.Text; debtPaymentRepository.Delete(debtPayment1); GetLastDebtPayment(); } if (lvwDebtPayment.Items.Count == 0) { tsbEdit.Enabled = false; tsbDelete.Enabled = false; } } } } }
private void ValidateDebt(DebtPayment reg) { if (reg.Debt == null) { throw new Exception(string.Format("Débito {0} não existe.", reg.DebtId)); } if (reg.Debt.Status == EnumDebtStatus.Canceled) { throw new Exception(string.Format("Débito {0} Está cancelado e não pode mais receber pagamentos.", reg.Debt)); } if (reg.Debt.Status == EnumDebtStatus.Pay) { throw new Exception(string.Format("Débito {0} Está pago e não pode mais receber pagamentos.", reg.Debt)); } }
public DebtPayment GetLast(int month, int year) { DebtPayment debtPayment = null; using (var em = EntityManagerFactory.CreateInstance(ds)) { string sql = "SELECT TOP 1 ID, PaymentCode, PaymentDate, " + "TotalCash, TotalBank, TotalGiro, TotalCorrection, GrandTotal, Notes, " + "CreatedDate, ModifiedDate, CreatedBy, ModifiedBy " + "FROM DebtPayment " + "WHERE Month(PaymentDate)=" + month + " AND Year(PaymentDate)=" + year + " ORDER BY DebtPayment.PaymentCode DESC"; debtPayment = em.ExecuteObject <DebtPayment>(sql, new DebtPaymentMapper()); } return(debtPayment); }
public DebtPayment GetByCode(string code) { DebtPayment debtPayment = null; using (var em = EntityManagerFactory.CreateInstance(ds)) { string sql = "SELECT ID, PaymentCode, PaymentDate, " + "TotalCash, TotalBank, TotalGiro, TotalCorrection, GrandTotal, Notes, " + "CreatedDate, ModifiedDate, CreatedBy, ModifiedBy " + "FROM DebtPayment " + "WHERE PaymentCode='" + code + "'"; debtPayment = em.ExecuteObject <DebtPayment>(sql, new DebtPaymentMapper()); } return(debtPayment); }
public async Task <DebtPaymentView> Insert(DebtPaymentDto dto) { var reg = new DebtPayment(); _debtPaymentMapper.Map(reg, dto); _customerValidator.Validate(reg); reg.Debt.Payments.Add(reg); reg.Debt.Calculate(); _debtValidator.Validate(reg.Debt); await Context.DebtPayments.AddAsync(reg); await Context.SaveChangesAsync(); return(DebtPaymentView.New(reg)); }
public DebtPayment GetById(Guid id) { DebtPayment debtPayment = null; using (var em = EntityManagerFactory.CreateInstance(ds)) { string sql = "SELECT dp.ID, dp.PaymentCode, dp.PaymentDate, " + "dp.TotalCash, dp.TotalBank, dp.TotalGiro, dp.TotalCorrection, dp.GrandTotal, dp.Notes, " + "dp.CreatedDate,dp.ModifiedDate, dp.CreatedBy, dp.ModifiedBy " + "FROM DebtPayment dp " + "WHERE " + "dp.ID='{" + id + "}'"; debtPayment = em.ExecuteObject <DebtPayment>(sql, new DebtPaymentMapper()); if (debtPayment != null) { debtPayment.DebtPaymentItems = debtPaymentItemRepository.GetByDebtPaymentId(debtPayment.ID); } } return(debtPayment); }
private void BtnPaymentSubmit_Click(object sender, RoutedEventArgs e) { if (TbPaymentAmount.Text == "" || TbPaymentDate.Text == "") { MessageBox.Show("Missing required information"); return; } if (!Common.CheckAmountInput(TbPaymentAmount.Text)) { MessageBox.Show("Invalid amount provided"); return; } var submission = new DebtPayment() { DebtID = Debt.ID, Amount = Convert.ToDouble(TbPaymentAmount.Text), Date = DateTime.Parse(TbPaymentDate.Text), RecordBy = Profile.ProfileName, RecordDate = DateTime.Now }; try { submission.SubmitDebtPayment(); } catch (DatabaseException ex) { MessageBox.Show(ex.ErrorMessage); return; } Common.ReturnToMainWindow(Profile); var main = (MainWindow)Application.Current.MainWindow; if (main.LoadedPage == "Default") { ((DefaultPage)main.PrimaryFrame.Content).RefreshGrid(); } MessageBox.Show("Payment successfully submitted."); Close(); }
private void tsbEdit_Click(object sender, EventArgs e) { var userAccess = userAccessRepository.GetAll(); bool isAllowed = userAccess.Exists(u => u.FullName == Store.ActiveUser && u.ObjectName == "Pelunasan Hutang" && u.IsEdit); if (isAllowed == false && Store.IsAdministrator == false) { MessageBox.Show("Anda tidak dapat merubah", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (Store.IsPeriodClosed) { MessageBox.Show("Tidak dapat menambah/ubah/hapus \n\n Periode : " + Store.GetMonthName(Store.ActiveMonth) + " " + Store.ActiveYear + "\n\n" + "Sudah Tutup Buku", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { DebtPayment debtPayment = debtPaymentRepository.GetById(new Guid(txtID.Text)); if (debtPayment.Notes.Contains("DIBATALKAN")) { MessageBox.Show("Sudah pernah di hapus ", "Perhatian", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { formMode = FormMode.Edit; this.Text = "Pembayaran Hutang - Edit"; EnableFormForEdit(); } } } }
private void SaveDebtPayment() { if (dtpDate.Value.Month != Store.ActiveMonth || dtpDate.Value.Year != Store.ActiveYear) { MessageBox.Show("Tanggal diluar periode aktif", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (lvwDebtPayment.Items.Count == 0) { MessageBox.Show("Detail tidak boleh kosong", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { var debtPayment = new DebtPayment(); debtPayment.PaymentCode = lblCode.Text; debtPayment.PaymentDate = dtpDate.Value; debtPayment.Notes = txtNotes.Text; debtPayment.TotalCash = decimal.Parse(lblCash.Text.Replace(".", "")); debtPayment.TotalBank = decimal.Parse(lblBank.Text.Replace(".", "")); debtPayment.TotalGiro = decimal.Parse(lblGiro.Text.Replace(".", "")); debtPayment.TotalCorrection = decimal.Parse(lblCorrection.Text.Replace(".", "")); debtPayment.GrandTotal = decimal.Parse(lblTotal.Text.Replace(".", "")); var debtPaymentItems = new List <DebtPaymentItem>(); foreach (ListViewItem item in lvwDebtPayment.Items) { string purchaseId = item.SubItems[0].Text; string cash = item.SubItems[2].Text; string bank = item.SubItems[3].Text; string giro = item.SubItems[4].Text; string giroNumber = item.SubItems[5].Text; string correction = item.SubItems[6].Text; string total = item.SubItems[7].Text; DebtPaymentItem si = new DebtPaymentItem(); if (si.Purchase == null) { si.Purchase = new Purchase(); } si.Purchase.Code = item.SubItems[1].Text; si.PurchaseId = new Guid(purchaseId); si.Notes = ""; si.Cash = int.Parse(cash.Replace(".", "")); si.Bank = decimal.Parse(bank.Replace(".", "")); si.Giro = decimal.Parse(giro.Replace(".", "")); si.GiroNumber = txtGiroNumber.Text; si.Correction = decimal.Parse(correction.Replace(".", "")); si.Total = decimal.Parse(total.Replace(".", "")); debtPaymentItems.Add(si); } debtPayment.DebtPaymentItems = debtPaymentItems; if (formMode == FormMode.Add) { debtPaymentRepository.Save(debtPayment); GetLastDebtPayment(); } else if (formMode == FormMode.Edit) { debtPayment.ID = new Guid(txtID.Text); debtPayment.TotalCash = decimal.Parse(lblCash.Text.Replace(".", "")); debtPayment.TotalBank = decimal.Parse(lblBank.Text.Replace(".", "")); debtPayment.TotalGiro = decimal.Parse(lblGiro.Text.Replace(".", "")); debtPayment.TotalCorrection = decimal.Parse(lblCorrection.Text.Replace(".", "")); debtPayment.GrandTotal = decimal.Parse(lblTotal.Text.Replace(".", "")); debtPaymentRepository.Update(debtPayment); } LoadDebtPaymentItems(new Guid(txtID.Text)); DisableForm(); formMode = FormMode.View; FillCode(); this.Text = "Pembayaran Hutang"; } }
public async Task <bool> DeleteDebtPaymentAsync(DebtPayment debtPayment) { return(await _baseRepository.DeleteEntityAsync(debtPayment)); }
public void Validate(DebtPayment reg) { ValidateNegativeValue(reg); ValidateDebt(reg); }