Fix: Sale Detail Report would not show the proper NC as it did not check of the product was Happy Hour and at times would overwrite the wrong value

Feature: Modifier form now resizes the buttons so that if there are more modifiers than can fit on the screen, the button size will reduce to a degree
Feature: The Final Sanction is also a background worker and reports progress.
This commit is contained in:
tanshu 2016-12-03 12:08:47 +05:30
parent 68388705f1
commit 3d3c21b853
6 changed files with 155 additions and 68 deletions

View File

@ -122,7 +122,7 @@ namespace Tanshu.Accounts.PointOfSale
}
catch (SqlException)
{
MessageBox.Show("Unable to connect to the server.\nPlease check that the this computer and the server both are on and connected to the network.", "Server Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Unable to connect to the server.\nPlease check that the server is on and both this computer and the server both are connected to the network.", "Server Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw;
}

View File

@ -8,6 +8,7 @@ using System.Web.Script.Serialization;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using System.ComponentModel;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.Management
{
@ -17,6 +18,7 @@ namespace Tanshu.Accounts.Management
Stopwatch _totalStopwatch;
private BackgroundWorker bwGo = new BackgroundWorker();
private BackgroundWorker bwExcel = new BackgroundWorker();
private BackgroundWorker bwFinalSanction = new BackgroundWorker();
public ManagementForm()
{
InitializeComponent();
@ -32,6 +34,12 @@ namespace Tanshu.Accounts.Management
bwExcel.DoWork += new DoWorkEventHandler(DoExcel);
bwExcel.ProgressChanged += new ProgressChangedEventHandler(bwGo_ProgressChanged);
bwExcel.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwExcel_RunWorkerCompleted);
bwFinalSanction.WorkerReportsProgress = true;
bwFinalSanction.WorkerSupportsCancellation = false;
bwFinalSanction.DoWork += new DoWorkEventHandler(DoFinalSanction);
bwFinalSanction.ProgressChanged += new ProgressChangedEventHandler(bwFinalSanction_ProgressChanged);
bwFinalSanction.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwFinalSanction_RunWorkerCompleted);
}
private void ManagementForm_Load(object sender, EventArgs e)
@ -85,50 +93,57 @@ namespace Tanshu.Accounts.Management
bwGo.ReportProgress(++count, "Starting on " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString());
using (var bi = new ManagementBI())
{
bwGo.ReportProgress(++count, "Clearing Modifiers");
bi.ClearModifiers(sDate, fDate);
bwGo.ReportProgress(++count, "Modifiers Cleared");
bwGo.ReportProgress(++count, " -- Modifiers Cleared");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Deleting Tobacco");
bi.DeleteTobacco(sDate, fDate);
bwGo.ReportProgress(++count, "Tobacco Deleted");
bwGo.ReportProgress(++count, " -- Tobacco Deleted");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Deleting Reprints");
bi.DeleteReprints(sDate, fDate);
bwGo.ReportProgress(++count, "Reprints Deleted");
bwGo.ReportProgress(++count, " -- Reprints Deleted");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Deleting Voids");
bi.DeleteVoid(sDate, fDate);
bwGo.ReportProgress(++count, "Voids Deleted");
bwGo.ReportProgress(++count, " -- Voids Deleted");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Combining Kots");
bi.CombineKots(sDate, fDate);
bwGo.ReportProgress(++count, "Kots Combined");
bwGo.ReportProgress(++count, " -- Kots Combined");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Removing Blank Kots");
bi.RemoveBlankKots(sDate, fDate);
bwGo.ReportProgress(++count, "Blank Kots Removed");
bwGo.ReportProgress(++count, " -- Blank Kots Removed");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Moving Staff to NC");
bi.MoveStaffToNc(sDate, fDate);
bwGo.ReportProgress(++count, "Staff Moved");
bwGo.ReportProgress(++count, " -- Staff Moved");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
@ -147,8 +162,9 @@ namespace Tanshu.Accounts.Management
return;
}
}
bwGo.ReportProgress(++count, "Removing Blank Kots");
bi.RemoveBlankKots(sDate, fDate);
bwGo.ReportProgress(++count, "Blank Kots Removed");
bwGo.ReportProgress(++count, " -- Blank Kots Removed");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
@ -179,13 +195,16 @@ namespace Tanshu.Accounts.Management
e.Cancel = true;
return;
}
bi.IncreaseLiqIfLess(item.Sale.Where(x=>x.IsLiq).ToList(), startDate, finishDate);
bi.IncreaseLiqIfLess(item.Sale.Where(x => x.IsLiq).ToList(), startDate, finishDate);
bwGo.ReportProgress(++count, "Sale Done");
if (bwGo.CancellationPending == true)
{
e.Cancel = true;
return;
}
bwGo.ReportProgress(++count, "Setting Payments");
bi.SetPayments(sDate, fDate);
bwGo.ReportProgress(++count, " -- Payments Set");
bi.SaveChanges();
}
bwGo.ReportProgress(++count, "Cleanup done");
@ -331,7 +350,8 @@ namespace Tanshu.Accounts.Management
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
var credit = Path.Combine(currentDirectory, "credit.json");
if (!File.Exists(credit))
throw new ArgumentException("Credit not found!");
return new List<CreditJson>();
// throw new ArgumentException("Credit not found!");
var startDate = dtpStart.Value.Date;
var finishDate = dtpFinish.Value.Date;
var fileContents = new StreamReader(File.OpenRead(credit)).ReadToEnd();
@ -558,15 +578,37 @@ namespace Tanshu.Accounts.Management
#endregion
private void btnFinalSanction_Click(object sender, EventArgs e)
{
txtStatus.Text = "";
_totalStopwatch = Stopwatch.StartNew();
bwFinalSanction.RunWorkerAsync();
}
private void DoFinalSanction(object sender, DoWorkEventArgs e)
{
var startDate = dtpStart.Value.Date.AddHours(7);
var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(7);
using (var bi = new ManagementBI())
{
bi.SetPayments(startDate, finishDate);
bi.UpdateBillID(startDate, finishDate);
bi.UpdateBillID(startDate, finishDate, bwFinalSanction);
bi.UpdateOtherBillID(startDate, finishDate, VoucherType.NoCharge, bwFinalSanction);
bi.UpdateOtherBillID(startDate, finishDate, VoucherType.Staff, bwFinalSanction);
bi.SaveChanges();
}
}
private void bwFinalSanction_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
var time = (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s";
txtStatus.Text = (string)e.UserState + " in " + time;
}
private void bwFinalSanction_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
var time = "Done in " + (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s";
_totalStopwatch.Stop();
txtStatus.Text = time;
}
}
}

