using BiskLog_Point_Of_Sale.Multiple_Login; using BiskLog_Point_Of_Sale.Properties; using System; using System.Data.SqlClient; using System.Drawing; using System.Threading.Tasks; using System.Windows.Forms; namespace Point_Of_Sale_Managment { public partial class CustomerSettlePayment : Form { string currency; SalesPOS selling; decimal balponit, paymentponit, carryForward; public CustomerSettlePayment(SalesPOS sales, decimal carryForward) { InitializeComponent(); currency = Settings.Default.currrencyCode + " "; selling = sales; this.carryForward = carryForward; } private void settlePayment_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { this.Close(); } } private void button16_Click(object sender, EventArgs e) { payment.AppendText("1"); } private void button17_Click(object sender, EventArgs e) { payment.AppendText("2"); } private void button18_Click(object sender, EventArgs e) { payment.AppendText("3"); } private void button19_Click(object sender, EventArgs e) { payment.AppendText("."); } private void button15_Click(object sender, EventArgs e) { payment.AppendText("0"); } private void button11_Click(object sender, EventArgs e) { payment.Text = ""; } private void button14_Click(object sender, EventArgs e) { payment.AppendText("6"); } private void button13_Click(object sender, EventArgs e) { payment.AppendText("5"); } private void button12_Click(object sender, EventArgs e) { payment.AppendText("4"); } private void button10_Click(object sender, EventArgs e) { payment.AppendText("9"); } private void button9_Click(object sender, EventArgs e) { payment.AppendText("8"); } private void btnSave_Click(object sender, EventArgs e) { payment.AppendText("7"); } private void settlePayment_Load(object sender, EventArgs e) { payment.Focus(); if (carryForward > 0 && carryForward < SalesPOS.mainTotal) { cost.Text = currency + (SalesPOS.mainTotal); owe.Text = currency + (SalesPOS.mainTotal - carryForward); } else if(carryForward > 0 && carryForward > SalesPOS.mainTotal) { cost.Text = currency + (SalesPOS.mainTotal); owe.Text = currency + (0); bal.Text = currency + (carryForward - SalesPOS.mainTotal); } else { cost.Text = currency + SalesPOS.mainTotal.ToString(); owe.Text = currency + SalesPOS.mainTotal.ToString(); } } private void payment_TextChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(payment.Text)) { decimal amount = decimal.Parse(payment.Text); if (!String.IsNullOrEmpty(payment.Text)) { arrangement(amount); } else { arrangement(decimal.Parse("0.00")); } } else { payment.Text = "0.00"; } } public void arrangement(decimal payment) { decimal paid = 0; if (carryForward > 0) { paid = SalesPOS.mainTotal - payment - carryForward; } else { paid = SalesPOS.mainTotal - payment; } paymentponit = payment; if (paid < 0) { bal.Text = currency + (paid * -1).ToString(); balponit = decimal.Parse((paid * -1).ToString()); owe.Text = currency + 0.00; } else if (paid == 0) { bal.Text = currency + paid.ToString(); balponit = decimal.Parse(paid.ToString()); owe.Text = currency + 0.00; } else { owe.Text = currency + paid.ToString(); bal.Text = currency + 0.00; balponit = decimal.Parse("00.00"); } } private void payment_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 8) { //accepts backspace } else if ((e.KeyChar < 48) || (e.KeyChar > 57)) //ascii code 48-57 between 0-9 { e.Handled = true; } else if (e.KeyChar == 46) { // accepts . character } } private void Close_Click(object sender, EventArgs e) { this.Close(); } private void Close_MouseEnter(object sender, EventArgs e) { close.BackColor = Color.Crimson; } private void Close_MouseLeave(object sender, EventArgs e) { close.BackColor = Color.Transparent; } private async void Button21_Click(object sender, EventArgs e) { if (owe.Text.Equals(currency + 0.00)) { Task task = new Task(() => selling.creditSale(0, paymentponit)); task.Start(); int result = await task; if (result == 1) { string title = "Success"; string message = "Payment made successfully"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); this.Close(); } else { string title = "Error Occurred"; string message = "Sorry an error occurred while making payment, please try again"; NoAction noAction = new NoAction(title, message); noAction.BringToFront(); noAction.ShowDialog(); } } else { string title = "Full amount not paid"; string message = "Would you like to take the cash tendered and credit the arrears to the customer's account ?"; Confirmation noAction = new Confirmation(title, message); noAction.BringToFront(); noAction.ShowDialog(); if (noAction.DialogResult == DialogResult.Yes) { Task task = new Task(() => selling.creditSale(decimal.Parse(owe.Text.Substring(currency.Length)), paymentponit)); task.Start(); int result = await task; if (result == 1) { string title1 = "Success"; string message1 = "Payment made successfully"; NoAction noAction1 = new NoAction(title1, message1); noAction1.BringToFront(); noAction1.ShowDialog(); this.Close(); } else { string title2 = "Error Occurred"; string message2 = "Sorry an error occurred while making payment, please try again"; NoAction noAction2 = new NoAction(title2, message2); noAction2.BringToFront(); noAction2.ShowDialog(); } } } } } }