diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs index 4982038..cf31593 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/ProductBO.cs @@ -9,7 +9,6 @@ namespace Tanshu.Accounts.Entities public class Product { public virtual Guid ProductID { get; set; } - public virtual int Code { get; set; } public virtual string Name { get; set; } public virtual string Units { get; set; } public virtual ProductGroup ProductGroup { get; set; } @@ -22,7 +21,6 @@ namespace Tanshu.Accounts.Entities public virtual bool IsActive { get; set; } public virtual bool IsNotAvailable { get; set; } public virtual int SortOrder { get; set; } - public virtual int BaseCode { get; set; } public virtual decimal Quantity { get; set; } public virtual IList Inventories { get; set; } @@ -36,7 +34,6 @@ namespace Tanshu.Accounts.Entities Schema("dbo"); Lazy(true); Id(x => x.ProductID, map => map.Generator(Generators.GuidComb)); - Property(x => x.Code); Property(x => x.Name, map => { map.NotNullable(true); map.UniqueKey("UQ_NameUnits"); }); Property(x => x.Units, map => { map.NotNullable(true); map.UniqueKey("UQ_NameUnits"); }); Property(x => x.ServiceCharge, map => map.NotNullable(true)); @@ -46,7 +43,6 @@ namespace Tanshu.Accounts.Entities Property(x => x.IsActive, map => map.NotNullable(true)); Property(x => x.IsNotAvailable, map => map.NotNullable(true)); Property(x => x.SortOrder, map => map.NotNullable(true)); - Property(x => x.BaseCode, map => map.NotNullable(true)); Property(x => x.Quantity, map => map.NotNullable(true)); ManyToOne(x => x.ProductGroup, map => { map.Column("ProductGroupID"); map.Cascade(Cascade.None); }); diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs index 18b009a..fb1e898 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs @@ -9,7 +9,7 @@ namespace Tanshu.Accounts.Entities { public class Voucher { - protected Voucher() + public Voucher() { Kots = new List(); Settlements = new List(); diff --git a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs index 288113e..e6296ec 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs @@ -4,13 +4,17 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Web.Script.Serialization; using System.Windows.Forms; using Tanshu.Accounts.Repository; +using System.ComponentModel; namespace Tanshu.Accounts.Management { public partial class ManagementForm : Form { + Stopwatch _stopwatch; + Stopwatch _totalStopwatch; public ManagementForm() { InitializeComponent(); @@ -22,12 +26,21 @@ namespace Tanshu.Accounts.Management dtpFinish.Value = DateTime.Today; } + #region Go private void btnGo_Click(object sender, EventArgs e) + { + txtStatus.Text = ""; + btnGo.Enabled = false; + _stopwatch = Stopwatch.StartNew(); + _totalStopwatch = Stopwatch.StartNew(); + bwGo.RunWorkerAsync(); + } + private void DoGo(BackgroundWorker worker) { var currentDirectory = AppDomain.CurrentDomain.BaseDirectory; - var beer = Path.Combine(currentDirectory, "beer.csv"); - var sale = Path.Combine(currentDirectory, "sale.csv"); - var credit = Path.Combine(currentDirectory, "credit.csv"); + var beer = Path.Combine(currentDirectory, "beer.json"); + var sale = Path.Combine(currentDirectory, "sale.json"); + var credit = Path.Combine(currentDirectory, "credit.json"); var error = string.Empty; if (!File.Exists(beer)) error += "Beer not found! "; @@ -49,246 +62,138 @@ namespace Tanshu.Accounts.Management var info = string.Empty; foreach (var item in saleDates) { - var startDate = item.StartDate; - var finishDate = item.FinishDate; - Debug.WriteLine("Starting on " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString()); - ProcessData(true, startDate, finishDate, item.Sale15 + item.Sale25); - Debug.WriteLine("Starting beer"); - ProcessBeer(beerDates, startDate, finishDate); - Debug.WriteLine("Starting sale"); - info += ProcessSale(item, creditDates); - Debug.WriteLine("Starting cleanup"); - ProcessData(false, startDate, finishDate, item.Sale15 + item.Sale25); - Debug.WriteLine("Cleanup done"); - } - MessageBox.Show(info); - btnGo.Enabled = true; - } - } - - #region Get Data - protected class SaleData - { - public DateTime StartDate { get; set; } - public DateTime FinishDate { get; set; } - public decimal Sale125 { get; set; } - public decimal Sale25 { get; set; } - public decimal Sale15 { get; set; } - public decimal Sale0 { get; set; } - } - private IEnumerable GetSale(string sale) - { - IFormatProvider culture = new CultureInfo("en-US", true); - var startDate = dtpStart.Value.Date; - var finishDate = dtpFinish.Value.Date; - - var dates = new List(); - using (var reader = new StreamReader(File.OpenRead(sale))) - { - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - var values = line.Split(','); - if (values.Length != 6) + var startDate = item.SDate.Value; + var finishDate = item.FDate.Value; + var sDate = startDate.AddHours(7); + var fDate = finishDate.AddDays(1).AddHours(7); + Console.WriteLine("Starting on " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString()); + int count = 0; + using (var bi = new ManagementBI()) { - MessageBox.Show("Error reading line: " + line); - continue; + worker.ReportProgress(++count, "Deleting Voids"); + bi.DeleteVoid(sDate, fDate); + worker.ReportProgress(++count, "Deleting Staff"); + bi.MoveStaffToNc(sDate, fDate); + worker.ReportProgress(++count, "Clearing Modifiers"); + bi.ClearModifiers(sDate, fDate); + worker.ReportProgress(++count, "Combining Kots"); + bi.CombineKots(sDate, fDate); + worker.ReportProgress(++count, "Removing Blank Kots"); + bi.RemoveBlankKots(sDate, fDate); + worker.ReportProgress(++count, "Starting beer"); + foreach (var beerDate in beerDates) + { + if (beerDate.bDate < startDate || beerDate.bDate > finishDate) + continue; + var stDt = beerDate.bDate.Value.AddHours(7); + var fiDt = stDt.AddDays(1); + worker.ReportProgress(++count, "Setting beer for " + stDt.ToShortDateString()); + bi.SetBeer(stDt, fiDt, beerDate.Quantity); + } + bi.MoveToNc(sDate, fDate, item.Sale.Where(x => x.IsLiq).Sum(x => x.Amount) / .75M); // Do not put all in NC this will allow for about 25% discount on the rest of non nc liqour + worker.ReportProgress(++count, "Starting sale"); + foreach (var saleItem in item.Sale) + { + worker.ReportProgress(++count, "Setting sale for " + saleItem.Rate.ToString()); + if (saleItem.IsLiq) + bi.SetSaleDiscount(saleItem.Rate, saleItem.Amount, sDate, fDate); + else + bi.SetSaleQuantity(saleItem.Rate, saleItem.Amount, sDate, fDate); + } + worker.ReportProgress(++count, "Removing Blank Kots"); + bi.RemoveBlankKots(sDate, fDate); + worker.ReportProgress(++count, "Starting cleanup"); + bi.SetPayments(sDate, fDate); + bi.SaveChanges(); } - DateTime dateStart; - DateTime dateFinish; - if (!DateTime.TryParseExact(values[0], "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dateStart)) - continue; - if (!DateTime.TryParseExact(values[1], "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dateFinish)) - continue; - if (dateFinish.Date < startDate.Date || dateStart.Date > finishDate.Date) - continue; - dates.Add(new SaleData - { - StartDate = dateStart, - FinishDate = dateFinish, - Sale125 = TryConvert(values[2]), - Sale25 = TryConvert(values[3]), - Sale15 = TryConvert(values[4]), - Sale0 = TryConvert(values[5]) - }); + worker.ReportProgress(++count, "Cleanup done"); } } - return dates; } - private Dictionary GetCredit(string credit) + private void bwGo_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { - IFormatProvider culture = new CultureInfo("en-US", true); - var startDate = dtpStart.Value.Date.AddHours(7); - var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(7); - - var dates = new Dictionary(); - using (var reader = new StreamReader(File.OpenRead(credit))) - { - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - var values = line.Split(','); - if (values.Length != 2) - { - MessageBox.Show("Error reading line: " + line); - continue; - } - DateTime dateOut; - if (!DateTime.TryParseExact(values[0], "dd/MM/yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dateOut)) - continue; - if (dateOut.Date < startDate.Date || dateOut.Date >= finishDate.Date) - continue; - var amount = TryConvert(values[1]); - if (!dates.ContainsKey(dateOut)) - dates.Add(dateOut, amount); - } - } - return dates; + DoGo(sender as BackgroundWorker); } - private Dictionary GetBeer(string beer) + private void bwGo_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { - IFormatProvider culture = new CultureInfo("en-US", true); - var startDate = dtpStart.Value.Date.AddHours(7); - var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(7); - - var dates = new Dictionary(); - using (var reader = new StreamReader(File.OpenRead(beer))) - { - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - var values = line.Split(','); - DateTime dateOut; - if (!DateTime.TryParseExact(values[0], "dd-MMM-yy", culture, DateTimeStyles.NoCurrentDateDefault, out dateOut)) - continue; - if (dateOut.Date < startDate.Date || dateOut.Date >= finishDate.Date) - continue; - decimal amount = 0; - if (values.Length > 1) // Dark - Location 1, Basecode 1 - amount += TryConvert(values[1]); - if (values.Length > 2) // Wheat - Location 2, Basecode 2 - amount += TryConvert(values[2]); - if (values.Length > 3) // Light - Location 3, Basecode 4 - amount += TryConvert(values[3]); - if (values.Length > 4) // Premium - Location 4, Basecode 3 - amount += TryConvert(values[4]); - dates.Add(dateOut, amount); - } - } - return dates; + var time = (_stopwatch.ElapsedMilliseconds / 1000).ToString() + "s / " + (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s"; + _stopwatch.Reset(); + _stopwatch.Start(); + txtStatus.Text = (string)e.UserState + " " + time + " \r\n" + txtStatus.Text; + } + private void bwGo_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) + { + txtStatus.Text += "Done !!!"; + _stopwatch.Stop(); + _totalStopwatch.Stop(); + btnGo.Enabled = true; } #endregion - private static void ProcessData(bool opening, DateTime startIn, DateTime finishIn, decimal liqTarget) + + #region Get Data + private IList GetSale(string sale) { - var startDate = startIn.AddHours(7); - var finishDate = finishIn.AddDays(1).AddHours(7); - if (opening) + var startDate = dtpStart.Value.Date; + var finishDate = dtpFinish.Value.Date; + var fileContents = new StreamReader(File.OpenRead(sale)).ReadToEnd(); + JavaScriptSerializer jss = new JavaScriptSerializer(); + var data = jss.Deserialize>(fileContents); + IList list = new List(); + foreach (var item in data) { - using (var bi = new ManagementBI()) - { - bi.DeleteVoid(startDate, finishDate); - } - using (var bi = new ManagementBI()) - { - bi.DeleteStaff(startDate, finishDate); - } - using (var bi = new ManagementBI()) - { - bi.ClearModifiers(startDate, finishDate); - } - using (var bi = new ManagementBI()) - { - bi.CombineKots(startDate, finishDate); - } - using (var bi = new ManagementBI()) - { - bi.RemoveBlankKots(startDate, finishDate); - } - using (var bi = new ManagementBI()) - { - bi.MoveNc(startDate, finishDate, liqTarget); - } - } - else - { - using (var bi = new ManagementBI()) - { - bi.SetPayments(startDate, finishDate); - } + if (!item.SDate.HasValue || !item.FDate.HasValue) + continue; + if (item.FDate.Value.Date < startDate.Date || item.SDate.Value.Date > finishDate.Date) + continue; + list.Add(item); } + return list; } - - private static void ProcessBeer(Dictionary dates, DateTime startIn, DateTime finishIn) + private IList GetCredit(string credit) { - using (var bi = new ManagementBI()) + var startDate = dtpStart.Value.Date; + var finishDate = dtpFinish.Value.Date; + var fileContents = new StreamReader(File.OpenRead(credit)).ReadToEnd(); + JavaScriptSerializer jss = new JavaScriptSerializer(); + var data = jss.Deserialize>(fileContents); + IList list = new List(); + foreach (var item in data) { - var info = string.Empty; - foreach (var item in dates) - { - if (item.Key < startIn || item.Key > finishIn) - continue; - var stDt = item.Key.AddHours(7); - var fiDt = stDt.AddDays(1); - var original = bi.GetQuantity(stDt, fiDt); - if (original < item.Value) - { - info += "Original for " + item.Key.ToString() + " is " + original.ToString() + " desired is " + item.Value.ToString() + "\r\n"; - } - else if (original == item.Value) - { - info += item.Key.ToString() + " is " + original.ToString() + " matches!" + "\r\n"; - } - else - { - bi.SetQuantity(stDt, fiDt, item.Value); - } - } + if (!item.CDate.HasValue) + continue; + if (item.CDate.Value.Date < startDate.Date || item.CDate.Value.Date > finishDate.Date) + continue; + list.Add(item); } + return list; } - - private static string ProcessSale(SaleData item, Dictionary creditDates) + private IList GetBeer(string beer) { - var info = string.Empty; - var startDate = item.StartDate.AddHours(7); - var finishDate = item.FinishDate.AddHours(7).AddDays(1); - var creditInfo = creditDates.Where(x => x.Key >= item.StartDate && x.Key <= item.FinishDate).ToDictionary(x => x.Key, x => x.Value); - - info += "From " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString() + "\r\n"; - - using (var bi = new ManagementBI()) + var startDate = dtpStart.Value.Date; + var finishDate = dtpFinish.Value.Date; + var fileContents = new StreamReader(File.OpenRead(beer)).ReadToEnd(); + JavaScriptSerializer jss = new JavaScriptSerializer(); + var data = jss.Deserialize>(fileContents); + IList list = new List(); + foreach (var item in data) { - info += "25%\t" + bi.GetFood(.26250M, startDate, finishDate) + "\t"; - var ret = bi.SetLiq(.26250M, item.Sale25, startDate, finishDate); - info += ret + "\t" + item.Sale25.ToString() + "\r\n"; + if (!item.bDate.HasValue) + continue; + if (item.bDate.Value.Date < startDate.Date || item.bDate.Value.Date > finishDate.Date) + continue; + list.Add(item); } - using (var bi = new ManagementBI()) - { - info += "15%\t" + bi.GetFood(.1575M, startDate, finishDate) + "\t"; - var ret = bi.SetLiq(.1575M, item.Sale15, startDate, finishDate); - info += ret + "\t" + item.Sale15.ToString() + "\r\n"; - } - using (var bi = new ManagementBI()) - { - info += "12.5%\t" + bi.GetFood(.13125M, startDate, finishDate) + "\t"; - var ret = bi.SetFood(.13125M, item.Sale125, startDate, finishDate); - info += ret + "\t" + item.Sale125.ToString() + "\r\n"; - } - using (var bi = new ManagementBI()) - { - info += "0%\t" + bi.GetFood(0M, startDate, finishDate) + "\t"; - var ret = bi.SetFood(0M, item.Sale0, startDate, finishDate); - info += ret + "\t" + item.Sale0.ToString() + "\r\n"; - } - return info; + return list; } - private static decimal TryConvert(string amount) { decimal result = 0; decimal.TryParse(amount, out result); return result; } + #endregion + #region Tally private void btnTally_Click(object sender, EventArgs e) { var startDate = dtpStart.Value.Date; @@ -331,49 +236,27 @@ namespace Tanshu.Accounts.Management var cash = 0M; using (var bi = new ManagementBI()) { - var sale = Math.Round(bi.GetFood(.26250M, currentStart, currentFinish)); - var vat = 0M; - if (sale != 0) + var saleAndVat = bi.GetSaleAndVat(currentStart, currentFinish); + foreach (var item in saleAndVat) { - cash += sale; - voucher += GetLedger("Sale @ 25 %", sale.ToString("#0.00")); - vat = Math.Round(bi.GetVat(.26250M, currentStart, currentFinish)); - cash += vat; - voucher += GetLedger("Output Vat @ 25%", vat.ToString("#0.00")); + if (item.Net == 0) + throw new ArgumentException(); + cash += Math.Round(item.Net); + var rate = item.Rate * 100 / 1.05M; + voucher += GetLedger(string.Format("Sale @ {0:#} %", rate), item.Net.ToString("#0.00")); + var vat = Math.Round(item.Vat); + if (vat != 0) + { + cash += vat; + voucher += GetLedger(string.Format("Output Vat @ {0:#}%", rate), vat.ToString("#0.00")); + } } - sale = Math.Round(bi.GetFood(.1575M, currentStart, currentFinish)); - if (sale != 0) + var st = Math.Round(bi.GetServiceTax(currentStart, currentFinish)); + if (st != 0) { - cash += sale; - voucher += GetLedger("Sale @ 15%", sale.ToString("#0.00")); - vat = Math.Round(bi.GetVat(.1575M, currentStart, currentFinish)); - cash += vat; - voucher += GetLedger("Output Vat @ 15%", vat.ToString("#0.00")); - } - - sale = Math.Round(bi.GetFood(.13125M, currentStart, currentFinish)); - if (sale != 0) - { - cash += sale; - voucher += GetLedger("Sale 12.5%", sale.ToString("#0.00")); - vat = Math.Round(bi.GetVat(.13125M, currentStart, currentFinish)); - cash += vat; - voucher += GetLedger("Output Vat 12.5%", vat.ToString("#0.00")); - } - - sale = Math.Round(bi.GetFood(0M, currentStart, currentFinish)); - if (sale != 0) - { - cash += sale; - voucher += GetLedger("Sale Tax Free", sale.ToString("#0.00")); - } - - vat = Math.Round(bi.GetServiceTax(currentStart, currentFinish)); - if (vat != 0) - { - cash += vat; - voucher += GetLedger("Central Service Tax@3.708%", vat.ToString("#0.00")); + cash += st; + voucher += GetLedger("Central Service Tax", st.ToString("#0.00")); } if (cash != 0) @@ -488,51 +371,87 @@ namespace Tanshu.Accounts.Management #endregion return string.Format(template, ledgername, isDeemedPositive, isPartyLedger, amount); } + #endregion + private void btnFinalSanction_Click(object sender, EventArgs e) { using (var bi = new ManagementBI()) { - bi.FinalSanction(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7)); + bi.UpdateBillID(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7)); + bi.SaveChanges(); } } + #region Excel private void btnExcel_Click(object sender, EventArgs e) { btnExcel.Enabled = false; var startDate = dtpStart.Value.Date; var finishDate = dtpFinish.Value.Date; - var sheet = "Date\t Bill Start\t Bill Final\t Sale 0%\t Sale 12.5%\t Sale 15%\t Sale 25%\t Vat 12.5%\t Vat 15%\t Vat 25%\t Service Tax\n"; - for (var date = startDate; date <= finishDate; date = date.AddDays(1)) - { - sheet += GetExcel(date); - } + var sheet = GetExcel(startDate, finishDate); Clipboard.SetText(sheet, TextDataFormat.Text); btnExcel.Enabled = true; } - private static string GetExcel(DateTime date) + private static string GetExcel(DateTime startDate, DateTime finishDate) { + var info = new List(); + var rates = new List(); using (var bi = new ManagementBI()) { - var currentStart = date.AddHours(7); - var currentFinish = date.AddDays(1).AddHours(7); - var cash = bi.GetFirstBill(date); - if (cash == "") - return ""; - cash = string.Format("{0:dd-MMM-yyyy}\t'{1}\t'{2}\t", date, cash, bi.GetLastBill(date)); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(0M, currentStart, currentFinish))); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(.13125M, currentStart, currentFinish))); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(.1575M, currentStart, currentFinish))); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(.2625M, currentStart, currentFinish))); + for (var date = startDate; date <= finishDate; date = date.AddDays(1)) + { + var currentStart = date.AddHours(7); + var currentFinish = date.AddDays(1).AddHours(7); + var bills = bi.GetMinMaxBills(currentStart, currentFinish); + if (bills == null) + continue; + var saleList = bi.GetSaleAndVat(currentStart, currentFinish); + var serviceTax = bi.GetServiceTax(currentStart, currentFinish); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetVat(.13125M, currentStart, currentFinish))); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetVat(.1575M, currentStart, currentFinish))); - cash += string.Format("{0:#0}\t", Math.Round(bi.GetVat(.2625M, currentStart, currentFinish))); + var ei = new ExcelInfo() + { + Date = date, + StartBill = bi.FullBillID(bills.StartBill, Tanshu.Accounts.Entities.VoucherType.Regular), + FinishBill = bi.FullBillID(bills.FinishBill, Tanshu.Accounts.Entities.VoucherType.Regular), + SaleAndVat = new Dictionary(), + ServiceTax = serviceTax + }; + foreach (var item in saleList) + { + if (!rates.Contains(item.Rate)) + rates.Add(item.Rate); + ei.SaleAndVat.Add(item.Rate, item); + } + info.Add(ei); + } - cash += string.Format("{0:#0}\n", Math.Round(bi.GetServiceTax(currentStart, currentFinish))); - return cash; + rates.Sort(); + + var sheet = "Date\tBill Start\tBill Final\t"; + + foreach (var item in rates) + { + sheet += string.Format("Sale {0:#0.00}%\tVat {0:#0.00}%\t", item * 100); + } + sheet += "Service Tax\n"; + + foreach (var item in info) + { + sheet += string.Format("{0:dd-MMM-yyyy}\t'{1}\t'{2}\t", item.Date, item.StartBill, item.FinishBill); + foreach (var rate in rates) + { + if (item.SaleAndVat.ContainsKey(rate)) + sheet += string.Format("{0:#0}\t{1:#0}\t", Math.Round(item.SaleAndVat[rate].Net), Math.Round(item.SaleAndVat[rate].Vat)); + else + sheet += "0\t0\t"; + } + sheet += string.Format("{0:#0}\n", Math.Round(item.ServiceTax)); + + } + return sheet; } } - + #endregion } } diff --git a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs index 0131b2f..74f5314 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs @@ -35,6 +35,8 @@ this.btnTally = new System.Windows.Forms.Button(); this.btnFinalSanction = new System.Windows.Forms.Button(); this.btnExcel = new System.Windows.Forms.Button(); + this.bwGo = new System.ComponentModel.BackgroundWorker(); + this.txtStatus = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // dtpFinish @@ -66,10 +68,9 @@ // // btnGo // - this.btnGo.Enabled = false; this.btnGo.Location = new System.Drawing.Point(12, 207); this.btnGo.Name = "btnGo"; - this.btnGo.Size = new System.Drawing.Size(150, 23); + this.btnGo.Size = new System.Drawing.Size(113, 23); this.btnGo.TabIndex = 24; this.btnGo.Text = "Go"; this.btnGo.UseVisualStyleBackColor = true; @@ -77,9 +78,9 @@ // // btnTally // - this.btnTally.Location = new System.Drawing.Point(168, 207); + this.btnTally.Location = new System.Drawing.Point(145, 207); this.btnTally.Name = "btnTally"; - this.btnTally.Size = new System.Drawing.Size(150, 23); + this.btnTally.Size = new System.Drawing.Size(113, 23); this.btnTally.TabIndex = 25; this.btnTally.Text = "Tally"; this.btnTally.UseVisualStyleBackColor = true; @@ -89,7 +90,7 @@ // this.btnFinalSanction.Location = new System.Drawing.Point(12, 178); this.btnFinalSanction.Name = "btnFinalSanction"; - this.btnFinalSanction.Size = new System.Drawing.Size(150, 23); + this.btnFinalSanction.Size = new System.Drawing.Size(113, 23); this.btnFinalSanction.TabIndex = 26; this.btnFinalSanction.Text = "Final Sanction"; this.btnFinalSanction.UseVisualStyleBackColor = true; @@ -97,19 +98,38 @@ // // btnExcel // - this.btnExcel.Location = new System.Drawing.Point(168, 178); + this.btnExcel.Location = new System.Drawing.Point(145, 178); this.btnExcel.Name = "btnExcel"; - this.btnExcel.Size = new System.Drawing.Size(150, 23); + this.btnExcel.Size = new System.Drawing.Size(113, 23); this.btnExcel.TabIndex = 27; this.btnExcel.Text = "Excel"; this.btnExcel.UseVisualStyleBackColor = true; this.btnExcel.Click += new System.EventHandler(this.btnExcel_Click); // + // bwGo + // + this.bwGo.WorkerReportsProgress = true; + this.bwGo.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bwGo_DoWork); + this.bwGo.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bwGo_RunWorkerCompleted); + this.bwGo.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bwGo_ProgressChanged); + // + // txtStatus + // + this.txtStatus.AcceptsReturn = true; + this.txtStatus.Location = new System.Drawing.Point(12, 38); + this.txtStatus.Multiline = true; + this.txtStatus.Name = "txtStatus"; + this.txtStatus.ReadOnly = true; + this.txtStatus.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.txtStatus.Size = new System.Drawing.Size(246, 134); + this.txtStatus.TabIndex = 28; + // // ManagementForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(359, 242); + this.ClientSize = new System.Drawing.Size(270, 242); + this.Controls.Add(this.txtStatus); this.Controls.Add(this.btnExcel); this.Controls.Add(this.btnFinalSanction); this.Controls.Add(this.btnTally); @@ -136,5 +156,7 @@ private System.Windows.Forms.Button btnTally; private System.Windows.Forms.Button btnFinalSanction; private System.Windows.Forms.Button btnExcel; + private System.ComponentModel.BackgroundWorker bwGo; + private System.Windows.Forms.TextBox txtStatus; } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx index 19dc0dd..e00c01d 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Products/ProductForm.Designer.cs index c69bf4b..9faeb95 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ProductForm.Designer.cs @@ -34,9 +34,6 @@ this.Label7 = new System.Windows.Forms.Label(); this.bsServiceTax = new System.Windows.Forms.BindingSource(this.components); this.label5 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); - this.txtProductID = new System.Windows.Forms.TextBox(); - this.txtCode = new System.Windows.Forms.TextBox(); this.Label2 = new System.Windows.Forms.Label(); this.txtUnits = new System.Windows.Forms.TextBox(); this.txtName = new System.Windows.Forms.TextBox(); @@ -54,6 +51,7 @@ this.label6 = new System.Windows.Forms.Label(); this.chkIsScTaxable = new System.Windows.Forms.CheckBox(); this.chkIsNotAvailable = new System.Windows.Forms.CheckBox(); + this.label1 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.bsProductGroups)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bsServiceTax)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bsVat)).BeginInit(); @@ -62,7 +60,7 @@ // Label4 // this.Label4.AutoSize = true; - this.Label4.Location = new System.Drawing.Point(19, 67); + this.Label4.Location = new System.Drawing.Point(19, 41); this.Label4.Name = "Label4"; this.Label4.Size = new System.Drawing.Size(85, 13); this.Label4.TabIndex = 15; @@ -75,7 +73,7 @@ // Label7 // this.Label7.AutoSize = true; - this.Label7.Location = new System.Drawing.Point(70, 169); + this.Label7.Location = new System.Drawing.Point(70, 143); this.Label7.Name = "Label7"; this.Label7.Size = new System.Drawing.Size(36, 13); this.Label7.TabIndex = 17; @@ -88,42 +86,16 @@ // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(26, 143); + this.label5.Location = new System.Drawing.Point(26, 117); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(80, 13); this.label5.TabIndex = 16; this.label5.Text = "Service Charge"; // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(12, 15); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(94, 13); - this.label3.TabIndex = 13; - this.label3.Text = "Product ID / Code"; - // - // txtProductID - // - this.txtProductID.Location = new System.Drawing.Point(112, 12); - this.txtProductID.Name = "txtProductID"; - this.txtProductID.ReadOnly = true; - this.txtProductID.Size = new System.Drawing.Size(189, 20); - this.txtProductID.TabIndex = 12; - // - // txtCode - // - this.txtCode.AccessibleName = ""; - this.txtCode.Location = new System.Drawing.Point(307, 12); - this.txtCode.Name = "txtCode"; - this.txtCode.Size = new System.Drawing.Size(96, 20); - this.txtCode.TabIndex = 0; - this.txtCode.WordWrap = false; - // // Label2 // this.Label2.AutoSize = true; - this.Label2.Location = new System.Drawing.Point(36, 41); + this.Label2.Location = new System.Drawing.Point(36, 15); this.Label2.Name = "Label2"; this.Label2.Size = new System.Drawing.Size(70, 13); this.Label2.TabIndex = 14; @@ -132,7 +104,7 @@ // txtUnits // this.txtUnits.AccessibleName = ""; - this.txtUnits.Location = new System.Drawing.Point(307, 38); + this.txtUnits.Location = new System.Drawing.Point(307, 12); this.txtUnits.Name = "txtUnits"; this.txtUnits.Size = new System.Drawing.Size(96, 20); this.txtUnits.TabIndex = 2; @@ -140,7 +112,7 @@ // txtName // this.txtName.AccessibleName = ""; - this.txtName.Location = new System.Drawing.Point(112, 38); + this.txtName.Location = new System.Drawing.Point(112, 12); this.txtName.Name = "txtName"; this.txtName.Size = new System.Drawing.Size(189, 20); this.txtName.TabIndex = 1; @@ -148,7 +120,7 @@ // txtPrice // this.txtPrice.AccessibleName = ""; - this.txtPrice.Location = new System.Drawing.Point(112, 64); + this.txtPrice.Location = new System.Drawing.Point(112, 38); this.txtPrice.Name = "txtPrice"; this.txtPrice.Size = new System.Drawing.Size(104, 20); this.txtPrice.TabIndex = 3; @@ -159,7 +131,7 @@ this.cmbVat.DataSource = this.bsVat; this.cmbVat.DisplayMember = "Name"; this.cmbVat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cmbVat.Location = new System.Drawing.Point(112, 114); + this.cmbVat.Location = new System.Drawing.Point(112, 88); this.cmbVat.Name = "cmbVat"; this.cmbVat.Size = new System.Drawing.Size(189, 21); this.cmbVat.TabIndex = 4; @@ -172,7 +144,7 @@ // chkIsActive // this.chkIsActive.AutoSize = true; - this.chkIsActive.Location = new System.Drawing.Point(307, 89); + this.chkIsActive.Location = new System.Drawing.Point(307, 66); this.chkIsActive.Name = "chkIsActive"; this.chkIsActive.Size = new System.Drawing.Size(67, 17); this.chkIsActive.TabIndex = 7; @@ -182,7 +154,7 @@ // txtServiceCharge // this.txtServiceCharge.AccessibleName = "Phone 1"; - this.txtServiceCharge.Location = new System.Drawing.Point(112, 141); + this.txtServiceCharge.Location = new System.Drawing.Point(112, 115); this.txtServiceCharge.Name = "txtServiceCharge"; this.txtServiceCharge.Size = new System.Drawing.Size(189, 20); this.txtServiceCharge.TabIndex = 5; @@ -190,7 +162,7 @@ // // btnAddProductGroup // - this.btnAddProductGroup.Location = new System.Drawing.Point(307, 167); + this.btnAddProductGroup.Location = new System.Drawing.Point(307, 141); this.btnAddProductGroup.Name = "btnAddProductGroup"; this.btnAddProductGroup.Size = new System.Drawing.Size(96, 21); this.btnAddProductGroup.TabIndex = 9; @@ -203,7 +175,7 @@ this.cmbProductGroup.DataSource = this.bsProductGroups; this.cmbProductGroup.DisplayMember = "Name"; this.cmbProductGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cmbProductGroup.Location = new System.Drawing.Point(112, 167); + this.cmbProductGroup.Location = new System.Drawing.Point(112, 141); this.cmbProductGroup.Name = "cmbProductGroup"; this.cmbProductGroup.Size = new System.Drawing.Size(189, 21); this.cmbProductGroup.TabIndex = 8; @@ -211,7 +183,7 @@ // // btnCancel // - this.btnCancel.Location = new System.Drawing.Point(328, 195); + this.btnCancel.Location = new System.Drawing.Point(328, 169); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(75, 75); this.btnCancel.TabIndex = 11; @@ -221,7 +193,7 @@ // // btnOk // - this.btnOk.Location = new System.Drawing.Point(247, 195); + this.btnOk.Location = new System.Drawing.Point(247, 169); this.btnOk.Name = "btnOk"; this.btnOk.Size = new System.Drawing.Size(75, 75); this.btnOk.TabIndex = 10; @@ -232,7 +204,7 @@ // txtFullPrice // this.txtFullPrice.AccessibleName = ""; - this.txtFullPrice.Location = new System.Drawing.Point(222, 64); + this.txtFullPrice.Location = new System.Drawing.Point(222, 38); this.txtFullPrice.Name = "txtFullPrice"; this.txtFullPrice.Size = new System.Drawing.Size(79, 20); this.txtFullPrice.TabIndex = 19; @@ -243,7 +215,7 @@ this.cmbServiceTax.DataSource = this.bsServiceTax; this.cmbServiceTax.DisplayMember = "Name"; this.cmbServiceTax.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.cmbServiceTax.Location = new System.Drawing.Point(112, 87); + this.cmbServiceTax.Location = new System.Drawing.Point(112, 61); this.cmbServiceTax.Name = "cmbServiceTax"; this.cmbServiceTax.Size = new System.Drawing.Size(189, 21); this.cmbServiceTax.TabIndex = 20; @@ -252,16 +224,16 @@ // label6 // this.label6.AutoSize = true; - this.label6.Location = new System.Drawing.Point(19, 89); + this.label6.Location = new System.Drawing.Point(42, 67); this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(91, 13); + this.label6.Size = new System.Drawing.Size(64, 13); this.label6.TabIndex = 21; - this.label6.Text = "Service Tax / Vat"; + this.label6.Text = "Service Tax"; // // chkIsScTaxable // this.chkIsScTaxable.AutoSize = true; - this.chkIsScTaxable.Location = new System.Drawing.Point(307, 144); + this.chkIsScTaxable.Location = new System.Drawing.Point(307, 118); this.chkIsScTaxable.Name = "chkIsScTaxable"; this.chkIsScTaxable.Size = new System.Drawing.Size(91, 17); this.chkIsScTaxable.TabIndex = 22; @@ -271,18 +243,28 @@ // chkIsNotAvailable // this.chkIsNotAvailable.AutoSize = true; - this.chkIsNotAvailable.Location = new System.Drawing.Point(307, 116); + this.chkIsNotAvailable.Location = new System.Drawing.Point(307, 93); this.chkIsNotAvailable.Name = "chkIsNotAvailable"; this.chkIsNotAvailable.Size = new System.Drawing.Size(57, 17); this.chkIsNotAvailable.TabIndex = 23; this.chkIsNotAvailable.Text = "Is N/A"; this.chkIsNotAvailable.UseVisualStyleBackColor = true; // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(78, 94); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(28, 13); + this.label1.TabIndex = 24; + this.label1.Text = "VAT"; + // // ProductForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(415, 282); + this.Controls.Add(this.label1); this.Controls.Add(this.chkIsNotAvailable); this.Controls.Add(this.chkIsScTaxable); this.Controls.Add(this.label6); @@ -301,9 +283,6 @@ this.Controls.Add(this.txtUnits); this.Controls.Add(this.txtName); this.Controls.Add(this.Label2); - this.Controls.Add(this.txtCode); - this.Controls.Add(this.txtProductID); - this.Controls.Add(this.label3); this.Controls.Add(this.Label4); this.MaximizeBox = false; this.MinimizeBox = false; @@ -326,9 +305,6 @@ private System.Windows.Forms.BindingSource bsProductGroups; private System.Windows.Forms.BindingSource bsServiceTax; internal System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.TextBox txtProductID; - internal System.Windows.Forms.TextBox txtCode; internal System.Windows.Forms.Label Label2; internal System.Windows.Forms.TextBox txtUnits; internal System.Windows.Forms.TextBox txtName; @@ -346,5 +322,6 @@ private System.Windows.Forms.CheckBox chkIsScTaxable; private System.Windows.Forms.BindingSource bsVat; private System.Windows.Forms.CheckBox chkIsNotAvailable; + internal System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductForm.cs b/Tanshu.Accounts.PointOfSale/Products/ProductForm.cs index 9dadc93..10e12a2 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductForm.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ProductForm.cs @@ -22,8 +22,6 @@ namespace Tanshu.Accounts.PointOfSale Product product; using (var bi = new ProductBI()) product = bi.Get(x => x.ProductID == _productID.Value); - txtProductID.Text = _productID.Value.ToString(); - txtCode.Text = product.Code.ToString(); txtName.Text = product.Name; txtUnits.Text = product.Units; txtPrice.Text = product.Price.ToString("#.##"); @@ -38,7 +36,6 @@ namespace Tanshu.Accounts.PointOfSale } else { - txtProductID.Text = "(Auto)"; txtName.Focus(); } } @@ -69,29 +66,34 @@ namespace Tanshu.Accounts.PointOfSale if (_productID.HasValue) product.ProductID = _productID.Value; - int code; - if (!int.TryParse(txtCode.Text, out code)) - return null; - if (code < 0) - return null; - product.Code = code; - if (string.IsNullOrEmpty(txtName.Text.Trim())) return null; product.Name = txtName.Text.Trim(); - //if (string.IsNullOrEmpty(txtUnits.Text.Trim())) - // return null; product.Units = txtUnits.Text.Trim(); decimal price; - if (!decimal.TryParse(txtPrice.Text, out price)) - return null; + if (string.IsNullOrEmpty(txtPrice.Text.Trim())) + { + price = 0; + } + else + { + if (!decimal.TryParse(txtPrice.Text.Trim(), out price)) + return null; + } if (price < 0) return null; product.Price = price; - if (!decimal.TryParse(txtFullPrice.Text, out price)) - return null; + if (string.IsNullOrEmpty(txtFullPrice.Text.Trim())) + { + price = 0; + } + else + { + if (!decimal.TryParse(txtFullPrice.Text.Trim(), out price)) + return null; + } if (price < 0 || price < product.Price) return null; product.FullPrice = price; @@ -106,8 +108,16 @@ namespace Tanshu.Accounts.PointOfSale product.ServiceTax = (Tax)cmbServiceTax.SelectedItem; decimal serviceCharge; - if (!decimal.TryParse(txtServiceCharge.Text, out serviceCharge)) - return null; + if (string.IsNullOrEmpty(txtServiceCharge.Text.Trim())) + { + serviceCharge = 0; + } + else + { + if (!decimal.TryParse(txtServiceCharge.Text.Trim(), out serviceCharge)) + return null; + } + if (serviceCharge < 0 || serviceCharge > 1) return null; product.ServiceCharge = serviceCharge; diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs index a8ecdd6..e378ce6 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs @@ -29,25 +29,25 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); this.btnAdd = new System.Windows.Forms.Button(); this.btnEdit = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); this.dgvProducts = new System.Windows.Forms.DataGridView(); + this.bsList = new System.Windows.Forms.BindingSource(this.components); + this.btnSave = new System.Windows.Forms.Button(); + this.chkIsActive = new System.Windows.Forms.CheckBox(); this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.unitsDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.moveUp = new System.Windows.Forms.DataGridViewButtonColumn(); this.moveDown = new System.Windows.Forms.DataGridViewButtonColumn(); - this.Vat = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ServiceTax = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Vat = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Group = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.serviceChargeDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.salePriceDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.isActiveDataGridViewCheckBoxColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); - this.bsList = new System.Windows.Forms.BindingSource(this.components); - this.btnSave = new System.Windows.Forms.Button(); - this.chkIsActive = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit(); this.SuspendLayout(); @@ -100,8 +100,8 @@ this.unitsDataGridViewTextBoxColumn, this.moveUp, this.moveDown, - this.Vat, this.ServiceTax, + this.Vat, this.Group, this.serviceChargeDataGridViewTextBoxColumn, this.salePriceDataGridViewTextBoxColumn, @@ -120,6 +120,36 @@ this.dgvProducts.TabIndex = 74; this.dgvProducts.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvProductTypes_CellFormatting); // + // bsList + // + this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Product); + // + // btnSave + // + this.btnSave.AccessibleName = "Done"; + this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnSave.Location = new System.Drawing.Point(174, 255); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 75); + this.btnSave.TabIndex = 75; + this.btnSave.Text = "&Save"; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // chkIsActive + // + this.chkIsActive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkIsActive.AutoSize = true; + this.chkIsActive.Checked = true; + this.chkIsActive.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkIsActive.Location = new System.Drawing.Point(255, 285); + this.chkIsActive.Name = "chkIsActive"; + this.chkIsActive.Size = new System.Drawing.Size(116, 17); + this.chkIsActive.TabIndex = 76; + this.chkIsActive.Text = "Show Active Only?"; + this.chkIsActive.ThreeState = true; + this.chkIsActive.UseVisualStyleBackColor = true; + this.chkIsActive.CheckStateChanged += new System.EventHandler(this.chkIsActive_CheckStateChanged); + // // nameDataGridViewTextBoxColumn // this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; @@ -154,14 +184,6 @@ this.moveDown.UseColumnTextForButtonValue = true; this.moveDown.Width = 41; // - // Vat - // - this.Vat.DataPropertyName = "Vat"; - this.Vat.HeaderText = "Vat"; - this.Vat.Name = "Vat"; - this.Vat.ReadOnly = true; - this.Vat.Width = 48; - // // ServiceTax // this.ServiceTax.DataPropertyName = "ServiceTax"; @@ -170,6 +192,14 @@ this.ServiceTax.ReadOnly = true; this.ServiceTax.Width = 86; // + // Vat + // + this.Vat.DataPropertyName = "Vat"; + this.Vat.HeaderText = "Vat"; + this.Vat.Name = "Vat"; + this.Vat.ReadOnly = true; + this.Vat.Width = 48; + // // Group // this.Group.DataPropertyName = "ProductGroup"; @@ -181,8 +211,8 @@ // serviceChargeDataGridViewTextBoxColumn // this.serviceChargeDataGridViewTextBoxColumn.DataPropertyName = "ServiceCharge"; - dataGridViewCellStyle7.Format = "P0"; - this.serviceChargeDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle7; + dataGridViewCellStyle1.Format = "P0"; + this.serviceChargeDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle1; this.serviceChargeDataGridViewTextBoxColumn.HeaderText = "SC"; this.serviceChargeDataGridViewTextBoxColumn.Name = "serviceChargeDataGridViewTextBoxColumn"; this.serviceChargeDataGridViewTextBoxColumn.ReadOnly = true; @@ -191,8 +221,8 @@ // salePriceDataGridViewTextBoxColumn // this.salePriceDataGridViewTextBoxColumn.DataPropertyName = "Price"; - dataGridViewCellStyle8.Format = "N0"; - this.salePriceDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle8; + dataGridViewCellStyle2.Format = "N0"; + this.salePriceDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2; this.salePriceDataGridViewTextBoxColumn.HeaderText = "Price"; this.salePriceDataGridViewTextBoxColumn.Name = "salePriceDataGridViewTextBoxColumn"; this.salePriceDataGridViewTextBoxColumn.ReadOnly = true; @@ -206,36 +236,6 @@ this.isActiveDataGridViewCheckBoxColumn.ReadOnly = true; this.isActiveDataGridViewCheckBoxColumn.Width = 54; // - // bsList - // - this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Product); - // - // btnSave - // - this.btnSave.AccessibleName = "Done"; - this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnSave.Location = new System.Drawing.Point(174, 255); - this.btnSave.Name = "btnSave"; - this.btnSave.Size = new System.Drawing.Size(75, 75); - this.btnSave.TabIndex = 75; - this.btnSave.Text = "&Save"; - this.btnSave.Click += new System.EventHandler(this.btnSave_Click); - // - // chkIsActive - // - this.chkIsActive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.chkIsActive.AutoSize = true; - this.chkIsActive.Checked = true; - this.chkIsActive.CheckState = System.Windows.Forms.CheckState.Checked; - this.chkIsActive.Location = new System.Drawing.Point(255, 285); - this.chkIsActive.Name = "chkIsActive"; - this.chkIsActive.Size = new System.Drawing.Size(116, 17); - this.chkIsActive.TabIndex = 76; - this.chkIsActive.Text = "Show Active Only?"; - this.chkIsActive.ThreeState = true; - this.chkIsActive.UseVisualStyleBackColor = true; - this.chkIsActive.CheckStateChanged += new System.EventHandler(this.chkIsActive_CheckStateChanged); - // // ProductListForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -268,17 +268,17 @@ private System.Windows.Forms.DataGridView dgvProducts; private System.Windows.Forms.BindingSource bsList; internal System.Windows.Forms.Button btnSave; + private System.Windows.Forms.CheckBox chkIsActive; private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn unitsDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewButtonColumn moveUp; private System.Windows.Forms.DataGridViewButtonColumn moveDown; - private System.Windows.Forms.DataGridViewTextBoxColumn Vat; private System.Windows.Forms.DataGridViewTextBoxColumn ServiceTax; + private System.Windows.Forms.DataGridViewTextBoxColumn Vat; private System.Windows.Forms.DataGridViewTextBoxColumn Group; private System.Windows.Forms.DataGridViewTextBoxColumn serviceChargeDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn salePriceDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewCheckBoxColumn isActiveDataGridViewCheckBoxColumn; - private System.Windows.Forms.CheckBox chkIsActive; //private System.Windows.Forms.DataGridViewTextBoxColumn discountLimitDataGridViewTextBoxColumn; //private System.Windows.Forms.DataGridViewTextBoxColumn groupTypeDataGridViewTextBoxColumn; //private System.Windows.Forms.DataGridViewTextBoxColumn productGroupDataGridViewTextBoxColumn; diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx index c97991e..4730ec2 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx +++ b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx @@ -123,30 +123,12 @@ True - - True - True - - True - - - 17, 17 - - - True - - - True - True - - True - True diff --git a/Tanshu.Accounts.Repository/ManagementBI.cs b/Tanshu.Accounts.Repository/ManagementBI.cs index 12d4756..18d679c 100644 --- a/Tanshu.Accounts.Repository/ManagementBI.cs +++ b/Tanshu.Accounts.Repository/ManagementBI.cs @@ -1,13 +1,131 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using System.Linq; using NHibernate; using Tanshu.Accounts.Entities; -using Tanshu.Common.Helpers; namespace Tanshu.Accounts.Repository { + public class SaleInfo + { + public int StartBill { get; set; } + public int FinishBill { get; set; } + public decimal Rate { get; set; } + public decimal Net { get; set; } + public decimal Vat { get; set; } + } + public class ExcelInfo + { + public DateTime Date { get; set; } + public string StartBill { get; set; } + public string FinishBill { get; set; } + public IDictionary SaleAndVat { get; set; } + public decimal ServiceTax { get; set; } + } + public class SaleJson + { + IFormatProvider culture = new CultureInfo("en-US", true); + private DateTime? dateStart; + private DateTime? dateFinish; + public string StartDate { get; set; } + public string FinishDate { get; set; } + public IList Sale { get; set; } + public DateTime? SDate + { + get + { + if (dateStart.HasValue) + return dateStart; + DateTime dStart; + if (!DateTime.TryParseExact(StartDate, "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dStart)) + dateStart = null; + else + dateStart = dStart; + return dateStart; + } + } + public DateTime? FDate + { + get + { + if (dateFinish.HasValue) + return dateFinish; + DateTime dFinish; + if (!DateTime.TryParseExact(FinishDate, "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dFinish)) + dateFinish = null; + else + dateFinish = dFinish; + return dateFinish; + } + } + } + public class SaleDetailJson + { + public decimal Rate { get; set; } + public bool IsLiq { get; set; } + public decimal Amount { get; set; } + } + public class BeerJson + { + IFormatProvider culture = new CultureInfo("en-US", true); + private DateTime? date; + public string Date { get; set; } + public IList Beers { get; set; } + public DateTime? bDate + { + get + { + if (date.HasValue) + return date; + DateTime tDate; + if (!DateTime.TryParseExact(Date, "d MMM yy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) + date = null; + else + date = tDate; + return tDate; + } + } + public decimal Quantity + { + get + { + decimal amount = 0; + foreach (var item in Beers) + { + amount += item.Quantity; + } + return amount; + } + } + } + public class BeerDetailJson + { + public string Name { get; set; } + public decimal Quantity { get; set; } + } + public class CreditJson + { + IFormatProvider culture = new CultureInfo("en-US", true); + private DateTime? date; + public string Date { get; set; } + public decimal Amount { get; set; } + public DateTime? CDate + { + get + { + if (date.HasValue) + return date; + DateTime tDate; + if (!DateTime.TryParseExact(Date, "dd/MM/yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) + date = null; + else + date = tDate; + return tDate; + } + } + } public class ManagementBI : IUnitOfWork { protected readonly ISession _session; @@ -21,35 +139,205 @@ namespace Tanshu.Accounts.Repository #region Cleanup public void DeleteVoid(DateTime startDate, DateTime finishDate) { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void).List(); + var query = @"delete from Reprint r where r.Voucher in ( +select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v.Void = :void +)"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("void", true) + .ExecuteUpdate(); + query = @"delete from VoucherSettlement vs where vs.Voucher in ( +select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v.Void = :void +)"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("void", true) + .ExecuteUpdate(); + query = @"delete from InventoryModifier im where im.Inventory in ( +select i from Inventory i where i.Kot in ( +select k from Kot k where k.Voucher in ( +select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v.Void = :void +)))"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("void", true) + .ExecuteUpdate(); + query = @"delete from Inventory i where i.Kot in ( +select k from Kot k where k.Voucher in ( +select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v.Void = :void +))"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("void", true) + .ExecuteUpdate(); + query = @"delete from Kot k where k.Voucher in ( +select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v.Void = :void +)"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("void", true) + .ExecuteUpdate(); + query = @"delete from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v.Void = :void"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("void", true) + .ExecuteUpdate(); + } + public void MoveStaffToNc(DateTime startDate, DateTime finishDate) + { + var query = @"update Voucher set VoucherType = :nc where VoucherType = :staff and Date >= :startDate and Date <= :finishDate"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("nc", VoucherType.NoCharge) + .SetParameter("staff", VoucherType.Staff) + .ExecuteUpdate(); + } + public void ClearModifiers(DateTime startDate, DateTime finishDate) + { + var query = @"delete from InventoryModifier im where im.Inventory in ( +select i from Inventory i where i.Kot in ( +select k from Kot k where k.Voucher in ( +select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate +)))"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .ExecuteUpdate(); + } + public void CombineKots(DateTime startDate, DateTime finishDate) + { + var query = @" +select v.VoucherID, k.KotID, i.InventoryID, i.Product.ProductID, i.Quantity +from Voucher v +inner join v.Kots k +inner join k.Inventories i +where v.Date >= :startDate and v.Date <= :finishDate +order by v.Date, k.Date"; + var list = _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .List(); + Dictionary>> vouchers = new Dictionary>>(); foreach (var item in list) { - _session.Delete(item); - foreach (var re in _session.QueryOver().Where(x => x.Voucher.VoucherID == item.VoucherID).List()) + var voucherID = (Guid)item[0]; + var kotID = (Guid)item[1]; + var inventoryID = (Guid)item[2]; + var productID = (Guid)item[3]; + var quantity = (decimal)item[4]; + if (!vouchers.ContainsKey(voucherID)) + vouchers.Add(voucherID, new Dictionary>()); + if (!vouchers[voucherID].ContainsKey(kotID)) + vouchers[voucherID].Add(kotID, new List()); + vouchers[voucherID][kotID].Add(new object[] { inventoryID, productID, quantity }); + } + foreach (var voucher in vouchers) + { + var kots = voucher.Value; + if (kots.Count <= 1) + continue; + Dictionary kotInventories = new Dictionary(); + foreach (var item in kots.ElementAt(0).Value) { - _session.Delete(re); + Guid inventoryID = (Guid)item[0]; + Guid productID = (Guid)item[1]; + kotInventories.Add(productID, inventoryID); + } + for (var i = kots.Count; i > 1; i--) + { + foreach (var item in kots.ElementAt(i - 1).Value) + { + Guid inventoryID = (Guid)item[0]; + Guid productID = (Guid)item[1]; + decimal quantity = (decimal)item[2]; + if (kotInventories.ContainsKey(productID)) + { + query = @"update Inventory set Quantity = Quantity + :quantity where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("quantity", quantity).SetParameter("inventoryID", kotInventories[productID]).ExecuteUpdate(); + query = @"delete from Inventory where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("inventoryID", inventoryID).ExecuteUpdate(); + } + else + { + kotInventories.Add(productID, inventoryID); + query = @"update Inventory set Kot.KotID = :kotID where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("kotID", kots.ElementAt(0).Key).SetParameter("inventoryID", inventoryID).ExecuteUpdate(); + } + } + query = @"delete from Kot where KotID = :kotID"; + _session.CreateQuery(query).SetParameter("kotID", kots.ElementAt(i - 1).Key).ExecuteUpdate(); } } } - public void DeleteStaff(DateTime startDate, DateTime finishDate) + public void RemoveBlankKots(DateTime startDate, DateTime finishDate) { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.Staff).List(); - foreach (var item in list) - { - _session.Delete(item); - foreach (var re in _session.QueryOver().Where(x => x.Voucher.VoucherID == item.VoucherID).List()) - { - _session.Delete(re); - } - } + var query = @"delete from Kot k where +k.Voucher in (select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate) +and k not in (select distinct i.Kot from Inventory i)"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .ExecuteUpdate(); + query = @"delete from VoucherSettlement vs where vs.Voucher in (select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v not in (select distinct k.Voucher from Kot k))"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .ExecuteUpdate(); + query = @"delete from Reprint r where r.Voucher in (select v from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v not in (select distinct k.Voucher from Kot k))"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .ExecuteUpdate(); + query = @"delete from Voucher v where v.Date >= :startDate and v.Date <= :finishDate and v not in (select distinct k.Voucher from Kot k)"; + _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .ExecuteUpdate(); } public void SetPayments(DateTime startDate, DateTime finishDate) { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate).List(); - foreach (var voucher in list) + var query = @"select v.VoucherID, v.VoucherType, sum(i.Amount) +from Voucher v +inner join v.Kots k +inner join k.Inventories i +where v.Date >= :startDate and v.Date <= :finishDate +group by v.VoucherID, v.VoucherType"; + var list = _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .List(); + Dictionary vouchers = new Dictionary(); + foreach (var item in list) { - var settlementType = SettleOption.Cash; - switch (voucher.VoucherType) + var voucherType = (int)item[1] == 1 || (int)item[1] == 3 ? VoucherType.Regular : (int)item[1] == 2 ? VoucherType.NoCharge : VoucherType.Staff; + vouchers.Add((Guid)item[0], new object[] { voucherType, Math.Round((decimal)item[2], 5) }); + } + + foreach (var item in vouchers) + { + SettleOption settlementType; + switch ((VoucherType)item.Value[0]) { case VoucherType.NoCharge: settlementType = SettleOption.NoCharge; @@ -57,101 +345,55 @@ namespace Tanshu.Accounts.Repository case VoucherType.Staff: settlementType = SettleOption.Staff; break; + default: + settlementType = SettleOption.Cash; + break; } - var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); + var amount = -1 * (decimal)item.Value[1]; var roundoff = Math.Round(amount) - amount; - voucher.Settlements.Clear(); - voucher.Settlements.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount }); - voucher.Settlements.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff }); - voucher.Settlements.Add(new VoucherSettlement() { Amount = -1 * (amount + roundoff), Settled = settlementType }); - _session.Update(voucher); - } - } - public void ClearModifiers(DateTime startDate, DateTime finishDate) - { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate).List(); - foreach (var voucher in list) - { - foreach (var kot in voucher.Kots) - { - foreach (var inventory in kot.Inventories) - { - if (inventory.InventoryModifier.Count > 0) - inventory.InventoryModifier.Clear(); - } - } - _session.Update(voucher); - } - } - public void CombineKots(DateTime startDate, DateTime finishDate) - { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate).List(); - foreach (var voucher in list) - { - if (voucher.Kots.Count == 0) - continue; - var kots = voucher.Kots.OrderBy(x => x.Date); - var kot = kots.First(); - for (var kotIndex = kots.Count(); kotIndex > 1; kotIndex--) - { - var otherKot = kots.ElementAt(kotIndex - 1); - for (var i = otherKot.Inventories.Count; i > 0; i--) - { - var inventory = otherKot.Inventories[i - 1]; - var oldProduct = kot.Inventories.SingleOrDefault(x => x.Product.ProductID == inventory.Product.ProductID); - if (oldProduct == null) - { - inventory.Kot = kot; - } - else - { - oldProduct.Quantity += inventory.Quantity; - otherKot.Inventories.RemoveAt(i - 1); - } - } - } - _session.Update(voucher); - } - } - public void RemoveBlankKots(DateTime startDate, DateTime finishDate) - { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate).List(); - foreach (var voucher in list) - { - for (var kotIndex = voucher.Kots.Count; kotIndex > 0; kotIndex--) - { - var kot = voucher.Kots[kotIndex - 1]; - if (kot.Inventories.Count == 0) - voucher.Kots.RemoveAt(kotIndex - 1); - } - _session.Update(voucher); + query = @"delete from VoucherSettlement vs where vs.Voucher.VoucherID = :voucherID"; + _session + .CreateQuery(query) + .SetParameter("voucherID", item.Key) + .ExecuteUpdate(); + _session.Save(new VoucherSettlement() { Voucher = new Voucher() { VoucherID = item.Key }, Amount = amount, Settled = SettleOption.Amount }); + _session.Save(new VoucherSettlement() { Voucher = new Voucher() { VoucherID = item.Key }, Amount = roundoff, Settled = SettleOption.RoundOff }); + _session.Save(new VoucherSettlement() { Voucher = new Voucher() { VoucherID = item.Key }, Amount = -1 * (amount + roundoff), Settled = settlementType }); } } - public void FinalSanction(DateTime startDate, DateTime finishDate) + + public void UpdateBillID(DateTime startDate, DateTime finishDate) { var query = @" -select v.BillID +select MAX(v.BillID) from Voucher v -where v.Date < :startDate and v.Void = false and v.VoucherType not in (:nc, :staff) -order by v.Date desc +where v.Date < :startDate and v.Void = false and v.VoucherType in (:regular, :takeAway) "; var lastBill = _session .CreateQuery(query) .SetParameter("startDate", startDate) - .SetParameter("nc", VoucherType.NoCharge) - .SetParameter("staff", VoucherType.Staff) - .SetMaxResults(1) + .SetParameter("regular", VoucherType.Regular) + .SetParameter("takeAway", VoucherType.TakeAway) .UniqueResult(); - var newID = lastBill == null ? 10001 : GetNewID((int)lastBill); - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff && x.Void == false).OrderBy(x => x.Date).Asc.List(); + var newID = lastBill == null ? 1 : GetNewID((int)lastBill); + var list = _session.QueryOver() + .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 i = 0; foreach (var voucher in list) { + i++; + if (i % 20 == 0) + Console.WriteLine("Loop " + i.ToString() + count); if (voucher.BillID != newID) { - throw new NotImplementedException(); - //voucher.BillID = newID; - _session.Update(voucher); + var update = _session.CreateSQLQuery("exec UpdateBillID ?,?"); + update.SetParameter(0, voucher.VoucherID); + update.SetParameter(1, newID); + update.ExecuteUpdate(); } newID = GetNewID(newID); } @@ -169,14 +411,18 @@ order by v.Date desc .SetMaxResults(1) .UniqueResult(); newID = (int)lastBill; - list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.NoCharge && x.Void == false).OrderBy(x => x.Date).Asc.List(); + list = _session.QueryOver() + .Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.NoCharge && x.Void == false) + .OrderBy(x => x.Date).Asc + .List(); foreach (var voucher in list) { if (voucher.BillID != newID) { - throw new NotImplementedException(); - //voucher.BillID = newID; - _session.Update(voucher); + var update = _session.CreateSQLQuery("exec UpdateBillID ?,?"); + update.SetParameter(0, voucher.VoucherID); + update.SetParameter(1, newID); + update.ExecuteUpdate(); } newID += 1; } @@ -191,14 +437,14 @@ order by v.Date desc } #endregion - public void MoveNc(DateTime startDate, DateTime finishDate, decimal target) + public void MoveToNc(DateTime startDate, DateTime finishDate, decimal target) { - const string query = @" + string query = @" select v.VoucherID, sum(i.Amount) from Voucher v inner join v.Kots k inner join k.Inventories i -where v.Date >= :startDate and v.Date <= :finishDate and i.Vat in (.1575, .2625) and v.Void = false and v.VoucherType not in (:nc, :staff) +where v.Date >= :startDate and v.Date <= :finishDate and i.Vat.TaxID = :vatLiquor and v.Void = false and v.VoucherType not in (:nc, :staff) group by v.VoucherID order by sum(i.Amount) desc "; @@ -208,98 +454,58 @@ order by sum(i.Amount) desc .SetParameter("finishDate", finishDate.AddDays(1).AddHours(7)) .SetParameter("nc", VoucherType.NoCharge) .SetParameter("staff", VoucherType.Staff) + .SetParameter("vatLiquor", new Guid("2C8AD8EC-E09A-4194-B348-01243474CF26")) .List(); - var totalAmount = GetFood(.1575M, startDate, finishDate) + GetFood(.2625M, startDate, finishDate); - var skip = false; - for (int i = 0; i < list.Count / 20; i++) + var totalAmount = GetSaleAmount(.1575M, startDate, finishDate) + GetSaleAmount(.2625M, startDate, finishDate); + for (int i = 0; i < list.Count / 20; i += 2) // Skip every alternate bill { - if (target / totalAmount > .75M) + if (totalAmount <= target) break; - skip = !skip; - if (skip) - continue; var item = (object[])list[i]; var voucherID = (Guid)item[0]; var amount = (decimal)item[1]; - var voucher = _session.QueryOver().Where(x => x.VoucherID == voucherID).SingleOrDefault(); - voucher.VoucherType = VoucherType.NoCharge; - _session.Update(voucher); + + query = @"update Voucher set VoucherType = :nc where VoucherID = :voucherID"; + _session + .CreateQuery(query) + .SetParameter("nc", VoucherType.NoCharge) + .SetParameter("voucherID", voucherID) + .ExecuteUpdate(); totalAmount -= amount; } } - public Dictionary GetLiq(decimal vat, DateTime startDate, DateTime finishDate) + public IList GetSaleAndVat(DateTime startDate, DateTime finishDate) { const string query = @" -select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) as Amount +select i.VatRate as Rate, +sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) as Net, +sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate) as Vat from Voucher v inner join v.Kots k inner join k.Inventories i -where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void = false and v.VoucherType not in (:nc, :staff) +where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType in (:regular, :takeAway) +group by i.VatRate +order by i.VatRate "; - var dict = new Dictionary(); - for (var date = startDate; date <= finishDate; date = date.AddDays(1)) - { - var qty = _session - .CreateQuery(query) - .SetParameter("startDate", date.AddHours(7)) - .SetParameter("finishDate", date.AddDays(1).AddHours(7)) - .SetParameter("vat", vat) - .SetParameter("nc", VoucherType.NoCharge) - .SetParameter("staff", VoucherType.Staff) - .UniqueResult(); - dict.Add(date, qty == null ? 0 : (decimal)qty); - } - return dict; - } - - public Dictionary GetGrossSale(DateTime startDate, DateTime finishDate) - { - const string query = @" -select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) * (1 + i.Vat) as Amount -from Voucher v -inner join v.Kots k -inner join k.Inventories i -where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff) - "; - var dict = new Dictionary(); - for (var date = startDate; date <= finishDate; date = date.AddDays(1)) - { - var qty = _session - .CreateQuery(query) - .SetParameter("startDate", date.AddHours(7)) - .SetParameter("finishDate", date.AddDays(1).AddHours(7)) - .SetParameter("nc", VoucherType.NoCharge) - .SetParameter("staff", VoucherType.Staff) - .UniqueResult(); - dict.Add(date, qty == null ? 0 : (decimal)qty); - } - return dict; - } - - public decimal GetVat(decimal vat, DateTime startDate, DateTime finishDate) - { - const string query = @" -select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.Vat) as Amount -from Voucher v -inner join v.Kots k -inner join k.Inventories i -where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void = false and v.VoucherType not in (:nc, :staff) - "; - var qty = _session + var list = _session .CreateQuery(query) .SetParameter("startDate", startDate) .SetParameter("finishDate", finishDate) - .SetParameter("vat", vat) - .SetParameter("nc", VoucherType.NoCharge) - .SetParameter("staff", VoucherType.Staff) - .UniqueResult(); - return qty == null ? 0 : (decimal)qty; + .SetParameter("regular", VoucherType.Regular) + .SetParameter("takeAway", VoucherType.TakeAway) + .List(); + var info = new List(); + foreach (var item in list) + { + info.Add(new SaleInfo() { Rate = (decimal)item[0], Net = (decimal)item[1], Vat = (decimal)item[2] }); + } + return info; } public decimal GetServiceTax(DateTime startDate, DateTime finishDate) { const string query = @" -select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTax) as Amount +select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate) as Amount from Voucher v inner join v.Kots k inner join k.Inventories i @@ -314,52 +520,54 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.Vo .UniqueResult(); return qty == null ? 0 : (decimal)qty; } - public string GetFirstBill(DateTime date) + public SaleInfo GetMinMaxBills(DateTime startDate, DateTime finishDate) { const string query = @" -select v.BillID +select MIN(v.BillID) as StartBill, MAX(v.BillID) as FinishBill from Voucher v -where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff) -order by v.Date +where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType in (:regular, :takeAway) "; - var qty = _session + var item = _session .CreateQuery(query) - .SetParameter("startDate", date.AddHours(7)) - .SetParameter("finishDate", date.AddDays(1).AddHours(7)) - .SetParameter("nc", VoucherType.NoCharge) - .SetParameter("staff", VoucherType.Staff) - .SetMaxResults(1) - .UniqueResult(); - return qty == null ? "" : (string)qty; + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("regular", VoucherType.Regular) + .SetParameter("takeAway", VoucherType.TakeAway) + .UniqueResult(); + if (item[0] == null || item[1] == null) + return null; + return new SaleInfo() { StartBill = (int)item[0], FinishBill = (int)item[1] }; } - public string GetLastBill(DateTime date) + public int? GetLastBill(DateTime date) { const string query = @" select v.BillID from Voucher v -where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff) +where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType in (:regular, :takeAway) order by v.Date desc "; var qty = _session .CreateQuery(query) .SetParameter("startDate", date.AddHours(7)) .SetParameter("finishDate", date.AddDays(1).AddHours(7)) - .SetParameter("nc", VoucherType.NoCharge) - .SetParameter("staff", VoucherType.Staff) + .SetParameter("regular", VoucherType.Regular) + .SetParameter("takeAway", VoucherType.TakeAway) .SetMaxResults(1) .UniqueResult(); - return qty == null ? "" : (string)qty; + if (qty == null) + return null; + return (int)qty; } - public decimal GetFood(decimal vat, DateTime startDate, DateTime finishDate) + public decimal GetSaleAmount(decimal vat, DateTime startDate, DateTime finishDate) { const string query = @" select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) as Amount from Voucher v inner join v.Kots k inner join k.Inventories i -where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void = false and v.VoucherType not in (:nc, :staff) +where v.Date >= :startDate and v.Date <= :finishDate and i.VatRate = :vat and v.Void = false and v.VoucherType not in (:nc, :staff) "; var qty = _session .CreateQuery(query) @@ -371,198 +579,114 @@ where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void .UniqueResult(); return qty == null ? 0 : (decimal)qty; } - public decimal SetFood(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) + public decimal SetSaleQuantity(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff).List(); + var query = @" +select i.InventoryID, i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) +from Voucher v +inner join v.Kots k +inner join k.Inventories i +where v.Date >= :startDate and v.Date <= :finishDate +and i.VatRate = :vat +and v.VoucherType in (:regular, :takeAway)"; + var list = _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("regular", VoucherType.Regular) + .SetParameter("vat", vat) + .SetParameter("takeAway", VoucherType.TakeAway) + .List(); + Dictionary inventories = new Dictionary(); list = Randomize(list); - var left = GetFood(vat, startDate, finishDate) - amount; foreach (var item in list) + { + inventories.Add((Guid)item[0], Convert.ToDecimal(item[1])); + } + var left = GetSaleAmount(vat, startDate, finishDate) - amount; + foreach (var item in inventories) { if (left <= 0) break; - foreach (var kot in item.Kots) + var inventoryAmount = item.Value; + + if (inventoryAmount > left) { - if (left <= 0) - break; - foreach (var inventory in kot.Inventories) - { - if (left <= 0) - break; - if (inventory.VatRate == vat) - { - var inventoryAmount = inventory.Quantity * inventory.Price * (1 - inventory.Discount) * - (1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)); - var i = _session.QueryOver().Where(x => x.InventoryID == inventory.InventoryID).SingleOrDefault(); - if (inventoryAmount > left) - { - var newQuantity = inventory.Quantity * (inventoryAmount - left) / inventoryAmount; - i.Quantity = newQuantity; - _session.Update(i); - left = 0; - } - else - { - left -= inventoryAmount; - _session.Delete(i); - } - } - } + var ratio = (inventoryAmount - left) / inventoryAmount; + query = @"update Inventory set Quantity = Quantity * :ratio where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("ratio", ratio).SetParameter("inventoryID", item.Key).ExecuteUpdate(); + left = 0; + } + else + { + query = @"delete from Inventory where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("inventoryID", item.Key).ExecuteUpdate(); + left -= inventoryAmount; } } - return GetFood(vat, startDate, finishDate); + return GetSaleAmount(vat, startDate, finishDate); } - - public decimal SetLiq(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) + public decimal SetSaleDiscount(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) { var rand = new Random(); - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff).List(); + var query = @" +select i.InventoryID, i.Quantity, i.Discount, i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) +from Voucher v +inner join v.Kots k +inner join k.Inventories i +where v.Date >= :startDate and v.Date <= :finishDate +and i.VatRate = :vat and i.Discount < :maxDiscount +and v.VoucherType in (:regular, :takeAway)"; + var list = _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("regular", VoucherType.Regular) + .SetParameter("vat", vat) + .SetParameter("maxDiscount", .9M) + .SetParameter("takeAway", VoucherType.TakeAway) + .List(); + Dictionary inventories = new Dictionary(); list = Randomize(list); - - var left = GetFood(vat, startDate, finishDate) - amount; foreach (var item in list) + { + inventories.Add((Guid)item[0], new object[] { Convert.ToDecimal(item[1]), Convert.ToDecimal(item[2]), Convert.ToDecimal(item[3]) }); + } + + var left = GetSaleAmount(vat, startDate, finishDate) - amount; + foreach (var item in inventories) { if (left <= 0) break; - foreach (var kot in item.Kots) - { - if (left <= 0) - break; - foreach (var inventory in kot.Inventories) - { - if (left <= 0) - break; - if (inventory.VatRate == vat) - { - var minimum = inventory.Discount == 0 ? 10 : Convert.ToInt32(inventory.Discount * 100); - if (minimum >= 90) - continue; - var discount = Convert.ToDecimal(rand.Next(minimum, 90)) / 100; - if (discount == inventory.Discount) - continue; - var reduction = inventory.Quantity * inventory.Price * - (1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)) * - (discount - inventory.Discount); + var invQuantity = (decimal)item.Value[0]; + var invDiscount = (decimal)item.Value[1]; + var invNet = (decimal)item.Value[2]; + var minimum = invDiscount == 0 ? 10 : Convert.ToInt32(invDiscount * 100); + var discount = Convert.ToDecimal(rand.Next(minimum, 90)) / 100; + if (discount == invDiscount) + continue; + var reduction = invNet * (discount - invDiscount); - var i = _session.QueryOver().Where(x => x.InventoryID == inventory.InventoryID).SingleOrDefault(); - if (reduction > left) - { - discount = inventory.Quantity * inventory.Price * - (1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)); - discount = left / discount; - i.Discount = discount; - _session.Update(i); - left = 0; - } - else - { - i.Discount = discount; - _session.Update(i); - left -= reduction; - } - } - } + if (reduction > left) + { + discount = left / invNet; + query = @"update Inventory set Discount = :discount where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("discount", discount).SetParameter("inventoryID", item.Key).ExecuteUpdate(); + left = 0; + } + else + { + query = @"update Inventory set Discount = :discount where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("discount", discount).SetParameter("inventoryID", item.Key).ExecuteUpdate(); + left -= reduction; } } - return GetFood(vat, startDate, finishDate); - } - - public decimal SetAmount(int vatID, decimal amount, DateTime startDate, DateTime finishDate) - { - throw new NotImplementedException(); - //var random = new Random(); - //var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff)); - //var left = GetFood(vatID, startDate, finishDate) - amount; - //foreach (var item in list) - //{ - // if (left <= 0) - // break; - // var discount = Convert.ToDecimal(random.Next(20, 70)); - // discount -= discount % 5; - // discount = discount / 100; - // foreach (var kot in item.Kots) - // { - // if (left <= 0) - // break; - // foreach (var inventory in kot.Inventories) - // { - // if (left <= 0) - // break; - // if (inventory.Product.Vat.TaxID == vatID) - // { - // using (var bi = new InventoryBI()) - // { - // if (discount < inventory.Discount) - // continue; - // var inventoryAmount = inventory.Quantity * inventory.Price * (1 - inventory.Discount) * - // (1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)); - // var reduction = inventory.Quantity * inventory.Price * (discount - inventory.Discount) * - // (1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)); - // if (reduction > left) - // { - // var newDiscount = (1 - inventory.Discount) * left / inventoryAmount; - // var i = bi.Get(x => x.InventoryID == inventory.InventoryID); - // i.Discount = newDiscount; - // bi.Update(i); - // left = 0; - // } - // else - // { - // var i = bi.Get(x => x.InventoryID == inventory.InventoryID); - // i.Discount = discount; - // bi.Update(i); - // left -= reduction; - // } - // } - // } - // } - // } - //} - //return GetFood(vatID, startDate, finishDate); - } - - public IList GetNcable(DateTime startDate, DateTime finishDate) - { - const string query = @" -select v.VoucherID, sum(case when p.TaxID = 1 then i.ServiceCharge else 0 end) , sum(i.Quantity * p.Quantity) as Quantity -from Voucher v -inner join v.Kots k -inner join k.Inventories i -inner join i.Product p -where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false -group by p.BaseCode -order by p.BaseCode - "; - var list = _session - .CreateQuery(query) - .SetParameter("startDate", startDate) - .SetParameter("finishDate", finishDate) - .List(); - return list; - } - - public IList GetMove(DateTime startDate, DateTime finishDate) - { - const string query = @" -select p.BaseCode, sum(i.Quantity * p.Quantity) as Quantity -from Voucher v -inner join v.Kots k -inner join k.Inventories i -inner join i.Product p -where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.BaseCode != 0 -group by p.BaseCode -order by p.BaseCode - "; - var list = _session - .CreateQuery(query) - .SetParameter("startDate", startDate) - .SetParameter("finishDate", finishDate) - .List(); - return list; + return GetSaleAmount(vat, startDate, finishDate); } #region Beer - public decimal GetQuantity(DateTime startDate, DateTime finishDate) + public decimal GetBeer(DateTime startDate, DateTime finishDate) { const string query = @" select sum(i.Quantity * p.Quantity) as Quantity @@ -579,45 +703,57 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Qu .UniqueResult(); return qty == null ? 0 : (decimal)qty; } - public decimal SetQuantity(DateTime startDate, DateTime finishDate, decimal quantity) + public decimal SetBeer(DateTime startDate, DateTime finishDate, decimal quantity) { - var list = _session.QueryOver().Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false).List(); + var query = @" +select i.InventoryID, i.Product.ProductID, i.Quantity, p.Quantity +from Voucher v +inner join v.Kots k +inner join k.Inventories i +inner join i.Product p +where v.Date >= :startDate and v.Date <= :finishDate +and p.Quantity != 0"; + var list = _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .List(); list = Randomize(list); - var left = GetQuantity(startDate, finishDate) - quantity; + Dictionary inventories = new Dictionary(); foreach (var item in list) + { + var inventoryID = (Guid)item[0]; + var productID = (Guid)item[1]; + var inventoryQuantity = (decimal)item[2]; + var productQuantity = (decimal)item[3]; + inventories.Add(inventoryID, new object[] { productID, inventoryQuantity, productQuantity }); + } + var left = GetBeer(startDate, finishDate) - quantity; + foreach (var item in inventories) { if (left <= 0) break; - foreach (var kot in item.Kots) - { - if (left <= 0) - break; - foreach (var inventory in kot.Inventories) - { - if (left <= 0) - break; - if (inventory.Product.Quantity != 0) - { - var inventoryQuantity = inventory.Quantity * inventory.Product.Quantity; + var productID = (Guid)item.Value[0]; + var inventoryQuantity = (decimal)item.Value[1]; + var productQuantity = (decimal)item.Value[2]; - var i = _session.QueryOver().Where(x => x.InventoryID == inventory.InventoryID).SingleOrDefault(); - if (inventoryQuantity > left) - { - var newQuantity = inventory.Quantity * (inventoryQuantity - left) / inventoryQuantity; - i.Quantity = newQuantity; - _session.Update(i); - left = 0; - } - else - { - left -= inventoryQuantity; - _session.Delete(i); - } - } - } + var q = inventoryQuantity * productQuantity; + + if (q > left) + { + var newQuantity = inventoryQuantity * (q - left) / q; + query = @"update Inventory set Quantity = :quantity where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("quantity", newQuantity).SetParameter("inventoryID", item.Key).ExecuteUpdate(); + left = 0; + } + else + { + query = @"delete from Inventory where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("inventoryID", item.Key).ExecuteUpdate(); + left -= q; } } - return GetQuantity(startDate, finishDate); + return GetBeer(startDate, finishDate); } #endregion #region Helper and Comments @@ -634,7 +770,22 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Qu } return tList.ToList(); } - // public decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate) + public string FullBillID(int billID, VoucherType voucherType) + { + switch (voucherType) + { + case VoucherType.NoCharge: + return "NC-" + billID.ToString(); + case VoucherType.Staff: + return "ST-" + billID.ToString(); + case VoucherType.TakeAway: + case VoucherType.Regular: + default: + return (billID / 10000).ToString() + "-" + (billID % 10000).ToString(); + } + } + + // public decimal GetBeer(int baseCode, DateTime startDate, DateTime finishDate) // { // const string query = @" //select sum(i.Quantity * p.Quantity) as Quantity @@ -655,7 +806,7 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Qu // public decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate) // { // var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false)); - // var left = GetQuantity(baseCode, startDate, finishDate) - quantity; + // var left = GetBeer(baseCode, startDate, finishDate) - quantity; // foreach (var item in list) // { // if (left <= 0) @@ -692,7 +843,7 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Qu // } // } // } - // return GetQuantity(baseCode, startDate, finishDate); + // return GetBeer(baseCode, startDate, finishDate); // } //private static int GetNewID(int code, int toBaseCode) //{