using BiskLog_Point_Of_Sale.Properties; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BiskLog_Point_Of_Sale.POSDialogs { public static class PreviousSettlement { public static void settlement(SqlConnection cn, string customerID, decimal investment, SortedList receiptList,SqlTransaction tn) { SqlCommand cm; foreach (var settle in receiptList) { decimal arrears = investment - settle.Value; if (arrears >= 0) { cm = new SqlCommand("Update CreditPurchases set paid = totalBill, status = @status where receiptID = @receiptID and " + "customerID = @customerID and branchID = @branchID " + "Update tblCart set status = @status1 where transno = @receiptID and branchID = @branchID", cn,tn); cm.Parameters.AddWithValue("@customerID", customerID); cm.Parameters.AddWithValue("@receiptID", settle.Key); cm.Parameters.AddWithValue("@status", "settled"); cm.Parameters.AddWithValue("@status1", "SOLD"); cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID); cm.ExecuteNonQuery(); } else { cm = new SqlCommand("Update CreditPurchases set paid = paid + @investment, status = @status where receiptID = @receiptID and " + "customerID = @customerID and branchID = @branchID", cn, tn); cm.Parameters.AddWithValue("@customerID", customerID); cm.Parameters.AddWithValue("@receiptID", settle.Key); cm.Parameters.AddWithValue("@investment", investment); cm.Parameters.AddWithValue("@status", "unsettled"); cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID); cm.ExecuteNonQuery(); } investment = investment - settle.Value; if (investment <= 0) break; } } } }