private void DeletePayment() { if (!mboCreditPaymentReversal) { MessageBox.Show("Sorry you are not allowed to reverse payments, please consult your system administrator.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); } else { if (dgvItems.SelectedRows.Count == 1) { foreach (DataGridViewRow dr in dgvItems.SelectedRows) { DateTime TransactionDate = DateTime.Parse(dr.Cells["TransactionDate"].Value.ToString()); if (TransactionDate < mclsCustomerDetails.CreditDetails.LastBillingDate) { MessageBox.Show("Sorry you cannot reverse payment's that are already included in billing statement last: " + mclsCustomerDetails.CreditDetails.LastBillingDate.ToString("MMM dd, yyyy"), "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); break; } else { decimal AmountPaid = decimal.Parse(dr.Cells["Amount"].Value.ToString()); if (MessageBox.Show("Are you sure you want to delete this Payment? " + "If you delete this payment, the current credit of " + mclsCustomerDetails.ContactName + " will be: " + Environment.NewLine + " " + mclsCustomerDetails.Credit.ToString("#,##0.#0") + " + " + AmountPaid.ToString("#,##0.#0") + " = " + (mclsCustomerDetails.Credit + AmountPaid).ToString("#,##0.#0"), "RetailPlus", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes) { Int32 BranchID = Int32.Parse(dr.Cells["BranchID"].Value.ToString()); string TerminalNo = dr.Cells["TerminalNo"].Value.ToString(); string TransactionNo = dr.Cells["TransactionNo"].Value.ToString(); Int64 TransactionID = Int64.Parse(dr.Cells["TransactionID"].Value.ToString()); // put the automatic adjustment outside AceSoft.RetailPlus.Client.LocalDB clsLocalConnection = new AceSoft.RetailPlus.Client.LocalDB(); clsLocalConnection.GetConnection(); Data.Creditors clsCreditors = new Data.Creditors(clsLocalConnection.Connection, clsLocalConnection.Transaction); switch (mclsSysConfigDetails.CreditPaymentType) { case CreditPaymentType.Houseware: clsCreditors.DeleteCreditTransaction(BranchID, TerminalNo, TransactionID); clsCreditors.AutoAdjustCredit(mclsCustomerDetails, mclsCustomerDetails.Credit + AmountPaid); break; case CreditPaymentType.Normal: case CreditPaymentType.MPC: default: clsCreditors.AdjustCredit(BranchID, TerminalNo, TransactionID, mclsCustomerDetails, mclsCustomerDetails.Credit + AmountPaid, AmountPaid); clsCreditors.DeleteCreditTransaction(BranchID, TerminalNo, TransactionID); break; } clsLocalConnection.CommitAndDispose(); mclsCustomerDetails.Credit = mclsCustomerDetails.Credit + AmountPaid; this.Hide(); dialog = System.Windows.Forms.DialogResult.OK; } } } } } }