You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.8 KiB
106 lines
3.8 KiB
using BiskLog_Point_Of_Sale.Classes;
|
|
using BiskLog_Point_Of_Sale.Multiple_Login;
|
|
using BiskLog_Point_Of_Sale.Properties;
|
|
using Point_Of_Sale_Managment;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace BiskLog_Point_Of_Sale.Customer
|
|
{
|
|
public partial class Finance : Form
|
|
{
|
|
SqlConnection cn;
|
|
SqlCommand cm;
|
|
SqlDataReader dr;
|
|
DatabaseConn conn = new DatabaseConn();
|
|
string customerID;
|
|
List<CustomerFinance> finances = new List<CustomerFinance>();
|
|
string currency;
|
|
public Finance(string customerID)
|
|
{
|
|
InitializeComponent();
|
|
cn = new SqlConnection(conn.MyConnection());
|
|
this.customerID = customerID;
|
|
holding.Left = (ClientSize.Width - holding.Width) / 2;
|
|
holding.Top = (ClientSize.Height - holding.Height) / 2;
|
|
currency = Settings.Default.currrencyCode + " ";
|
|
|
|
|
|
}
|
|
|
|
public int loadFinance()
|
|
{
|
|
try
|
|
{
|
|
cn.Open();
|
|
cm = new SqlCommand("Select * from CustomerAccounts where branchID = @branchID and customerID = @customerID", cn);
|
|
cm.Parameters.AddWithValue("@customerID", customerID);
|
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
|
cm.ExecuteNonQuery();
|
|
dr = cm.ExecuteReader();
|
|
while (dr.Read())
|
|
{
|
|
CustomerFinance customer = new CustomerFinance();
|
|
customer.description = dr["comments"].ToString();
|
|
customer.date = dr["date"].ToString();
|
|
customer.debit = decimal.Parse(dr["debit"].ToString());
|
|
customer.credit = decimal.Parse(dr["credit"].ToString());
|
|
customer.transactionID = dr["transactionID"].ToString();
|
|
customer.total = decimal.Parse(dr["balance"].ToString());
|
|
finances.Add(customer);
|
|
}
|
|
dr.Close();
|
|
cn.Close();
|
|
return 1;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorLogging.WriteToFile(ex.ToString());
|
|
cn.Close();
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
private async void Finance_Load(object sender, EventArgs e)
|
|
{
|
|
Task<int> task = new Task<int>(loadFinance);
|
|
holding.Visible = true;
|
|
task.Start();
|
|
int result = await task;
|
|
if (result == 0)
|
|
{
|
|
string title = "Error Occurred";
|
|
string message = "An error occurred while getting customer finance, please try again later.";
|
|
NoAction noAction = new NoAction(title, message);
|
|
noAction.BringToFront();
|
|
noAction.ShowDialog();
|
|
}
|
|
else
|
|
{
|
|
if (finances.Count > 0)
|
|
{
|
|
decimal debit = 0;
|
|
decimal credit = 0;
|
|
foreach (CustomerFinance finance in finances)
|
|
{
|
|
debit += finance.debit;
|
|
credit += finance.credit;
|
|
dataGridView1.Rows.Add(Convert.ToDateTime(finance.date).ToLongDateString(), finance.description, finance.transactionID, currency + finance.debit,
|
|
currency + finance.credit, currency + finance.total);
|
|
}
|
|
decimal total = debit - credit;
|
|
acBal.Text = "Account Balance : " + currency + total.ToString();
|
|
}
|
|
}
|
|
holding.Visible = false;
|
|
}
|
|
}
|
|
}
|