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.
1207 lines
54 KiB
1207 lines
54 KiB
3 months ago
|
using BarcodeLib;
|
||
|
using BiskLog_Point_Of_Sale.Cashier_Module;
|
||
|
using BiskLog_Point_Of_Sale.Classes;
|
||
|
using BiskLog_Point_Of_Sale.Company_Setup;
|
||
|
using BiskLog_Point_Of_Sale.Dialogs;
|
||
|
using BiskLog_Point_Of_Sale.Multiple_Login;
|
||
|
using BiskLog_Point_Of_Sale.POSDialogs;
|
||
|
using BiskLog_Point_Of_Sale.Properties;
|
||
|
using Microsoft.Reporting.WinForms;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Data;
|
||
|
using System.Data.SqlClient;
|
||
|
using System.Drawing;
|
||
|
using System.Drawing.Imaging;
|
||
|
using System.IO;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows.Forms;
|
||
|
|
||
|
namespace Point_Of_Sale_Managment.CashierModule
|
||
|
{
|
||
|
public partial class NewSalesPOS : Form
|
||
|
{
|
||
|
string heldID = "";
|
||
|
List<string> cart = new List<string>();
|
||
|
SqlConnection cn = new SqlConnection();
|
||
|
SqlCommand cm, cm1;
|
||
|
DatabaseConn databasecon = new DatabaseConn();
|
||
|
SqlDataReader dr;
|
||
|
int i = 1;
|
||
|
string currency;
|
||
|
decimal subtotal;
|
||
|
decimal discount, vat;
|
||
|
public static decimal mainTotal;
|
||
|
public static List<ReceiptObject> receiptClasses = new List<ReceiptObject>();
|
||
|
public static List<bottom> receiptClasses2 = new List<bottom>();
|
||
|
string printLocation = "";
|
||
|
string printerReceiptDefault = Settings.Default.ReceiptPrinter;
|
||
|
Form form = null;
|
||
|
string invoiceid;
|
||
|
CustomerClass customerO;
|
||
|
bool printReceipt = false;
|
||
|
public NewSalesPOS(Form f = null, List<InvoicePOS> invoicecode = null, string invoiceid = null, CustomerClass customer = null)
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
lblDate.Text = DateTime.Now.ToLongDateString();
|
||
|
cn = new SqlConnection(databasecon.MyConnection());
|
||
|
KeyPreview = true;
|
||
|
currency = Settings.Default.currrencyCode + " ";
|
||
|
discount = decimal.Parse("0.00");
|
||
|
if (customer != null)
|
||
|
{
|
||
|
customerO = customer;
|
||
|
lblAddress.Text = customerO.address;
|
||
|
lblTel.Text = customerO.telephone;
|
||
|
lblName.Text = customerO.firstname;
|
||
|
lblMail.Text = customerO.email;
|
||
|
groupBox1.Visible = true;
|
||
|
usualPanel.Visible = false;
|
||
|
customerSalesPanel.Visible = true;
|
||
|
}
|
||
|
if (Settings.Default.AutomaticallyTax)
|
||
|
{
|
||
|
vat = decimal.Parse(Settings.Default.TaxRate.ToString());
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
vat = decimal.Parse("0.0");
|
||
|
}
|
||
|
if (f != null)
|
||
|
{
|
||
|
form = f;
|
||
|
}
|
||
|
if (invoicecode != null)
|
||
|
{
|
||
|
this.invoiceid = invoiceid;
|
||
|
Initializing initializing = new Initializing(invoicecode);
|
||
|
initializing.BringToFront();
|
||
|
initializing.ShowDialog();
|
||
|
if (initializing.DialogResult == DialogResult.OK)
|
||
|
{
|
||
|
newTransaction();
|
||
|
foreach (InvoicePOS pOS in initializing.getInvoiceList)
|
||
|
{
|
||
|
decimal price = decimal.Parse(pOS.totalprice.ToString());
|
||
|
int quantity = int.Parse(pOS.quantity.ToString());
|
||
|
decimal cost = price / quantity;
|
||
|
dataGridView1.Rows.Add(i, pOS.productCode.ToString(), pOS.productname.ToString(), Settings.Default.currrencyCode + " " + cost,
|
||
|
quantity, pOS.unitName, Settings.Default.currrencyCode + " " + price, pOS.unitCode, pOS.distinctiveCode);
|
||
|
i++;
|
||
|
}
|
||
|
checkTotal();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public bool newTransaction()
|
||
|
{
|
||
|
if (Settings.Default.pinOnEveryTransaction)
|
||
|
{
|
||
|
Prompt transPrompt = new Prompt();
|
||
|
transPrompt.BringToFront();
|
||
|
transPrompt.ShowDialog();
|
||
|
if ((transPrompt.DialogResult == DialogResult.OK) && (transPrompt.confirmed))
|
||
|
{
|
||
|
GetTransNo();
|
||
|
txtSearch.Enabled = true;
|
||
|
txtSearch.Focus();
|
||
|
dataGridView1.Rows.Clear();
|
||
|
cart.Clear();
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GetTransNo();
|
||
|
txtSearch.Enabled = true;
|
||
|
txtSearch.Focus();
|
||
|
dataGridView1.Rows.Clear();
|
||
|
cart.Clear();
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
public Image getBarcodeImage(string Bcode)
|
||
|
{
|
||
|
Barcode barcodeAPI = new Barcode();
|
||
|
Color foreColor = Color.Black;
|
||
|
Color backColor = Color.Transparent;
|
||
|
return barcodeAPI.Encode(TYPE.UPCA, Bcode, foreColor, backColor, 290, 120);
|
||
|
}
|
||
|
public int makePayment(decimal balance, decimal tendered)
|
||
|
{
|
||
|
DateTime transactionT = DateTime.Now;
|
||
|
lblTransno.Invoke(new Action(() =>
|
||
|
{
|
||
|
MemoryStream ms = new MemoryStream();
|
||
|
getBarcodeImage(lblTransno.Text).Save(ms, ImageFormat.Png);
|
||
|
byte[] imageBytes = ms.ToArray();
|
||
|
string barcodeStringImage = Convert.ToBase64String(imageBytes);
|
||
|
receiptClasses.Clear();
|
||
|
receiptClasses2.Clear();
|
||
|
bottom bottomReceipt = new bottom(lblTax.Text, lblTransno.Text, MainLogin.login_user, balance, tendered, discount.ToString(), lblDate.Text,
|
||
|
LBLsubtotal.Text, lblTotalCol.Text, Form1.bCompanyName, Form1.branchName, Form1.branchLocation, Form1.branchTel, Form1.tin, Form1.vatno,
|
||
|
barcodeStringImage);
|
||
|
receiptClasses2.Add(bottomReceipt);
|
||
|
GetTransNo();
|
||
|
}));
|
||
|
try
|
||
|
{
|
||
|
dataGridView1.Invoke(new Action(() =>
|
||
|
{
|
||
|
DataTable paymentList = new DataTable();
|
||
|
paymentList.Columns.Add("transno", typeof(string));
|
||
|
paymentList.Columns.Add("id", typeof(string));
|
||
|
paymentList.Columns.Add("quantity", typeof(int));
|
||
|
paymentList.Columns.Add("price", typeof(decimal));
|
||
|
paymentList.Columns.Add("total", typeof(decimal));
|
||
|
paymentList.Columns.Add("status", typeof(string));
|
||
|
paymentList.Columns.Add("unit", typeof(string));
|
||
|
paymentList.Columns.Add("distinctive", typeof(string));
|
||
|
paymentList.Columns.Add("cashier", typeof(string));
|
||
|
paymentList.Columns.Add("branchID", typeof(string));
|
||
|
paymentList.Columns.Add("countID", typeof(string));
|
||
|
paymentList.Columns.Add("pcode", typeof(string));
|
||
|
paymentList.Columns.Add("discount", typeof(decimal));
|
||
|
paymentList.Columns.Add("invoiceID", typeof(string));
|
||
|
paymentList.Columns.Add("customerID", typeof(string));
|
||
|
paymentList.Columns.Add("rowid", typeof(int));
|
||
|
int i = 0;
|
||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||
|
{
|
||
|
ReceiptObject receipt = new ReceiptObject(row.Cells[2].Value.ToString(), decimal.Parse(row.Cells[3].Value.ToString().Substring(currency.Length)),
|
||
|
int.Parse(row.Cells[4].Value.ToString()), decimal.Parse(row.Cells[6].Value.ToString().Substring(currency.Length)));
|
||
|
receiptClasses.Add(receipt);
|
||
|
|
||
|
paymentList.Rows.Add(lblTransno.Text, row.Cells["id"].Value.ToString(), int.Parse(row.Cells["qty"].Value.ToString()),
|
||
|
decimal.Parse(row.Cells["price"].Value.ToString().Substring(currency.Length)), decimal.Parse(row.Cells["total"].Value.ToString().Substring(currency.Length)),
|
||
|
"SOLD", row.Cells["unitCode"].Value.ToString(), row.Cells["distinctiveCode"].Value.ToString(), MainLogin.login_user, Form1.branch,
|
||
|
MainLogin.login_user + Form1.branch + DateTime.Now.ToString("yyyyMMddHHmmssfff") + row.Index, row.Cells["id"].Value.ToString(),
|
||
|
discount, !String.IsNullOrEmpty(invoiceid) ? invoiceid : "", customerO != null ? customerO.id : "", i);
|
||
|
i++;
|
||
|
}
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Exec usp_make_payment @paymentItems = @items,@tendered = @tender,@valueAddTax = @vat,@holdID = @heldID", cn);
|
||
|
cm.Parameters.Add(new SqlParameter
|
||
|
{
|
||
|
ParameterName = "@items",
|
||
|
SqlDbType = SqlDbType.Structured,
|
||
|
Value = paymentList,
|
||
|
TypeName = "[PaymentItem]"
|
||
|
});
|
||
|
cm.Parameters.Add(new SqlParameter
|
||
|
{
|
||
|
ParameterName = "@tender",
|
||
|
SqlDbType = SqlDbType.Decimal,
|
||
|
Value = tendered,
|
||
|
});
|
||
|
cm.Parameters.Add(new SqlParameter
|
||
|
{
|
||
|
ParameterName = "@vat",
|
||
|
SqlDbType = SqlDbType.Decimal,
|
||
|
Value = vat,
|
||
|
});
|
||
|
cm.Parameters.Add(new SqlParameter
|
||
|
{
|
||
|
ParameterName = "@heldID",
|
||
|
SqlDbType = SqlDbType.VarChar,
|
||
|
Value = heldID,
|
||
|
});
|
||
|
cm.ExecuteNonQuery();
|
||
|
cn.Close();
|
||
|
GetTransNo();
|
||
|
|
||
|
if (printReceipt)
|
||
|
{
|
||
|
if (printerReceiptDefault == "Microsoft XPS Document Writer" || printerReceiptDefault == "Microsoft Print to PDF")
|
||
|
{
|
||
|
FolderBrowserDialog folder = new FolderBrowserDialog();
|
||
|
DialogResult result = folder.ShowDialog();
|
||
|
if (result == DialogResult.OK && !String.IsNullOrEmpty(folder.SelectedPath))
|
||
|
{
|
||
|
printLocation = folder.SelectedPath;
|
||
|
LocalReport report = new LocalReport();
|
||
|
string path = Path.GetDirectoryName(Application.ExecutablePath);
|
||
|
string fullpath = Path.GetDirectoryName(Application.ExecutablePath).Remove(path.Length - 10) +
|
||
|
@"\Receipt.rdlc";
|
||
|
report.ReportPath = fullpath;
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptReport", receiptClasses));
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptRest", receiptClasses2));
|
||
|
ReceiptConfig.PrintToPrinter(report, printLocation, printerReceiptDefault);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printLocation = "";
|
||
|
LocalReport report = new LocalReport();
|
||
|
string path = Path.GetDirectoryName(Application.ExecutablePath);
|
||
|
string fullpath = Path.GetDirectoryName(Application.ExecutablePath).Remove(path.Length - 10) +
|
||
|
@"\Receipt.rdlc";
|
||
|
report.ReportPath = fullpath;
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptReport", receiptClasses));
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptRest", receiptClasses2));
|
||
|
ReceiptConfig.PrintToPrinter(report, printLocation, printerReceiptDefault);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
subtotal = decimal.Parse("00.00");
|
||
|
lbldiscount.Text = "0";
|
||
|
LBLsubtotal.Text = "0.00";
|
||
|
dataGridView1.Rows.Clear();
|
||
|
lblTransno.Text = "000000000000000";
|
||
|
txtSearch.Enabled = true;
|
||
|
txtSearch.Focus();
|
||
|
receiptClasses2.Clear();
|
||
|
receiptClasses.Clear();
|
||
|
customer.Text = "";
|
||
|
lblName.Text = "";
|
||
|
clearCustomer();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
private void GetTransNo()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
i = 1;
|
||
|
subtotal = decimal.Parse("00.00");
|
||
|
lbldiscount.Text = "0";
|
||
|
LBLsubtotal.Text = "0.00";
|
||
|
lblTotalCol.Text = "0.00";
|
||
|
string sdate = DateTime.Now.ToString("yyyyMMdd");
|
||
|
string transno;
|
||
|
int count;
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Select top 1 transno from tblCart where transno like '" + sdate + "%' order by transno desc", cn);
|
||
|
dr = cm.ExecuteReader();
|
||
|
dr.Read();
|
||
|
if (dr.HasRows)
|
||
|
{
|
||
|
transno = dr[0].ToString();
|
||
|
count = int.Parse(transno.Substring(8, 4));
|
||
|
lblTransno.Text = sdate + (count + 1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
transno = sdate + "1001";
|
||
|
lblTransno.Text = transno;
|
||
|
}
|
||
|
dr.Close();
|
||
|
|
||
|
cn.Close();
|
||
|
lblTax.Text = vat.ToString() + "%";
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
cn.Close();
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
lblTransno.Text = String.Format("{0:d9}", (DateTime.Now.Ticks / 10) % 10000000);
|
||
|
}
|
||
|
}
|
||
|
private void btnNew_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
newTransaction();
|
||
|
}
|
||
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (e.RowIndex != -1)
|
||
|
{
|
||
|
string colName = dataGridView1.Columns[e.ColumnIndex].Name;
|
||
|
if (colName.Equals("Delete"))
|
||
|
{
|
||
|
int r = dataGridView1.CurrentCell.RowIndex;
|
||
|
string productcode = dataGridView1.Rows[r].Cells[1].Value.ToString();
|
||
|
string title = "Remove item";
|
||
|
string message = "Are you show you would like to remove " + dataGridView1.Rows[r].Cells[2].Value.ToString() +
|
||
|
" from the cart ?";
|
||
|
Confirmation Confirmation = new Confirmation(title, message);
|
||
|
Confirmation.BringToFront();
|
||
|
Confirmation.ShowDialog();
|
||
|
if (Confirmation.DialogResult == DialogResult.Yes)
|
||
|
{
|
||
|
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
discount = 0;
|
||
|
lbldiscount.Text = "0";
|
||
|
}
|
||
|
checkTotal();
|
||
|
cart.Remove(productcode);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string productcode = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
|
||
|
string name = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
|
||
|
int quantity = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString());
|
||
|
string unit = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
|
||
|
string total = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
|
||
|
string selling = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
|
||
|
decimal price = decimal.Parse(selling.Substring(currency.Length));
|
||
|
decimal totalCost = decimal.Parse(total.Substring(currency.Length));
|
||
|
AlterWindow alterWindow = new AlterWindow(productcode, name, quantity, unit, price, totalCost);
|
||
|
alterWindow.BringToFront();
|
||
|
alterWindow.ShowDialog();
|
||
|
if (alterWindow.DialogResult == DialogResult.OK)
|
||
|
{
|
||
|
dataGridView1.Rows[e.RowIndex].Cells[4].Value = alterWindow.quantity;
|
||
|
dataGridView1.Rows[e.RowIndex].Cells[3].Value = currency + alterWindow.sellingprice;
|
||
|
dataGridView1.Rows[e.RowIndex].Cells[6].Value = currency + alterWindow.totalPrice;
|
||
|
}
|
||
|
checkTotal();
|
||
|
txtSearch.Focus();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
txtSearch.Focus();
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private async void txtSearch_TextChanged(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (txtSearch.Text.Length >= 12)
|
||
|
{
|
||
|
if (txtSearch.Text == string.Empty)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
await Lookup();
|
||
|
txtSearch.Text = "";
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
cn.Close();
|
||
|
ErrorLogging.WriteToFile(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
private async Task Lookup()
|
||
|
{
|
||
|
cn.Open();
|
||
|
bool set = false;
|
||
|
cm = new SqlCommand("Exec usp_fetch_product_by_barcode @branchID = @branch, @barcode = @barcode1", cn);
|
||
|
cm.Parameters.AddWithValue("@barcode1", txtSearch.Text);
|
||
|
cm.Parameters.AddWithValue("@branch", Form1.branch);
|
||
|
SqlDataReader dataReader = cm.ExecuteReader();
|
||
|
dataReader.Read();
|
||
|
if (dataReader.HasRows)
|
||
|
{
|
||
|
loadProductAutomatic(dataReader[0].ToString(), dataReader[2].ToString(), dataReader[1].ToString(), 1, dataReader[3].ToString(),
|
||
|
dataReader[4].ToString(), dataReader[0].ToString());
|
||
|
}
|
||
|
|
||
|
else
|
||
|
{
|
||
|
string title = "Product unavailable";
|
||
|
string message = "Product is supposed to be out of stock or product does not exist";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
dataReader.Close();
|
||
|
cn.Close();
|
||
|
}
|
||
|
private void BTNitem_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (lblTransno.Text == "000000000000000")
|
||
|
{
|
||
|
if (newTransaction())
|
||
|
{
|
||
|
AddProducttoCart producttoCart = new AddProducttoCart(this);
|
||
|
producttoCart.BringToFront();
|
||
|
producttoCart.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
AddProducttoCart producttoCart = new AddProducttoCart(this);
|
||
|
producttoCart.BringToFront();
|
||
|
producttoCart.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
public void loadProductManual(string id, string productName, string price, int quantity, string unitname, string unitCode, string distinctive)
|
||
|
{
|
||
|
decimal cost = decimal.Parse(price.Substring(currency.Length));
|
||
|
decimal total = cost * quantity;
|
||
|
|
||
|
if (!cart.Contains(id) && !id.Equals(distinctive) && !cart.Contains(distinctive))
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, id, productName, price, quantity, unitname, currency + total, unitCode, distinctive);
|
||
|
cart.Add(distinctive);
|
||
|
i++;
|
||
|
}
|
||
|
else if (!cart.Contains(id) && id.Equals(distinctive) && !cart.Contains(distinctive))
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, id, productName, price, quantity, unitname, currency + total, unitCode, distinctive);
|
||
|
cart.Add(id);
|
||
|
i++;
|
||
|
}
|
||
|
else if (!id.Equals(distinctive) && !cart.Contains(distinctive))
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, id, productName, price, quantity, unitname, currency + total, unitCode, distinctive);
|
||
|
cart.Add(distinctive);
|
||
|
i++;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||
|
{
|
||
|
if (row.Cells[1].Value.ToString().Equals(id) && row.Cells[8].Value.ToString().Equals(distinctive))
|
||
|
{
|
||
|
int total_quantity = int.Parse(row.Cells[4].Value.ToString());
|
||
|
decimal total_bill = decimal.Parse(row.Cells[6].Value.ToString().Substring(currency.Length));
|
||
|
total_bill += total;
|
||
|
total_quantity += quantity;
|
||
|
row.Cells[4].Value = total_quantity;
|
||
|
row.Cells[6].Value = currency + " " + total_bill;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
checkTotal();
|
||
|
if (Settings.Default.BeepOnAdd)
|
||
|
{
|
||
|
Console.Beep();
|
||
|
}
|
||
|
}
|
||
|
public void loadProductAutomatic(string id, string productName, string price, int quantity, string unitname, string unitCode, string distinctive)
|
||
|
{
|
||
|
decimal cost = decimal.Parse(price);
|
||
|
decimal total = cost * quantity;
|
||
|
|
||
|
if (!cart.Contains(id) && !id.Equals(distinctive) && !cart.Contains(distinctive))
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, id, productName, currency + price, quantity, unitname, currency + total, unitCode, distinctive);
|
||
|
cart.Add(distinctive);
|
||
|
i++;
|
||
|
}
|
||
|
else if (!cart.Contains(id) && id.Equals(distinctive) && !cart.Contains(distinctive))
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, id, productName, currency + price, quantity, unitname, currency + total, unitCode, distinctive);
|
||
|
cart.Add(id);
|
||
|
i++;
|
||
|
}
|
||
|
else if (!id.Equals(distinctive) && !cart.Contains(distinctive))
|
||
|
{
|
||
|
dataGridView1.Rows.Add(i, id, productName, currency + price, quantity, unitname, currency + total, unitCode, distinctive);
|
||
|
cart.Add(distinctive);
|
||
|
i++;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||
|
{
|
||
|
if (row.Cells[1].Value.ToString().Equals(id) && row.Cells[8].Value.ToString().Equals(distinctive))
|
||
|
{
|
||
|
int total_quantity = int.Parse(row.Cells[4].Value.ToString());
|
||
|
decimal total_bill = decimal.Parse(row.Cells[6].Value.ToString().Substring(currency.Length));
|
||
|
total_bill += total;
|
||
|
total_quantity += quantity;
|
||
|
row.Cells[4].Value = total_quantity;
|
||
|
row.Cells[6].Value = currency + " " + total_bill;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
checkTotal();
|
||
|
if (Settings.Default.BeepOnAdd)
|
||
|
{
|
||
|
Console.Beep();
|
||
|
}
|
||
|
}
|
||
|
public void checkTotal()
|
||
|
{
|
||
|
decimal Ttotal = decimal.Parse("00.00");
|
||
|
foreach (DataGridViewRow rows in dataGridView1.Rows)
|
||
|
{
|
||
|
Ttotal += decimal.Parse(rows.Cells[6].Value.ToString().Substring(currency.Length));
|
||
|
}
|
||
|
LBLsubtotal.Text = Ttotal.ToString();
|
||
|
decimal thiscou = decimal.Parse((Ttotal * discount / 100).ToString());
|
||
|
decimal vatr = (Ttotal * vat / 100);
|
||
|
mainTotal = decimal.Parse((Ttotal + vatr - thiscou).ToString());
|
||
|
lblTotalCol.Text = currency + " " + mainTotal.ToString();
|
||
|
}
|
||
|
private void SalesPOS_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
if (customerO != null)
|
||
|
{
|
||
|
this.customer.Text = "Customer Name : " + customerO.firstname;
|
||
|
this.customer.Visible = true;
|
||
|
if (!newTransaction())
|
||
|
{
|
||
|
this.Close();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
lblTax.Text = vat + "%";
|
||
|
cashierName.Text = MainLogin.login_user;
|
||
|
timer1.Start();
|
||
|
}
|
||
|
private void btnSettle_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
printReceipt = false;
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
settlePayment payment = new settlePayment(this);
|
||
|
payment.BringToFront();
|
||
|
payment.ShowDialog();
|
||
|
lblTotalCol.Text = "00.00";
|
||
|
}
|
||
|
cart.Clear();
|
||
|
}
|
||
|
private void SalesPOS_KeyDown(object sender, KeyEventArgs e)
|
||
|
{
|
||
|
if (e.KeyCode == Keys.F1)
|
||
|
{
|
||
|
newTransaction();
|
||
|
clearCustomer();
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F2)
|
||
|
{
|
||
|
if (lblTransno.Text == "000000000000000")
|
||
|
{
|
||
|
if (newTransaction())
|
||
|
{
|
||
|
AddProducttoCart producttoCart = new AddProducttoCart(this);
|
||
|
producttoCart.BringToFront();
|
||
|
producttoCart.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
AddProducttoCart producttoCart = new AddProducttoCart(this);
|
||
|
producttoCart.BringToFront();
|
||
|
producttoCart.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F3)
|
||
|
{
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can add a discount";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Discount discount = new Discount(this);
|
||
|
discount.BringToFront();
|
||
|
discount.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
else if (e.KeyCode == Keys.F7)
|
||
|
{
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
settlePayment payment = new settlePayment(this);
|
||
|
payment.BringToFront();
|
||
|
payment.ShowDialog();
|
||
|
}
|
||
|
cart.Clear();
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F11)
|
||
|
{
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
settlePayment payment = new settlePayment(this);
|
||
|
payment.BringToFront();
|
||
|
payment.ShowDialog();
|
||
|
}
|
||
|
cart.Clear();
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt)
|
||
|
{
|
||
|
string message = "Are you sure you would like to leave ?";
|
||
|
string title = "Confirmation";
|
||
|
Confirmation noAction = new Confirmation(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
if (noAction.DialogResult == DialogResult.Yes)
|
||
|
{
|
||
|
this.Close();
|
||
|
}
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F5)
|
||
|
{
|
||
|
//only authorized users cancel
|
||
|
ReceiptModule cancellation = new ReceiptModule();
|
||
|
cancellation.BringToFront();
|
||
|
cancellation.ShowDialog();
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F6)
|
||
|
{
|
||
|
DailySales sales = new DailySales();
|
||
|
sales.BringToFront();
|
||
|
sales.ShowDialog();
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F9)
|
||
|
{
|
||
|
CustomerBill customer = new CustomerBill();
|
||
|
customer.BringToFront();
|
||
|
customer.ShowDialog();
|
||
|
if (customer.DialogResult == DialogResult.OK)
|
||
|
{
|
||
|
customerO = new CustomerClass();
|
||
|
customerO = customer.customer;
|
||
|
lblAddress.Text = customer.address;
|
||
|
lblTel.Text = customer.telephone;
|
||
|
lblName.Text = customer.name;
|
||
|
lblMail.Text = customer.email;
|
||
|
this.customer.Text = "Customer Name : " + customerO.firstname;
|
||
|
this.customer.Visible = true;
|
||
|
}
|
||
|
}
|
||
|
else if (e.KeyCode == Keys.F10)
|
||
|
{
|
||
|
string message = "Are you sure you would like to cancel this sale ?";
|
||
|
string title = "Confirmation";
|
||
|
Confirmation noAction = new Confirmation(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
if (noAction.DialogResult == DialogResult.Yes)
|
||
|
{
|
||
|
dataGridView1.Rows.Clear();
|
||
|
newTransaction();
|
||
|
checkTotal();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public void LoadDiscount(decimal dis)
|
||
|
{
|
||
|
discount = dis;
|
||
|
lbldiscount.Text = discount.ToString() + "%";
|
||
|
checkTotal();
|
||
|
}
|
||
|
public int loadBal()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
lblBal.Invoke(new Action(() =>
|
||
|
{
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Select top(1) balance from CustomerAccounts where branchID = @branchID and customerID = @customer " +
|
||
|
"order by date desc", cn);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.Parameters.AddWithValue("@customer", customerO.id);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
dr.Read();
|
||
|
if (dr.HasRows)
|
||
|
{
|
||
|
decimal figure = decimal.Parse(dr[0].ToString());
|
||
|
lblBal.Text = currency + figure;
|
||
|
if (figure < 0)
|
||
|
{
|
||
|
lblBal.ForeColor = Color.Crimson;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lblBal.ForeColor = Color.DarkGreen;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
lblBal.Text = currency + "00.00";
|
||
|
lblBal.ForeColor = Color.DarkGreen;
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
public void clearCustomer()
|
||
|
{
|
||
|
lblName.Text = "";
|
||
|
lblBal.Text = "";
|
||
|
customerO = null;
|
||
|
groupBox1.Visible = false;
|
||
|
usualPanel.Visible = true;
|
||
|
customerSalesPanel.Visible = false;
|
||
|
this.customer.Text = "";
|
||
|
this.customer.Visible = false;
|
||
|
}
|
||
|
private async void lblName_TextChanged(object sender, EventArgs e)
|
||
|
{
|
||
|
if (!String.IsNullOrEmpty(lblName.Text))
|
||
|
{
|
||
|
groupBox1.Visible = true;
|
||
|
usualPanel.Visible = false;
|
||
|
customerSalesPanel.Visible = true;
|
||
|
this.customer.Text = "Customer Name : " + customerO.firstname;
|
||
|
this.customer.Visible = true;
|
||
|
Task<int> task = new Task<int>(loadBal);
|
||
|
task.Start();
|
||
|
await task;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
clearCustomer();
|
||
|
}
|
||
|
}
|
||
|
public int creditSale(decimal balance, decimal tendered)
|
||
|
{
|
||
|
string transactionT = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
|
decimal totalBill = 0;
|
||
|
|
||
|
lblTransno.Invoke(new Action(() =>
|
||
|
{
|
||
|
totalBill = decimal.Parse(lblTotalCol.Text.Substring(Settings.Default.currrencyCode.Length));
|
||
|
MemoryStream ms = new MemoryStream();
|
||
|
getBarcodeImage(lblTransno.Text).Save(ms, ImageFormat.Png);
|
||
|
byte[] imageBytes = ms.ToArray();
|
||
|
string barcodeStringImage = Convert.ToBase64String(imageBytes);
|
||
|
receiptClasses.Clear();
|
||
|
receiptClasses2.Clear();
|
||
|
bottom bottomReceipt = new bottom(lblTax.Text, lblTransno.Text, MainLogin.login_user, balance, tendered, discount.ToString(), lblDate.Text,
|
||
|
LBLsubtotal.Text, lblTotalCol.Text, CashierMain.bCompanyName, CashierMain.branchName, CashierMain.branchLocation, CashierMain.branchTel, customerO.firstname, CashierMain.vatno,
|
||
|
barcodeStringImage);
|
||
|
receiptClasses2.Add(bottomReceipt);
|
||
|
GetTransNo();
|
||
|
}));
|
||
|
|
||
|
cn.Open();
|
||
|
SortedList<string, decimal> receiptList = new SortedList<string, decimal>();
|
||
|
SqlDataReader dr;
|
||
|
SqlCommand cm;
|
||
|
cm = new SqlCommand("Select receiptID,(totalBill - paid) as remaining from CreditPurchases where status = @status and " +
|
||
|
"customerID = @customerID and branchID = @branchID", cn);
|
||
|
cm.Parameters.AddWithValue("@customerID", customerO.id);
|
||
|
cm.Parameters.AddWithValue("@status", "unsettled");
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
string receiptID = dr[0].ToString();
|
||
|
decimal remaining1 = decimal.Parse(dr[1].ToString());
|
||
|
receiptList.Add(receiptID, remaining1);
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
|
||
|
cn.Open();
|
||
|
SqlTransaction tn = cn.BeginTransaction();
|
||
|
try
|
||
|
{
|
||
|
dataGridView1.Invoke(new Action(() =>
|
||
|
{
|
||
|
string status = "";
|
||
|
string comment = "";
|
||
|
if (tendered < totalBill && balance > 0)
|
||
|
{
|
||
|
status = "CREDIT";
|
||
|
comment = "ITEMS SOLD TO CUSTOMER ON CREDIT";
|
||
|
cm1 = new SqlCommand("Insert into CreditPurchases (customerID,receiptID,date,paid,totalBill,status,branchID) " +
|
||
|
"values (@customerID,@receiptID,@date,@paid,@totalBill,@status,@branchID)", cn, tn);
|
||
|
cm1.Parameters.AddWithValue("@customerID", customerO.id);
|
||
|
cm1.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm1.Parameters.AddWithValue("@receiptID", lblTransno.Text);
|
||
|
cm1.Parameters.AddWithValue("@date", transactionT);
|
||
|
cm1.Parameters.AddWithValue("@paid", totalBill - balance);
|
||
|
cm1.Parameters.AddWithValue("@totalBill", lblTotalCol.Text.Substring(Settings.Default.currrencyCode.Length));
|
||
|
cm1.Parameters.AddWithValue("@status", "unsettled");
|
||
|
cm1.ExecuteNonQuery();
|
||
|
}
|
||
|
else if (tendered > totalBill)
|
||
|
{
|
||
|
decimal afterPayment = tendered - totalBill;
|
||
|
status = "SOLD";
|
||
|
comment = "ITEMS SOLD TO CUSTOMER";
|
||
|
PreviousSettlement.settlement(cn, customerO.id, afterPayment, receiptList, tn);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
status = "SOLD";
|
||
|
comment = "ITEMS SOLD TO CUSTOMER";
|
||
|
}
|
||
|
|
||
|
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||
|
{
|
||
|
|
||
|
cm = new SqlCommand("Declare @baseunit varchar(150) = (Select baseUnit from tblProduct where pcode = @pcode) " +
|
||
|
"Declare @costprice decimal(19, 2) = (Select costprice from tblProduct where pcode = @pcode) " +
|
||
|
"Declare @dquantity int = Case when @baseUnit = @unit then 1 * @quantity else " +
|
||
|
"(Select [quantity/unit] * @quantity as quantity from ProductAltUnit where distinctiveCode = @distinctive and branchID = @branchID) end " +
|
||
|
|
||
|
"Insert into tblCart(transno, id, quantity, date, price, cashier, status, total, countID, branchID, unit, costprice) " +
|
||
|
"Values(@transno, @id, @dquantity, @date, @price, @cashier, @status, @total, @countID, @branchID, @unit, @costprice) " +
|
||
|
|
||
|
"Declare @newQuantity int = (Select MAX(quantity) - MIN(@dquantity) from tblInventory where pcode = @pcode and branchID = @branchID) " +
|
||
|
"Update tblInventory set quantity = @newQuantity where pcode = @pcode and branchID = @branchID " +
|
||
|
"Insert into tblInventoryEntries(pcode, quantity, date, countID, branchID) values (@pcode, @newQuantity, @date, @countID, @branchID)", cn, tn);
|
||
|
cm.Parameters.AddWithValue("@transno", lblTransno.Text);
|
||
|
cm.Parameters.AddWithValue("@id", row.Cells[1].Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@quantity", row.Cells[4].Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@price", row.Cells[3].Value.ToString().Substring(currency.Length));
|
||
|
cm.Parameters.AddWithValue("@total", row.Cells[6].Value.ToString().Substring(currency.Length));
|
||
|
cm.Parameters.AddWithValue("@date", transactionT);
|
||
|
cm.Parameters.AddWithValue("@status", status);
|
||
|
cm.Parameters.AddWithValue("@unit", row.Cells[7].Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@distinctive", row.Cells[8].Value.ToString());
|
||
|
cm.Parameters.AddWithValue("@cashier", MainLogin.login_user);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.Parameters.AddWithValue("@countID", MainLogin.login_user + Settings.Default.BranchID + DateTime.Now.ToString("yyyyMMddHHmmssfff") + row.Index);
|
||
|
cm.Parameters.AddWithValue("@pcode", row.Cells[1].Value.ToString());
|
||
|
cm.ExecuteNonQuery();
|
||
|
|
||
|
ReceiptObject receipt = new ReceiptObject(row.Cells[2].Value.ToString(), decimal.Parse(row.Cells[3].Value.ToString().Substring(currency.Length)),
|
||
|
int.Parse(row.Cells[4].Value.ToString()), decimal.Parse(row.Cells[6].Value.ToString().Substring(currency.Length)));
|
||
|
receiptClasses.Add(receipt);
|
||
|
}
|
||
|
|
||
|
if (discount > 0)
|
||
|
{
|
||
|
cm1 = new SqlCommand("Insert into tblDiscountLogs (receiptID,cashier,date,discount,branchID,countID) values " +
|
||
|
"(@receiptID,@cashier,@date,@discount,@branchID,@countID)", cn, tn);
|
||
|
cm1.Parameters.AddWithValue("@receiptID", lblTransno.Text);
|
||
|
cm1.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm1.Parameters.AddWithValue("@cashier", MainLogin.login_user);
|
||
|
cm1.Parameters.AddWithValue("@date", transactionT);
|
||
|
cm1.Parameters.AddWithValue("@discount", discount);
|
||
|
cm1.Parameters.AddWithValue("@countID", MainLogin.login_user + lblTransno.Text + transactionT);
|
||
|
cm1.ExecuteNonQuery();
|
||
|
}
|
||
|
if (!String.IsNullOrEmpty(invoiceid))
|
||
|
{
|
||
|
cm1 = new SqlCommand("Update tblInvoice set status = @status where invoiceID = @invoiceID and branchID = @branchID ", cn, tn);
|
||
|
cm1.Parameters.AddWithValue("@invoiceID", invoiceid);
|
||
|
cm1.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm1.Parameters.AddWithValue("@status", "SOLD");
|
||
|
cm1.ExecuteNonQuery();
|
||
|
}
|
||
|
cm = new SqlCommand("Declare @total decimal(19,2) = Case when (Select SUM(debit - credit) from CustomerAccounts where branchID = @branchID " +
|
||
|
"and customerID = @customerID) is null then 0 else (Select SUM(debit - credit) from CustomerAccounts where branchID = @branchID and customerID = @customerID) end " +
|
||
|
"set @total = (@total + @debit) - @credit " +
|
||
|
"Insert into CustomerAccounts(customerID, transactionID, date, debit, credit, balance, comments, branchID, countID) " +
|
||
|
"Values(@customerID, @transactionID, @date, @debit, @credit, @total, @comments, @branchID, @countID)", cn, tn);
|
||
|
cm.Parameters.AddWithValue("@customerID", customerO.id);
|
||
|
cm.Parameters.AddWithValue("@transactionID", lblTransno.Text);
|
||
|
cm.Parameters.AddWithValue("@date", transactionT);
|
||
|
cm.Parameters.AddWithValue("@debit", tendered);
|
||
|
cm.Parameters.AddWithValue("@credit", lblTotalCol.Text.Substring(Settings.Default.currrencyCode.Length));
|
||
|
cm.Parameters.AddWithValue("@comments", comment);
|
||
|
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm.Parameters.AddWithValue("@countID", MainLogin.login_user + lblTransno.Text + transactionT);
|
||
|
cm.ExecuteNonQuery();
|
||
|
|
||
|
cm1 = new SqlCommand("Insert into tblCustomerPurchases (customerID,transactionID,branchID,countID) values(@customerID,@transactionID,@branchID,@countID)", cn, tn);
|
||
|
cm1.Parameters.AddWithValue("@customerID", customerO.id);
|
||
|
cm1.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
|
||
|
cm1.Parameters.AddWithValue("@countID", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
|
||
|
cm1.Parameters.AddWithValue("@transactionID", lblTransno.Text);
|
||
|
cm1.ExecuteNonQuery();
|
||
|
|
||
|
tn.Commit();
|
||
|
cn.Close();
|
||
|
GetTransNo();
|
||
|
|
||
|
if (printReceipt)
|
||
|
{
|
||
|
if (printerReceiptDefault == "Microsoft XPS Document Writer" || printerReceiptDefault == "Microsoft Print to PDF")
|
||
|
{
|
||
|
FolderBrowserDialog folder = new FolderBrowserDialog();
|
||
|
DialogResult result = folder.ShowDialog();
|
||
|
if (result == DialogResult.OK && !String.IsNullOrEmpty(folder.SelectedPath))
|
||
|
{
|
||
|
printLocation = folder.SelectedPath;
|
||
|
LocalReport report = new LocalReport();
|
||
|
string path = Path.GetDirectoryName(Application.ExecutablePath);
|
||
|
string fullpath = Path.GetDirectoryName(Application.ExecutablePath).Remove(path.Length - 10) +
|
||
|
@"\CreditReceipt.rdlc";
|
||
|
report.ReportPath = fullpath;
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptReport", receiptClasses));
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptRest", receiptClasses2));
|
||
|
ReceiptConfig.PrintToPrinter(report, printLocation, printerReceiptDefault);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printLocation = "";
|
||
|
LocalReport report = new LocalReport();
|
||
|
string path = Path.GetDirectoryName(Application.ExecutablePath);
|
||
|
string fullpath = Path.GetDirectoryName(Application.ExecutablePath).Remove(path.Length - 10) +
|
||
|
@"\CreditReceipt.rdlc";
|
||
|
report.ReportPath = fullpath;
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptReport", receiptClasses));
|
||
|
report.DataSources.Add(new ReportDataSource("ReceiptRest", receiptClasses2));
|
||
|
ReceiptConfig.PrintToPrinter(report, printLocation, printerReceiptDefault);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
dataGridView1.Rows.Clear();
|
||
|
lblTransno.Text = "000000000000000";
|
||
|
txtSearch.Enabled = true;
|
||
|
txtSearch.Focus();
|
||
|
receiptClasses2.Clear();
|
||
|
receiptClasses.Clear();
|
||
|
}));
|
||
|
return 1;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
ErrorLogging.WriteToFile(ex.ToString());
|
||
|
tn.Rollback();
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
private async void magicButton7_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
checkTotal();
|
||
|
string titleM = "Action Required !!!";
|
||
|
string messageM = "Would you like a receipt for this transaction ?";
|
||
|
Confirmation confirmation = new Confirmation(titleM, messageM);
|
||
|
confirmation.BringToFront();
|
||
|
confirmation.ShowDialog();
|
||
|
if (confirmation.DialogResult == DialogResult.Yes)
|
||
|
{
|
||
|
printReceipt = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
printReceipt = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
decimal balance = decimal.Parse(lblTotalCol.Text.Substring(Settings.Default.currrencyCode.Length));
|
||
|
decimal bal = decimal.Parse(lblBal.Text.Substring(Settings.Default.currrencyCode.Length));
|
||
|
if (bal > 0)
|
||
|
{
|
||
|
balance -= bal;
|
||
|
if (balance < 0)
|
||
|
balance *= 0;
|
||
|
}
|
||
|
|
||
|
Task<int> task = new Task<int>(() => creditSale(balance, 0));
|
||
|
task.Start();
|
||
|
int result = await task;
|
||
|
if (result == 1)
|
||
|
{
|
||
|
string title = "Transaction Successful";
|
||
|
string message = "Billed has been credited to " + lblName.Text + "'s account successfully";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
clearCustomer();
|
||
|
lblTotalCol.Text = "00.00";
|
||
|
cart.Clear();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Error Occurred";
|
||
|
string message = "An error occurred while billing customer";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
private void magicButton6_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
printReceipt = false;
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
checkTotal();
|
||
|
decimal bal = decimal.Parse(lblBal.Text.Substring(currency.Length));
|
||
|
CashierCustomerSettlePayment payment = new CashierCustomerSettlePayment(this, bal);
|
||
|
payment.BringToFront();
|
||
|
payment.ShowDialog();
|
||
|
clearCustomer();
|
||
|
lblTotalCol.Text = "00.00";
|
||
|
}
|
||
|
cart.Clear();
|
||
|
}
|
||
|
private void magicButton5_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
printReceipt = true;
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
checkTotal();
|
||
|
decimal bal = decimal.Parse(lblBal.Text.Substring(currency.Length));
|
||
|
CashierCustomerSettlePayment payment = new CashierCustomerSettlePayment(this, bal);
|
||
|
payment.BringToFront();
|
||
|
payment.ShowDialog();
|
||
|
clearCustomer();
|
||
|
lblTotalCol.Text = "00.00";
|
||
|
}
|
||
|
cart.Clear();
|
||
|
}
|
||
|
private void BtnDiscount_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can add a discount";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Discount discount = new Discount(this);
|
||
|
discount.BringToFront();
|
||
|
discount.ShowDialog();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
private void Timer1_Tick(object sender, EventArgs e)
|
||
|
{
|
||
|
timeStamp.Text = DateTime.Now.ToString("HH:mm:ss");
|
||
|
}
|
||
|
private void MagicButton2_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
string message = "Are you sure you would like to cancel this sale ?";
|
||
|
string title = "Confirmation";
|
||
|
Confirmation noAction = new Confirmation(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
if (noAction.DialogResult == DialogResult.Yes)
|
||
|
{
|
||
|
customer.Text = "";
|
||
|
customer.Visible = false;
|
||
|
dataGridView1.Rows.Clear();
|
||
|
newTransaction();
|
||
|
checkTotal();
|
||
|
}
|
||
|
}
|
||
|
private void BtnCancel_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
//only authorized users cancel
|
||
|
ReceiptModule cancellation = new ReceiptModule();
|
||
|
cancellation.BringToFront();
|
||
|
cancellation.ShowDialog();
|
||
|
}
|
||
|
private void BtnDaily_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
DailySales sales = new DailySales();
|
||
|
sales.BringToFront();
|
||
|
sales.ShowDialog();
|
||
|
}
|
||
|
private void magicButton3_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
printReceipt = true;
|
||
|
if (dataGridView1.Rows.Count == 0)
|
||
|
{
|
||
|
string title = "Cart empty";
|
||
|
string message = "Add items to cart before you can settle payment";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
settlePayment payment = new settlePayment(this);
|
||
|
payment.BringToFront();
|
||
|
payment.ShowDialog();
|
||
|
lblTotalCol.Text = "00.00";
|
||
|
}
|
||
|
cart.Clear();
|
||
|
}
|
||
|
private void lbldiscount_TextChanged(object sender, EventArgs e)
|
||
|
{
|
||
|
checkTotal();
|
||
|
}
|
||
|
private void button19_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
CashierCustomerBill customer = new CashierCustomerBill();
|
||
|
customer.BringToFront();
|
||
|
customer.ShowDialog();
|
||
|
if (customer.DialogResult == DialogResult.OK)
|
||
|
{
|
||
|
customerO = new CustomerClass();
|
||
|
customerO = customer.customer;
|
||
|
lblAddress.Text = customer.address;
|
||
|
lblTel.Text = customer.telephone;
|
||
|
lblName.Text = customer.name;
|
||
|
lblMail.Text = customer.email;
|
||
|
this.customer.Text = "Customer Name : " + customerO.firstname;
|
||
|
this.customer.Visible = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|