View File

@ -30,7 +30,7 @@ namespace Tanshu.Accounts.PointOfSale
foreach (var item in bi.NcQuantity(dtpStart.Value, dtpFinish.Value))
{
var old = _list.FirstOrDefault(x => x.ProductID == item.ProductID);
var old = _list.FirstOrDefault(x => x.ProductID == item.ProductID && x.IsHappyHour == item.IsHappyHour);
if (old != null)
old.NC = item.NC;
else

View File

@ -28,20 +28,10 @@
/// </summary>
private void InitializeComponent()
{
this.flpModifier = new System.Windows.Forms.FlowLayoutPanel();
this.btnClose = new System.Windows.Forms.Button();
this.flpModifier.SuspendLayout();
this.flpModifier = new System.Windows.Forms.FlowLayoutPanel();
this.SuspendLayout();
//
// flpModifier
//
this.flpModifier.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.flpModifier.Dock = System.Windows.Forms.DockStyle.Bottom;
this.flpModifier.Location = new System.Drawing.Point(0, 84);
this.flpModifier.Name = "flpModifier";
this.flpModifier.Size = new System.Drawing.Size(486, 324);
this.flpModifier.TabIndex = 6;
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@ -54,28 +44,37 @@
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// flpModifier
//
this.flpModifier.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flpModifier.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.flpModifier.Location = new System.Drawing.Point(0, 84);
this.flpModifier.Name = "flpModifier";
this.flpModifier.Size = new System.Drawing.Size(486, 324);
this.flpModifier.TabIndex = 6;
this.flpModifier.Resize += new System.EventHandler(this.flpModifier_Resize);
//
// ModifierForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(486, 408);
this.ControlBox = false;
this.Controls.Add(this.btnClose);
this.Controls.Add(this.flpModifier);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Name = "ModifierForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Modifier";
this.Load += new System.EventHandler(this.ModifierForm_Load);
this.flpModifier.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.FlowLayoutPanel flpModifier;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.FlowLayoutPanel flpModifier;
}
}

