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

@ -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;
}
}
}