View File

@ -15,13 +15,13 @@ namespace Tanshu.Accounts.PointOfSale
public partial class ModifierForm : Form
{
private IList<InventoryModifier> selection;
private IList<Modifier> source;
private IList<Modifier> modifiersList;
private IList<CheckBox> list;
public ModifierForm(IList<Modifier> source, IList<InventoryModifier> selection)
{
InitializeComponent();
this.selection = selection;
this.source = source;
this.modifiersList = source;
list = new List<CheckBox>();
}
@ -35,33 +35,61 @@ namespace Tanshu.Accounts.PointOfSale
else
selection.Remove(selection.First(x => x.Modifier.ModifierID == ((Modifier)button.Tag).ModifierID));
}
private static Point GetSize(FlowLayoutPanel panel, int count)
{
Point min = new Point(20, 50);
Point max = new Point(75, 75);
var marginWidth = panel.Margin.Right + panel.Margin.Left;
var marginHeight = panel.Margin.Top + panel.Margin.Bottom;
var rows = panel.ClientSize.Height / (max.Y + marginHeight);
var cols = panel.ClientSize.Width / (max.X + marginWidth);
var num = rows * cols;
if (num >= count)
return max;
var w = max.X;
var h = max.Y;
while (w > min.X && h > min.Y)
{
h = (panel.ClientSize.Height / (rows + 1)) - marginHeight;
if (h >= min.Y)
{
++rows;
}
if (rows * cols >= count)
break;
w = (panel.ClientSize.Width / (cols + 1)) - marginWidth;
if (w >= min.X)
{
++cols;
}
if (rows * cols >= count)
break;
}
max.X = (panel.ClientSize.Width / cols) - marginWidth;
max.Y = (panel.ClientSize.Height / rows) - marginHeight;
return max;
}
private void ModifierForm_Load(object sender, EventArgs e)
{
var size = new Point(75, 75);
int count = 30;
var size = GetSize(flpModifier, modifiersList.Count);
ButtonClickDelegate bcDelegate = new ButtonClickDelegate(button_Click);
if (list.Count != 0)
{
for (int i = list.Count - 1; i >= 0; i--)
{
list[i].Dispose();
}
list = new List<CheckBox>();
}
if (count > source.Count)
count = source.Count;
for (int i = 0; i < count; i++)
for (int i = 0; i < modifiersList.Count; i++)
{
var control = new CheckBox()
{
Name = i.ToString(),
Text = source[i].Name,
Text = modifiersList[i].Name,
Width = size.X,
Height = size.Y,
Tag = source[i],
Tag = modifiersList[i],
Appearance = Appearance.Button,
Checked = selection.Count(x => x.Modifier.ModifierID == source[i].ModifierID) > 0
Checked = selection.Count(x => x.Modifier.ModifierID == modifiersList[i].ModifierID) > 0
};
control.Click += new EventHandler(bcDelegate);
flpModifier.Controls.Add(control);
@ -73,5 +101,15 @@ namespace Tanshu.Accounts.PointOfSale
{
this.Close();
}
private void flpModifier_Resize(object sender, EventArgs e)
{
var size = GetSize(flpModifier, modifiersList.Count);
foreach (var item in list)
{
item.Width = size.X;
item.Height = size.Y;
}
}
}
}

View File

@ -5,6 +5,7 @@ using System.Globalization;
using System.Linq;
using NHibernate;
using Tanshu.Accounts.Entities;
using System.ComponentModel;
namespace Tanshu.Accounts.Repository
{
@ -386,7 +387,7 @@ where vs.Voucher.VoucherID = :voucherID and (
_session.Insert(new VoucherSettlement() { Voucher = new Voucher() { VoucherID = item.Key }, Amount = -1 * (amount + roundoff), Settled = settlementType });
}
}
public void UpdateBillID(DateTime startDate, DateTime finishDate)
public void UpdateBillID(DateTime startDate, DateTime finishDate, BackgroundWorker bw)
{
var query = @"
select MAX(v.BillID)
@ -404,13 +405,13 @@ where v.Date < :startDate and v.Void = false and v.VoucherType in (:regular, :ta
.Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && (x.VoucherType == VoucherType.Regular || x.VoucherType == VoucherType.TakeAway))
.OrderBy(x => x.Date).Asc
.List();
var count = " of" + list.Count.ToString();
var count = " of " + list.Count.ToString();
var i = 0;
foreach (var voucher in list)
{
i++;
if (i % 20 == 0)
Console.WriteLine("Loop " + i.ToString() + count);
bw.ReportProgress(0, "Loop " + i.ToString() + count);
if (voucher.BillID != newID)
{
var update = _session.CreateSQLQuery("exec UpdateBillID ?,?");
@ -420,26 +421,31 @@ where v.Date < :startDate and v.Void = false and v.VoucherType in (:regular, :ta
}
newID = GetNewID(newID);
}
}
query = @"
select coalesce(v.BillID + 1, 1)
public void UpdateOtherBillID(DateTime startDate, DateTime finishDate, VoucherType vt, BackgroundWorker bw)
{
var query = @"
select MAX(v.BillID)
from Voucher v
where v.Date < :startDate and v.Void = false and v.VoucherType = :nc
order by v.Date desc
";
lastBill = _session
where v.Date < :startDate and v.Void = false and v.VoucherType = :vt";
var lastBill = _session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("nc", VoucherType.NoCharge)
.SetMaxResults(1)
.SetParameter("vt", vt)
.UniqueResult();
newID = (int)lastBill;
list = _session.QueryOver<Voucher>()
.Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.NoCharge && x.Void == false)
var newID = lastBill == null ? 1 : (int)lastBill + 1;
var list = _session.QueryOver<Voucher>()
.Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType == vt)
.OrderBy(x => x.Date).Asc
.List();
var count = " of " + list.Count.ToString();
var i = 0;
foreach (var voucher in list)
{
i++;
if (i % 20 == 0)
bw.ReportProgress(0, "Loop " + i.ToString() + count);
if (voucher.BillID != newID)
{
var update = _session.CreateSQLQuery("exec UpdateBillID ?,?");
@ -450,7 +456,6 @@ order by v.Date desc
newID += 1;
}
}
private static int GetNewID(int lastBill)
{
lastBill += 1;
@ -740,11 +745,11 @@ and v.VoucherType = :regular";
continue;
//throw new ArgumentException("Unknown type of vat rate encountered");
if (c == null) // Means no credit card for the day
c = new CreditJson() { _date = inv.Date.ToString("dd-MMM-yyyy"), Amount = 0 };
c = new CreditJson() { _date = inv.Date.ToString("dd-MMM-yyyy"), Amount = s.Amount };
// throw new ArgumentException("Unknown date encountered");
if (Math.Abs(s.Amount) < 10)
if (Math.Abs(s.Amount) < 1)
continue; // Close enough for now
if (s.Amount > 0 && c.Amount < 10)
if (s.Amount > 0 && c.Amount <= 0)
continue; //Move on if we have to reduce and we do not have credit sale margin
if (!s.IsLiq) //Food
{
@ -772,7 +777,8 @@ and v.VoucherType = :regular";
}
else
{
DecreaseLiqour(rand, s, inv, c);
if (inv.Inv.Quantity != 0 && inv.Inv.EffectivePrice != 0)
DecreaseLiqour(rand, s, inv, c);
}
}
}
@ -809,7 +815,7 @@ and v.VoucherType = :regular";
if (s == null) // Temp ignore and move on
continue;
//throw new ArgumentException("Unknown type of vat rate encountered");
if (Math.Abs(s.Amount) < 10)
if (Math.Abs(s.Amount) < 2)
continue; // Close enough for now
if (s.Amount >= 0)
continue; //Move on if we have to reduce and we do not have credit sale margin
@ -999,6 +1005,8 @@ and p.Quantity != 0";
inventories.Add(inventoryID, new object[] { productID, inventoryQuantity, productQuantity });
}
var left = GetBeer(startDate, finishDate) - quantity;
if (left < 0)
Console.Write("Beer was already negative");
foreach (var item in inventories)
{
if (left <= 0)