From fd54104560c56db790495041b19da9d8845690a8 Mon Sep 17 00:00:00 2001 From: Tanshu Date: Tue, 12 Feb 2013 18:55:10 +0530 Subject: [PATCH] Management form working with the correct CSV file. --- .../Data Contracts/VoucherSettlementBO.cs | 6 +- Tanshu.Accounts.PointOfSale/MainForm.cs | 24 +- .../MainForm.designer.cs | 54 +- .../Management/AmountForm.cs | 49 -- .../Management/FoodForm.cs | 46 -- .../Management/FoodForm.designer.cs | 116 --- .../Management/FoodForm.resx | 120 --- .../Management/ManagementForm.cs | 538 +++++++++++++ ...designer.cs => ManagementForm.designer.cs} | 60 +- .../{AmountForm.resx => ManagementForm.resx} | 0 .../Management/MoveForm.cs | 162 ---- .../Management/MoveForm.designer.cs | 119 --- .../Management/MoveForm.resx | 120 --- .../Management/NcForm.cs | 129 ---- .../Management/NcForm.designer.cs | 119 --- .../Management/NcForm.resx | 120 --- .../Management/QuantityForm.cs | 159 ---- .../Management/QuantityForm.designer.cs | 92 --- .../Management/QuantityForm.resx | 120 --- .../Reports/SaleDetail.cs | 2 - .../Tanshu.Accounts.PointOfSale.csproj | 37 +- .../BusinessLayer/InventoryBI.cs | 6 +- .../BusinessLayer/ManagementBI.cs | 731 +++++++++++++++--- .../BusinessLayer/SalesAnalysisBI.cs | 2 +- .../Fluent/SetupStore.cs | 15 +- 25 files changed, 1239 insertions(+), 1707 deletions(-) delete mode 100644 Tanshu.Accounts.PointOfSale/Management/AmountForm.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/FoodForm.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/FoodForm.designer.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/FoodForm.resx create mode 100644 Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs rename Tanshu.Accounts.PointOfSale/Management/{AmountForm.designer.cs => ManagementForm.designer.cs} (66%) rename Tanshu.Accounts.PointOfSale/Management/{AmountForm.resx => ManagementForm.resx} (100%) delete mode 100644 Tanshu.Accounts.PointOfSale/Management/MoveForm.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/MoveForm.designer.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/MoveForm.resx delete mode 100644 Tanshu.Accounts.PointOfSale/Management/NcForm.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/NcForm.designer.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/NcForm.resx delete mode 100644 Tanshu.Accounts.PointOfSale/Management/QuantityForm.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/QuantityForm.designer.cs delete mode 100644 Tanshu.Accounts.PointOfSale/Management/QuantityForm.resx diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs index 21366e0..7e6754b 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherSettlementBO.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using Tanshu.Accounts.Contracts; -using Tanshu.Accounts.Contracts.Attributes; -using Tanshu.Accounts.Entities.Auth; +using Tanshu.Accounts.Contracts; namespace Tanshu.Accounts.Entities { diff --git a/Tanshu.Accounts.PointOfSale/MainForm.cs b/Tanshu.Accounts.PointOfSale/MainForm.cs index e594b8f..6ccff30 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.cs @@ -180,13 +180,9 @@ namespace Tanshu.Accounts.PointOfSale btnChangePassword.Visible = Session.IsAuthenticated; #if (DEBUG) - btnMgtBeer.Visible = true; - btnMgtFood.Visible = true; - btnMgtLiq.Visible = true; + btnManagement.Visible = true; #else - btnMgtBeer.Visible = false; - btnMgtFood.Visible = false; - btnMgtLiq.Visible = false; + btnManagement.Visible = false; #endif } @@ -279,21 +275,9 @@ namespace Tanshu.Accounts.PointOfSale } - private void btnMgtBeer_Click(object sender, EventArgs e) + private void btnManagement_Click(object sender, EventArgs e) { - using (var frm = new MoveForm()) - frm.ShowDialog(); - } - - private void btnMgtFood_Click(object sender, EventArgs e) - { - using (var frm = new FoodForm()) - frm.ShowDialog(); - } - - private void btnMgtLiq_Click(object sender, EventArgs e) - { - using (var frm = new AmountForm()) + using (var frm = new ManagementForm()) frm.ShowDialog(); } } diff --git a/Tanshu.Accounts.PointOfSale/MainForm.designer.cs b/Tanshu.Accounts.PointOfSale/MainForm.designer.cs index 2ff442c..f108033 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.designer.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.designer.cs @@ -49,9 +49,7 @@ this.btnDiscountReport = new System.Windows.Forms.Button(); this.btnChangePassword = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); - this.btnMgtBeer = new System.Windows.Forms.Button(); - this.btnMgtFood = new System.Windows.Forms.Button(); - this.btnMgtLiq = new System.Windows.Forms.Button(); + this.btnManagement = new System.Windows.Forms.Button(); this.flowLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // @@ -99,9 +97,7 @@ this.flowLayoutPanel1.Controls.Add(this.btnDiscountReport); this.flowLayoutPanel1.Controls.Add(this.btnChangePassword); this.flowLayoutPanel1.Controls.Add(this.btnExit); - this.flowLayoutPanel1.Controls.Add(this.btnMgtBeer); - this.flowLayoutPanel1.Controls.Add(this.btnMgtFood); - this.flowLayoutPanel1.Controls.Add(this.btnMgtLiq); + this.flowLayoutPanel1.Controls.Add(this.btnManagement); this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4); @@ -307,38 +303,16 @@ this.btnExit.UseVisualStyleBackColor = true; this.btnExit.Click += new System.EventHandler(this.btnExit_Click); // - // btnMgtBeer + // btnManagement // - this.btnMgtBeer.Location = new System.Drawing.Point(4, 528); - this.btnMgtBeer.Margin = new System.Windows.Forms.Padding(4); - this.btnMgtBeer.Name = "btnMgtBeer"; - this.btnMgtBeer.Size = new System.Drawing.Size(200, 123); - this.btnMgtBeer.TabIndex = 20; - this.btnMgtBeer.Text = "Beer Quantity"; - this.btnMgtBeer.UseVisualStyleBackColor = true; - this.btnMgtBeer.Click += new System.EventHandler(this.btnMgtBeer_Click); - // - // btnMgtFood - // - this.btnMgtFood.Location = new System.Drawing.Point(212, 528); - this.btnMgtFood.Margin = new System.Windows.Forms.Padding(4); - this.btnMgtFood.Name = "btnMgtFood"; - this.btnMgtFood.Size = new System.Drawing.Size(200, 123); - this.btnMgtFood.TabIndex = 22; - this.btnMgtFood.Text = "Food Amount"; - this.btnMgtFood.UseVisualStyleBackColor = true; - this.btnMgtFood.Click += new System.EventHandler(this.btnMgtFood_Click); - // - // btnMgtLiq - // - this.btnMgtLiq.Location = new System.Drawing.Point(420, 528); - this.btnMgtLiq.Margin = new System.Windows.Forms.Padding(4); - this.btnMgtLiq.Name = "btnMgtLiq"; - this.btnMgtLiq.Size = new System.Drawing.Size(200, 123); - this.btnMgtLiq.TabIndex = 23; - this.btnMgtLiq.Text = "Liq Amount"; - this.btnMgtLiq.UseVisualStyleBackColor = true; - this.btnMgtLiq.Click += new System.EventHandler(this.btnMgtLiq_Click); + this.btnManagement.Location = new System.Drawing.Point(4, 528); + this.btnManagement.Margin = new System.Windows.Forms.Padding(4); + this.btnManagement.Name = "btnManagement"; + this.btnManagement.Size = new System.Drawing.Size(200, 123); + this.btnManagement.TabIndex = 20; + this.btnManagement.Text = "Management"; + this.btnManagement.UseVisualStyleBackColor = true; + this.btnManagement.Click += new System.EventHandler(this.btnManagement_Click); // // MainForm // @@ -346,7 +320,7 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1056, 661); this.Controls.Add(this.flowLayoutPanel1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Margin = new System.Windows.Forms.Padding(4); this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; @@ -380,9 +354,7 @@ private System.Windows.Forms.Button btnOpenBill; private System.Windows.Forms.Button btnBillDetails; private System.Windows.Forms.Button btnVoidOrReprints; - private System.Windows.Forms.Button btnMgtBeer; + private System.Windows.Forms.Button btnManagement; private System.Windows.Forms.Button btnDiscountReport; - private System.Windows.Forms.Button btnMgtFood; - private System.Windows.Forms.Button btnMgtLiq; } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/AmountForm.cs b/Tanshu.Accounts.PointOfSale/Management/AmountForm.cs deleted file mode 100644 index dc3cfc3..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/AmountForm.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Windows.Forms; -using Tanshu.Accounts.Repository; - -namespace Tanshu.Accounts.Management -{ - public partial class AmountForm : Form - { - public AmountForm() - { - InitializeComponent(); - } - - private void Sale_Analysis_Form_Load(object sender, EventArgs e) - { - dtpStart.Value = DateTime.Today; - dtpFinish.Value = DateTime.Today; - } - - private void btnGo_Click(object sender, EventArgs e) - { - dtpStart.Value = dtpStart.Value.Date.AddHours(7); - dtpFinish.Value = dtpFinish.Value.Date.AddDays(1).AddHours(7); - var amount = GetAmount(); - var newAmount = TryConvert(txtQuantity.Text); - if (MessageBox.Show(amount.ToString(), "Amounts", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes && amount > newAmount) - { - MessageBox.Show(SetAmount(newAmount).ToString()); - } - } - private decimal TryConvert(string amount) - { - decimal result = 0; - decimal.TryParse(amount, out result); - return result; - } - private decimal GetAmount() - { - using (var bi = new ManagementBI()) - return bi.GetFood(2, dtpStart.Value, dtpFinish.Value); - } - private decimal SetAmount(decimal quantity) - { - using (var bi = new ManagementBI()) - return bi.SetAmount(2, quantity, dtpStart.Value, dtpFinish.Value); - } - - } -} diff --git a/Tanshu.Accounts.PointOfSale/Management/FoodForm.cs b/Tanshu.Accounts.PointOfSale/Management/FoodForm.cs deleted file mode 100644 index 3d0b979..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/FoodForm.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Windows.Forms; -using Tanshu.Accounts.Repository; -using Tanshu.Accounts.Contracts; - -namespace Tanshu.Accounts.Management -{ - public partial class FoodForm : Form - { - public FoodForm() - { - InitializeComponent(); - } - - private void Sale_Analysis_Form_Load(object sender, EventArgs e) - { - dtpStart.Value = DateTime.Today; - dtpFinish.Value = DateTime.Today; - } - - private void btnGo_Click(object sender, EventArgs e) - { - dtpStart.Value = dtpStart.Value.Date.AddHours(7); - dtpFinish.Value = dtpFinish.Value.Date.AddDays(1).AddHours(7); - var amount = GetFood(); - var newAmount = Convert.ToDecimal(txtQuantity.Text); - if (MessageBox.Show(amount.ToString(), "Food Sales", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes && amount > newAmount) - { - MessageBox.Show(SetFood(newAmount).ToString()); - } - } - private decimal GetFood() - { - using (var bi = new ManagementBI()) - return bi.GetFood(1, dtpStart.Value, dtpFinish.Value); - } - private decimal SetFood(decimal quantity) - { - using (var bi = new ManagementBI()) - return bi.SetFood(1, quantity, dtpStart.Value, dtpFinish.Value); - } - - } -} diff --git a/Tanshu.Accounts.PointOfSale/Management/FoodForm.designer.cs b/Tanshu.Accounts.PointOfSale/Management/FoodForm.designer.cs deleted file mode 100644 index f072935..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/FoodForm.designer.cs +++ /dev/null @@ -1,116 +0,0 @@ -namespace Tanshu.Accounts.Management -{ - partial class FoodForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.dtpFinish = new System.Windows.Forms.DateTimePicker(); - this.dtpStart = new System.Windows.Forms.DateTimePicker(); - this.label10 = new System.Windows.Forms.Label(); - this.txtQuantity = new System.Windows.Forms.TextBox(); - this.btnGo = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // dtpFinish - // - this.dtpFinish.CustomFormat = "dd-MMM-yyyy"; - this.dtpFinish.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpFinish.Location = new System.Drawing.Point(224, 15); - this.dtpFinish.Margin = new System.Windows.Forms.Padding(4); - this.dtpFinish.Name = "dtpFinish"; - this.dtpFinish.Size = new System.Drawing.Size(119, 22); - this.dtpFinish.TabIndex = 21; - // - // dtpStart - // - this.dtpStart.CustomFormat = "dd-MMM-yyyy"; - this.dtpStart.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpStart.Location = new System.Drawing.Point(16, 15); - this.dtpStart.Margin = new System.Windows.Forms.Padding(4); - this.dtpStart.Name = "dtpStart"; - this.dtpStart.Size = new System.Drawing.Size(119, 22); - this.dtpStart.TabIndex = 20; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(144, 20); - this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(72, 17); - this.label10.TabIndex = 22; - this.label10.Text = "<- Date ->"; - // - // txtQuantity - // - this.txtQuantity.Location = new System.Drawing.Point(16, 223); - this.txtQuantity.Margin = new System.Windows.Forms.Padding(4); - this.txtQuantity.Name = "txtQuantity"; - this.txtQuantity.Size = new System.Drawing.Size(445, 22); - this.txtQuantity.TabIndex = 5; - // - // btnGo - // - this.btnGo.Location = new System.Drawing.Point(16, 255); - this.btnGo.Margin = new System.Windows.Forms.Padding(4); - this.btnGo.Name = "btnGo"; - this.btnGo.Size = new System.Drawing.Size(200, 28); - this.btnGo.TabIndex = 24; - this.btnGo.Text = "Go"; - this.btnGo.UseVisualStyleBackColor = true; - this.btnGo.Click += new System.EventHandler(this.btnGo_Click); - // - // FoodForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(479, 298); - this.Controls.Add(this.btnGo); - this.Controls.Add(this.dtpFinish); - this.Controls.Add(this.dtpStart); - this.Controls.Add(this.label10); - this.Controls.Add(this.txtQuantity); - this.Margin = new System.Windows.Forms.Padding(4); - this.MaximizeBox = false; - this.Name = "FoodForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sale Analysis Form"; - this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.DateTimePicker dtpFinish; - private System.Windows.Forms.DateTimePicker dtpStart; - private System.Windows.Forms.Label label10; - private System.Windows.Forms.TextBox txtQuantity; - private System.Windows.Forms.Button btnGo; - } -} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/FoodForm.resx b/Tanshu.Accounts.PointOfSale/Management/FoodForm.resx deleted file mode 100644 index 19dc0dd..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/FoodForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs new file mode 100644 index 0000000..a4d1aeb --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs @@ -0,0 +1,538 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using Tanshu.Accounts.Repository; + +namespace Tanshu.Accounts.Management +{ + public partial class ManagementForm : Form + { + public ManagementForm() + { + InitializeComponent(); + } + + private void Sale_Analysis_Form_Load(object sender, EventArgs e) + { + dtpStart.Value = DateTime.Today; + dtpFinish.Value = DateTime.Today; + } + + private void btnGo_Click(object sender, EventArgs e) + { + 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 error = string.Empty; + if (!File.Exists(beer)) + error += "Beer not found! "; + if (!File.Exists(sale)) + error += "Sale not found! "; + if (!File.Exists(credit)) + error += "Credit not found"; + if (!string.IsNullOrEmpty(error)) + { + MessageBox.Show(error); + } + else + { + btnGo.Enabled = false; + var beerDates = GetBeer(beer); + var saleDates = GetSale(sale); + var creditDates = GetCredit(credit); + + 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) + { + MessageBox.Show("Error reading line: " + line); + continue; + } + 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]) + }); + } + } + return dates; + } + private Dictionary GetCredit(string credit) + { + 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; + } + private Dictionary GetBeer(string beer) + { + 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; + } + #endregion + private static void ProcessData(bool opening, DateTime startIn, DateTime finishIn, decimal liqTarget) + { + var startDate = startIn.AddHours(7); + var finishDate = finishIn.AddDays(1).AddHours(7); + if (opening) + { + 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); + } + } + } + + private static void ProcessBeer(Dictionary dates, DateTime startIn, DateTime finishIn) + { + using (var bi = new ManagementBI()) + { + 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); + } + } + } + } + + private static string ProcessSale(SaleData item, Dictionary creditDates) + { + 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()) + { + 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"; + } + 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; + } + + private static decimal TryConvert(string amount) + { + decimal result = 0; + decimal.TryParse(amount, out result); + return result; + } + + private void button1_Click(object sender, EventArgs e) + { + var startDate = dtpStart.Value.Date; + var finishDate = dtpFinish.Value.Date; + var daybook = @" + +
+Import Data +
+ + + +All Masters + +Peitho Foods Pvt. Ltd.(2012-13) + + + + +"; + + for (var date = startDate; date <= finishDate; date = date.AddDays(1)) + { + daybook += GetVoucher(date); + } + daybook += @" + + + + +
+"; + Clipboard.SetText(daybook, TextDataFormat.Text); + } + private static string GetVoucher(DateTime date) + { + var currentStart = date.AddHours(7); + var currentFinish = date.AddDays(1).AddHours(7); + var voucher = string.Empty; + var cash = 0M; + using (var bi = new ManagementBI()) + { + var sale = Math.Round(bi.GetFood(.26250M, currentStart, currentFinish)); + var vat = 0M; + if (sale != 0) + { + 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")); + } + + sale = Math.Round(bi.GetFood(.1575M, currentStart, currentFinish)); + if (sale != 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")); + } + + if (cash != 0) + { + voucher = GetLedger("Cash", cash.ToString("#0.00")) + voucher; + } + } + return voucher != "" ? GetVoucher(date.ToString("yyyyMMdd"), voucher) : ""; + } + private static string GetVoucher(string date, string ledgers) + { + #region Voucher Template + var template = @" + + {1} + {0} + Journal + 349 + Cash + + + Default + + Admin + No + No + No + No + {1} + No + No + No + No + 3525 + No + No + Yes + No + No + No + No + No + No + No + No +{2} + +"; + var servicetaxtemplate = @""; + #endregion + return string.Format(template, Guid.NewGuid(), date, ledgers); + } + private static string GetLedger(string ledgername, string amount) + { + var isDeemedPositive = string.Empty; + var isPartyLedger = string.Empty; + switch (ledgername) + { + case "Cash": + isDeemedPositive = "Yes"; + isPartyLedger = "Yes"; + amount = "-" + amount; + break; + case "Sale 12.5%": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Sale @ 15%": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Sale @ 25 %": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Sale Tax Free": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Output Vat 12.5%": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Output Vat @ 15%": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Output Vat @ 25%": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + case "Central Service Tax@3.708%": + isDeemedPositive = "No"; + isPartyLedger = "No"; + break; + + + } + #region Voucher Template + const string template = @" + + {0} + + {1} + No + No + {2} + {3} + +"; + var servicetaxtemplate = @""; + #endregion + return string.Format(template, ledgername, isDeemedPositive, isPartyLedger, amount); + } + private void button2_Click(object sender, EventArgs e) + { + using (var bi = new ManagementBI()) + { + bi.FinalSanction(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7)); + } + } + + private void button3_Click(object sender, EventArgs e) + { + button3.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); + } + Clipboard.SetText(sheet, TextDataFormat.Text); + button3.Enabled = true; + } + private static string GetExcel(DateTime date) + { + 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))); + + 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))); + + cash += string.Format("{0:#0}\n", Math.Round(bi.GetServiceTax(currentStart, currentFinish))); + return cash; + } + } + + } +} diff --git a/Tanshu.Accounts.PointOfSale/Management/AmountForm.designer.cs b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs similarity index 66% rename from Tanshu.Accounts.PointOfSale/Management/AmountForm.designer.cs rename to Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs index 1a54262..36a2921 100644 --- a/Tanshu.Accounts.PointOfSale/Management/AmountForm.designer.cs +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs @@ -1,6 +1,6 @@ namespace Tanshu.Accounts.Management { - partial class AmountForm + partial class ManagementForm { /// /// Required designer variable. @@ -31,8 +31,10 @@ this.dtpFinish = new System.Windows.Forms.DateTimePicker(); this.dtpStart = new System.Windows.Forms.DateTimePicker(); this.label10 = new System.Windows.Forms.Label(); - this.txtQuantity = new System.Windows.Forms.TextBox(); this.btnGo = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // dtpFinish @@ -65,16 +67,9 @@ this.label10.TabIndex = 22; this.label10.Text = "<- Date ->"; // - // txtQuantity - // - this.txtQuantity.Location = new System.Drawing.Point(16, 223); - this.txtQuantity.Margin = new System.Windows.Forms.Padding(4); - this.txtQuantity.Name = "txtQuantity"; - this.txtQuantity.Size = new System.Drawing.Size(445, 22); - this.txtQuantity.TabIndex = 5; - // // btnGo // + this.btnGo.Enabled = false; this.btnGo.Location = new System.Drawing.Point(16, 255); this.btnGo.Margin = new System.Windows.Forms.Padding(4); this.btnGo.Name = "btnGo"; @@ -84,19 +79,54 @@ this.btnGo.UseVisualStyleBackColor = true; this.btnGo.Click += new System.EventHandler(this.btnGo_Click); // - // FoodForm + // button1 + // + this.button1.Location = new System.Drawing.Point(224, 255); + this.button1.Margin = new System.Windows.Forms.Padding(4); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(200, 28); + this.button1.TabIndex = 25; + this.button1.Text = "Tally"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(16, 219); + this.button2.Margin = new System.Windows.Forms.Padding(4); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(200, 28); + this.button2.TabIndex = 26; + this.button2.Text = "Final Sanction"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(224, 219); + this.button3.Margin = new System.Windows.Forms.Padding(4); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(200, 28); + this.button3.TabIndex = 27; + this.button3.Text = "Excel"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // ManagementForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(479, 298); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); this.Controls.Add(this.btnGo); this.Controls.Add(this.dtpFinish); this.Controls.Add(this.dtpStart); this.Controls.Add(this.label10); - this.Controls.Add(this.txtQuantity); this.Margin = new System.Windows.Forms.Padding(4); this.MaximizeBox = false; - this.Name = "FoodForm"; + this.Name = "ManagementForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Sale Analysis Form"; this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load); @@ -110,7 +140,9 @@ private System.Windows.Forms.DateTimePicker dtpFinish; private System.Windows.Forms.DateTimePicker dtpStart; private System.Windows.Forms.Label label10; - private System.Windows.Forms.TextBox txtQuantity; private System.Windows.Forms.Button btnGo; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/AmountForm.resx b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx similarity index 100% rename from Tanshu.Accounts.PointOfSale/Management/AmountForm.resx rename to Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx diff --git a/Tanshu.Accounts.PointOfSale/Management/MoveForm.cs b/Tanshu.Accounts.PointOfSale/Management/MoveForm.cs deleted file mode 100644 index 1b1c9ab..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/MoveForm.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Windows.Forms; -using Tanshu.Accounts.Repository; - -namespace Tanshu.Accounts.Management -{ - public partial class MoveForm : Form - { - private IList comboBoxes; - private IDictionary list; - public MoveForm() - { - InitializeComponent(); - list = new Dictionary - { - {1, "1 - Dark"}, - {2, "2 - Wheat"}, - {3, "3 - Premium"}, - {4, "4 - Light"}, - {5, "5 - Dragon"}, - {6, "6 - Festival"}, - {7, "7 - Vanilla"}, - {8, "8 - Strong"} - }; - } - - private void Sale_Analysis_Form_Load(object sender, EventArgs e) - { - dtpStartDate.Value = DateTime.Today; - dtpFinishDate.Value = DateTime.Today; - } - - private void btnGo_Click(object sender, EventArgs e) - { - comboBoxes = new List(); - var startDate = dtpStartDate.Value.Date.AddHours(7); - var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7); - var details = GetMove(startDate, finishDate); - foreach (var detail in details) - { - var item = (object[])detail; - var text = GetName((int)item[0]) + " ---> " + ((decimal)item[1]).ToString(); - - var label = new Label() - { - Name = "label" + ((int)item[0]).ToString(CultureInfo.InvariantCulture), - AutoSize = true, - Text = text - }; - flpProducts.Controls.Add(label); - var comboBox = GetBox((int)item[0]); - comboBoxes.Add(comboBox); - flpProducts.Controls.Add(comboBox); - - } - //foreach (var comboBox in comboBoxes) - //{ - // var startDate = dtpStartDate.Value.Date.AddHours(7); - // var finishDate = startDate.AddDays(1); - - // var baseCode = (int)(((object[])comboBox.Tag)[0]); - // var text = (string)(((object[])comboBox.Tag)[1]); - // foreach (var item in comboBox.Text.Split(',')) - // { - // var newQuantity = TryConvert(item); - // var quantity = GetQuantity(baseCode, startDate, finishDate); - - // if (MessageBox.Show(text + " " + startDate.ToString("dd-MMM-yyyy") + " " + quantity.ToString(), "Quantity of Beer", MessageBoxButtons.YesNo, - // MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes && - // quantity > newQuantity && newQuantity > 0) - // { - // MessageBox.Show(SetQuantity(baseCode, newQuantity, startDate, finishDate).ToString()); - // } - // startDate = startDate.AddDays(1); - // finishDate = finishDate.AddDays(1); - // } - //} - } - private ComboBox GetBox(int code) - { - var comboBox = new ComboBox() - { - Name = "comboBox" + (code).ToString(CultureInfo.InvariantCulture), - Width = 400, - Height = 20, - Tag = code, - DisplayMember = "Value", - ValueMember = "Key", - DropDownStyle = ComboBoxStyle.DropDownList, - DataSource = new BindingSource(list, null) - }; - //foreach (var item in list) - // comboBox.Items.Add(new { Code = item.Key, Name = item.Value }); - //MessageBox.Show(code.ToString()); - //comboBox.SelectedIndex = code - 1; - comboBox.SelectedValue = code; - return comboBox; - } - private static string GetName(int code) - { - switch (code) - { - case 1: - return "1 - Dark"; - case 2: - return "2 - Wheat"; - case 3: - return "3 - Premium"; - case 4: - return "4 - Light"; - case 5: - return "5 - Dragon"; - case 6: - return "6 - Festival"; - case 7: - return "7 - Vanilla"; - case 8: - return "8 - Strong"; - default: - return ""; - } - } - private static decimal TryConvert(string amount) - { - decimal result = 0; - decimal.TryParse(amount, out result); - return result; - } - - private static IList GetMove(DateTime startDate, DateTime finishDate) - { - using (var bi = new ManagementBI()) - return bi.GetMove(startDate, finishDate); - } - private static void SetMove(int fromBaseCode, int toBaseCode, DateTime startDate, DateTime finishDate) - { - using (var bi = new ManagementBI()) - bi.SetMove(fromBaseCode, toBaseCode, startDate, finishDate); - } - - private void btnProcess_Click(object sender, EventArgs e) - { - btnProcess.Enabled = false; - var startDate = dtpStartDate.Value.Date.AddHours(7); - var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7); - foreach (var item in comboBoxes) - { - var fromBaseCode = (int) item.Tag; - var toBaseCode = (int) item.SelectedValue; - if (fromBaseCode == toBaseCode) - continue; - Text = GetName(fromBaseCode) + " to " + GetName(toBaseCode); - MessageBox.Show(Text); - SetMove(fromBaseCode, toBaseCode, startDate , finishDate); - } - } - - } -} diff --git a/Tanshu.Accounts.PointOfSale/Management/MoveForm.designer.cs b/Tanshu.Accounts.PointOfSale/Management/MoveForm.designer.cs deleted file mode 100644 index b5a3706..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/MoveForm.designer.cs +++ /dev/null @@ -1,119 +0,0 @@ -namespace Tanshu.Accounts.Management -{ - partial class MoveForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.dtpStartDate = new System.Windows.Forms.DateTimePicker(); - this.flpProducts = new System.Windows.Forms.FlowLayoutPanel(); - this.btnGo = new System.Windows.Forms.Button(); - this.dtpFinishDate = new System.Windows.Forms.DateTimePicker(); - this.btnProcess = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // dtpStartDate - // - this.dtpStartDate.CustomFormat = "dd-MMM-yyyy"; - this.dtpStartDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpStartDate.Location = new System.Drawing.Point(16, 15); - this.dtpStartDate.Margin = new System.Windows.Forms.Padding(4); - this.dtpStartDate.Name = "dtpStartDate"; - this.dtpStartDate.Size = new System.Drawing.Size(119, 22); - this.dtpStartDate.TabIndex = 0; - // - // flpProducts - // - this.flpProducts.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.flpProducts.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flpProducts.Location = new System.Drawing.Point(16, 47); - this.flpProducts.Margin = new System.Windows.Forms.Padding(4); - this.flpProducts.Name = "flpProducts"; - this.flpProducts.Size = new System.Drawing.Size(447, 390); - this.flpProducts.TabIndex = 2; - // - // btnGo - // - this.btnGo.Location = new System.Drawing.Point(16, 445); - this.btnGo.Margin = new System.Windows.Forms.Padding(4); - this.btnGo.Name = "btnGo"; - this.btnGo.Size = new System.Drawing.Size(200, 28); - this.btnGo.TabIndex = 24; - this.btnGo.Text = "Load"; - this.btnGo.UseVisualStyleBackColor = true; - this.btnGo.Click += new System.EventHandler(this.btnGo_Click); - // - // dtpFinishDate - // - this.dtpFinishDate.CustomFormat = "dd-MMM-yyyy"; - this.dtpFinishDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpFinishDate.Location = new System.Drawing.Point(143, 15); - this.dtpFinishDate.Margin = new System.Windows.Forms.Padding(4); - this.dtpFinishDate.Name = "dtpFinishDate"; - this.dtpFinishDate.Size = new System.Drawing.Size(119, 22); - this.dtpFinishDate.TabIndex = 1; - // - // btnProcess - // - this.btnProcess.Location = new System.Drawing.Point(263, 445); - this.btnProcess.Margin = new System.Windows.Forms.Padding(4); - this.btnProcess.Name = "btnProcess"; - this.btnProcess.Size = new System.Drawing.Size(200, 28); - this.btnProcess.TabIndex = 25; - this.btnProcess.Text = "Process"; - this.btnProcess.UseVisualStyleBackColor = true; - this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click); - // - // MoveForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(479, 488); - this.Controls.Add(this.btnProcess); - this.Controls.Add(this.dtpFinishDate); - this.Controls.Add(this.btnGo); - this.Controls.Add(this.flpProducts); - this.Controls.Add(this.dtpStartDate); - this.Margin = new System.Windows.Forms.Padding(4); - this.MaximizeBox = false; - this.Name = "MoveForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sale Analysis Form"; - this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.DateTimePicker dtpStartDate; - private System.Windows.Forms.FlowLayoutPanel flpProducts; - private System.Windows.Forms.Button btnGo; - private System.Windows.Forms.DateTimePicker dtpFinishDate; - private System.Windows.Forms.Button btnProcess; - } -} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/MoveForm.resx b/Tanshu.Accounts.PointOfSale/Management/MoveForm.resx deleted file mode 100644 index 19dc0dd..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/MoveForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/NcForm.cs b/Tanshu.Accounts.PointOfSale/Management/NcForm.cs deleted file mode 100644 index 210beaa..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/NcForm.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Windows.Forms; -using Tanshu.Accounts.Repository; - -namespace Tanshu.Accounts.Management -{ - public partial class NcForm : Form - { - private IList checkBoxes; - private IDictionary list; - public NcForm() - { - InitializeComponent(); - } - - private void Sale_Analysis_Form_Load(object sender, EventArgs e) - { - dtpStartDate.Value = DateTime.Today; - dtpFinishDate.Value = DateTime.Today; - } - - private void btnGo_Click(object sender, EventArgs e) - { - checkBoxes = new List(); - var startDate = dtpStartDate.Value.Date.AddHours(7); - var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7); - var details = GetNc(startDate, finishDate); - foreach (var detail in details) - { - var item = (object[])detail; - var text = GetName((int)item[0]) + " ---> " + ((decimal)item[1]).ToString(); - - var label = new Label() - { - Name = "label" + ((int)item[0]).ToString(CultureInfo.InvariantCulture), - AutoSize = true, - Text = text - }; - flpProducts.Controls.Add(label); - var checkBox = GetBox((int)item[0]); - checkBoxes.Add(checkBox); - flpProducts.Controls.Add(checkBox); - - } - } - private ComboBox GetBox(int code) - { - var checkBox = new CheckBox() - { - Name = "comboBox" + (code).ToString(CultureInfo.InvariantCulture), - Width = 400, - Height = 20, - Tag = code, - DisplayMember = "Value", - ValueMember = "Key", - DropDownStyle = ComboBoxStyle.DropDownList, - DataSource = new BindingSource(list, null) - }; - //foreach (var item in list) - // comboBox.Items.Add(new { Code = item.Key, Name = item.Value }); - //MessageBox.Show(code.ToString()); - //comboBox.SelectedIndex = code - 1; - comboBox.SelectedValue = code; - return comboBox; - } - private static string GetName(int code) - { - switch (code) - { - case 1: - return "1 - Dark"; - case 2: - return "2 - Wheat"; - case 3: - return "3 - Premium"; - case 4: - return "4 - Light"; - case 5: - return "5 - Dragon"; - case 6: - return "6 - Festival"; - case 7: - return "7 - Vanilla"; - case 8: - return "8 - Strong"; - default: - return ""; - } - } - private static decimal TryConvert(string amount) - { - decimal result = 0; - decimal.TryParse(amount, out result); - return result; - } - - private static IList GetNcable(DateTime startDate, DateTime finishDate) - { - using (var bi = new ManagementBI()) - return bi.GetNcable(startDate, finishDate); - } - private static void SetMove(int fromBaseCode, int toBaseCode, DateTime startDate, DateTime finishDate) - { - using (var bi = new ManagementBI()) - bi.SetMove(fromBaseCode, toBaseCode, startDate, finishDate); - } - - private void btnProcess_Click(object sender, EventArgs e) - { - btnProcess.Enabled = false; - var startDate = dtpStartDate.Value.Date.AddHours(7); - var finishDate = dtpFinishDate.Value.Date.AddDays(1).AddHours(7); - foreach (var item in comboBoxes) - { - var fromBaseCode = (int) item.Tag; - var toBaseCode = (int) item.SelectedValue; - if (fromBaseCode == toBaseCode) - continue; - Text = GetName(fromBaseCode) + " to " + GetName(toBaseCode); - MessageBox.Show(Text); - SetMove(fromBaseCode, toBaseCode, startDate , finishDate); - } - } - - } -} diff --git a/Tanshu.Accounts.PointOfSale/Management/NcForm.designer.cs b/Tanshu.Accounts.PointOfSale/Management/NcForm.designer.cs deleted file mode 100644 index fb069bb..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/NcForm.designer.cs +++ /dev/null @@ -1,119 +0,0 @@ -namespace Tanshu.Accounts.Management -{ - partial class NcForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.dtpStartDate = new System.Windows.Forms.DateTimePicker(); - this.flpProducts = new System.Windows.Forms.FlowLayoutPanel(); - this.btnGo = new System.Windows.Forms.Button(); - this.dtpFinishDate = new System.Windows.Forms.DateTimePicker(); - this.btnProcess = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // dtpStartDate - // - this.dtpStartDate.CustomFormat = "dd-MMM-yyyy"; - this.dtpStartDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpStartDate.Location = new System.Drawing.Point(16, 15); - this.dtpStartDate.Margin = new System.Windows.Forms.Padding(4); - this.dtpStartDate.Name = "dtpStartDate"; - this.dtpStartDate.Size = new System.Drawing.Size(119, 22); - this.dtpStartDate.TabIndex = 0; - // - // flpProducts - // - this.flpProducts.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.flpProducts.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flpProducts.Location = new System.Drawing.Point(16, 47); - this.flpProducts.Margin = new System.Windows.Forms.Padding(4); - this.flpProducts.Name = "flpProducts"; - this.flpProducts.Size = new System.Drawing.Size(447, 390); - this.flpProducts.TabIndex = 2; - // - // btnGo - // - this.btnGo.Location = new System.Drawing.Point(16, 445); - this.btnGo.Margin = new System.Windows.Forms.Padding(4); - this.btnGo.Name = "btnGo"; - this.btnGo.Size = new System.Drawing.Size(200, 28); - this.btnGo.TabIndex = 24; - this.btnGo.Text = "Load"; - this.btnGo.UseVisualStyleBackColor = true; - this.btnGo.Click += new System.EventHandler(this.btnGo_Click); - // - // dtpFinishDate - // - this.dtpFinishDate.CustomFormat = "dd-MMM-yyyy"; - this.dtpFinishDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpFinishDate.Location = new System.Drawing.Point(143, 15); - this.dtpFinishDate.Margin = new System.Windows.Forms.Padding(4); - this.dtpFinishDate.Name = "dtpFinishDate"; - this.dtpFinishDate.Size = new System.Drawing.Size(119, 22); - this.dtpFinishDate.TabIndex = 1; - // - // btnProcess - // - this.btnProcess.Location = new System.Drawing.Point(263, 445); - this.btnProcess.Margin = new System.Windows.Forms.Padding(4); - this.btnProcess.Name = "btnProcess"; - this.btnProcess.Size = new System.Drawing.Size(200, 28); - this.btnProcess.TabIndex = 25; - this.btnProcess.Text = "Process"; - this.btnProcess.UseVisualStyleBackColor = true; - this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click); - // - // MoveForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(479, 488); - this.Controls.Add(this.btnProcess); - this.Controls.Add(this.dtpFinishDate); - this.Controls.Add(this.btnGo); - this.Controls.Add(this.flpProducts); - this.Controls.Add(this.dtpStartDate); - this.Margin = new System.Windows.Forms.Padding(4); - this.MaximizeBox = false; - this.Name = "MoveForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sale Analysis Form"; - this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.DateTimePicker dtpStartDate; - private System.Windows.Forms.FlowLayoutPanel flpProducts; - private System.Windows.Forms.Button btnGo; - private System.Windows.Forms.DateTimePicker dtpFinishDate; - private System.Windows.Forms.Button btnProcess; - } -} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/NcForm.resx b/Tanshu.Accounts.PointOfSale/Management/NcForm.resx deleted file mode 100644 index 19dc0dd..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/NcForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/QuantityForm.cs b/Tanshu.Accounts.PointOfSale/Management/QuantityForm.cs deleted file mode 100644 index 48a0a17..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/QuantityForm.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Windows.Forms; -using Tanshu.Accounts.Repository; -using Tanshu.Accounts.Contracts; - -namespace Tanshu.Accounts.Management -{ - public partial class QuantityForm : Form - { - private IList textBoxes; - public QuantityForm() - { - InitializeComponent(); - } - - private void Sale_Analysis_Form_Load(object sender, EventArgs e) - { - dtpDate.Value = DateTime.Today; - - textBoxes = new List(); - for (int i = 0; i < 8; i++) - { - var text = ""; - switch (i) - { - case 0: - text = "1 - Dark"; - break; - case 1: - text = "2 - Wheat"; - break; - case 2: - text = "3 - Premium"; - break; - case 3: - text = "4 - Light"; - break; - case 4: - text = "5 - Dragon"; - break; - case 5: - text = "6 - Festival"; - break; - case 6: - text = "7 - Vanilla"; - break; - case 7: - text = "8 - Strong"; - break; - } - var label = new Label() - { - Name = "label" + (i + 1).ToString(CultureInfo.InvariantCulture), - AutoSize = true, - Text = text - }; - flpProducts.Controls.Add(label); - var textBox = new TextBox() - { - Name = "textBox" + (i + 1).ToString(CultureInfo.InvariantCulture), - Width = 400, - Height = 22, - Tag = new object[] { (i + 1), text } - }; - textBoxes.Add(textBox); - flpProducts.Controls.Add(textBox); - } - } - - private void btnGo_Click(object sender, EventArgs e) - { - foreach (var textBox in textBoxes) - { - var startDate = dtpDate.Value.Date.AddHours(7); - var finishDate = startDate.AddDays(1); - - var baseCode = (int)(((object[])textBox.Tag)[0]); - var text = (string)(((object[])textBox.Tag)[1]); - foreach (var item in textBox.Text.Split(',')) - { - var newQuantity = TryConvert(item); - var quantity = GetQuantity(baseCode, startDate, finishDate); - - if (MessageBox.Show(text + " " + startDate.ToString("dd-MMM-yyyy") + " " + quantity.ToString(), "Quantity of Beer", MessageBoxButtons.YesNo, - MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes && - quantity > newQuantity && newQuantity > 0) - { - MessageBox.Show(SetQuantity(baseCode, newQuantity, startDate, finishDate).ToString()); - } - startDate = startDate.AddDays(1); - finishDate = finishDate.AddDays(1); - } - } - } - private decimal TryConvert(string amount) - { - decimal result = 0; - decimal.TryParse(amount, out result); - return result; - } - private decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate) - { - using (var bi = new ManagementBI()) - return bi.GetQuantity(baseCode, startDate, finishDate); - } - private decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate) - { - using (var bi = new ManagementBI()) - return bi.SetQuantity(baseCode, quantity, startDate, finishDate); - } - - private void btnGetClipboard_Click(object sender, EventArgs e) - { - //Clipboard format -- Date,BaseCode,Quantity" - var fmtCsv = DataFormats.CommaSeparatedValue; - - // read the CSV - var dataobject = Clipboard.GetDataObject(); - if (dataobject == null) - { - MessageBox.Show(@"No Data in clipboard"); - return; - } - var stream = (System.IO.Stream)dataobject.GetData(fmtCsv); - var enc = new System.Text.UTF8Encoding(); - - IFormatProvider culture = new CultureInfo("en-US", true); - - using (var reader = new System.IO.StreamReader(stream, enc)) - { - using (var bi = new ManagementBI()) - { - string line; - while ((line = reader.ReadLine()) != null) - { - DateTime startDate; - int baseCode; - decimal quantity; - var data = line.Split(','); - if (!DateTime.TryParseExact(data[0], "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out startDate)) - continue; - var finishDate = startDate.AddDays(1).AddHours(7); - startDate = startDate.AddHours(7); - if (!int.TryParse(data[1], out baseCode)) - continue; - if (baseCode <= 0) - continue; - if (!decimal.TryParse(data[2], out quantity)) - continue; - - bi.SetQuantity(baseCode, quantity, startDate, finishDate); - } - } - } - } - } -} diff --git a/Tanshu.Accounts.PointOfSale/Management/QuantityForm.designer.cs b/Tanshu.Accounts.PointOfSale/Management/QuantityForm.designer.cs deleted file mode 100644 index 0bc740a..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/QuantityForm.designer.cs +++ /dev/null @@ -1,92 +0,0 @@ -namespace Tanshu.Accounts.Management -{ - partial class QuantityForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.dtpDate = new System.Windows.Forms.DateTimePicker(); - this.flpProducts = new System.Windows.Forms.FlowLayoutPanel(); - this.btnGo = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // dtpDate - // - this.dtpDate.CustomFormat = "dd-MMM-yyyy"; - this.dtpDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom; - this.dtpDate.Location = new System.Drawing.Point(16, 15); - this.dtpDate.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.dtpDate.Name = "dtpDate"; - this.dtpDate.Size = new System.Drawing.Size(119, 22); - this.dtpDate.TabIndex = 20; - // - // flpProducts - // - this.flpProducts.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.flpProducts.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - this.flpProducts.Location = new System.Drawing.Point(16, 47); - this.flpProducts.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.flpProducts.Name = "flpProducts"; - this.flpProducts.Size = new System.Drawing.Size(447, 390); - this.flpProducts.TabIndex = 23; - // - // btnGo - // - this.btnGo.Location = new System.Drawing.Point(16, 445); - this.btnGo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.btnGo.Name = "btnGo"; - this.btnGo.Size = new System.Drawing.Size(200, 28); - this.btnGo.TabIndex = 24; - this.btnGo.Text = "Go"; - this.btnGo.UseVisualStyleBackColor = true; - this.btnGo.Click += new System.EventHandler(this.btnGo_Click); - // - // QuantityForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(479, 488); - this.Controls.Add(this.btnGo); - this.Controls.Add(this.flpProducts); - this.Controls.Add(this.dtpDate); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.MaximizeBox = false; - this.Name = "QuantityForm"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Sale Analysis Form"; - this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.DateTimePicker dtpDate; - private System.Windows.Forms.FlowLayoutPanel flpProducts; - private System.Windows.Forms.Button btnGo; - } -} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/QuantityForm.resx b/Tanshu.Accounts.PointOfSale/Management/QuantityForm.resx deleted file mode 100644 index 19dc0dd..0000000 --- a/Tanshu.Accounts.PointOfSale/Management/QuantityForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Reports/SaleDetail.cs b/Tanshu.Accounts.PointOfSale/Reports/SaleDetail.cs index 2c8739f..804bc37 100644 --- a/Tanshu.Accounts.PointOfSale/Reports/SaleDetail.cs +++ b/Tanshu.Accounts.PointOfSale/Reports/SaleDetail.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.Windows.Forms; using Tanshu.Accounts.Repository; using Tanshu.Accounts.Contracts; -using Tanshu.Accounts.Helpers; -using System.Linq; namespace Tanshu.Accounts.PointOfSale { diff --git a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj index 0934975..ad31daa 100644 --- a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj +++ b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj @@ -126,29 +126,11 @@ CurrencyCounter.cs - + Form - - AmountForm.cs - - - Form - - - MoveForm.cs - - - Form - - - FoodForm.cs - - - Form - - - QuantityForm.cs + + ManagementForm.cs Form @@ -311,17 +293,8 @@ CurrencyCounter.cs - - AmountForm.cs - - - MoveForm.cs - - - FoodForm.cs - - - QuantityForm.cs + + ManagementForm.cs ProductListForm.cs diff --git a/Tanshu.Accounts.Repository/BusinessLayer/InventoryBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/InventoryBI.cs index 831fe68..890234b 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/InventoryBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/InventoryBI.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; -using Tanshu.Accounts.Contracts; -using Tanshu.Accounts.Entities; +using Tanshu.Accounts.Entities; using NHibernate; namespace Tanshu.Accounts.Repository diff --git a/Tanshu.Accounts.Repository/BusinessLayer/ManagementBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/ManagementBI.cs index 755da59..0d2243c 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/ManagementBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/ManagementBI.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using NHibernate; using Tanshu.Accounts.Entities; +using Tanshu.Common.Helpers; namespace Tanshu.Accounts.Repository { @@ -24,31 +25,418 @@ namespace Tanshu.Accounts.Repository public ManagementBI(ISession session, bool beginTransaction) : base(session, beginTransaction) { } + #region Cleanup + public void DeleteVoid(DateTime startDate, DateTime finishDate) + { + IList list; + using (var bi = new VoucherBI(Session)) + { + list = bi.List(x => x.Date >= startDate && x.Date <= finishDate && x.Void); + } + foreach (var item in list) + { + using (var bi = new VoucherBI()) + { + using (var ri = new ReprintBI()) + { + ri.DeleteList(x => x.Voucher.VoucherID == item.VoucherID); + bi.Delete(item.VoucherID); + } + } + } + } + public void DeleteStaff(DateTime startDate, DateTime finishDate) + { + IList list; + using (var bi = new VoucherBI(Session)) + { + list = bi.List(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.Staff); + } + foreach (var item in list) + { + using (var bi = new VoucherBI()) + { + using (var ri = new ReprintBI()) + { + ri.DeleteList(x => x.Voucher.VoucherID == item.VoucherID); + bi.Delete(item.VoucherID); + } + } + } + } + public void SetPayments(DateTime startDate, DateTime finishDate) + { + using (var bi = new VoucherBI(Session)) + { + var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate); + foreach (var voucher in list) + { + var settlementType = SettleOption.Cash; + switch (voucher.VoucherType) + { + case VoucherType.NoCharge: + settlementType = SettleOption.NoCharge; + break; + case VoucherType.Staff: + settlementType = SettleOption.Staff; + break; + } + var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); + 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) + { + using (var bi = new VoucherBI(Session)) + { + var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate); + 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) + { + using (var bi = new VoucherBI(Session)) + { + var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate); + 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) + { + using (var bi = new VoucherBI(Session)) + { + var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate); + 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); + } + } + } - public decimal GetFood(int vatID, DateTime startDate, DateTime finishDate) + public void FinalSanction(DateTime startDate, DateTime finishDate) + { + var query = @" +select 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 + "; + var lastBill = Session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("nc", VoucherType.NoCharge) + .SetParameter("staff", VoucherType.Staff) + .SetMaxResults(1) + .UniqueResult(); + var newID = lastBill == null ? "01-0001" : GetNewID((string)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(); + foreach (var voucher in list) + { + if (voucher.BillID != newID) + { + voucher.SetValue(VoucherFields.BillID, newID); + Session.Update(voucher); + } + newID = GetNewID(newID); + } + + query = @" +select v.BillID +from Voucher v +where v.Date < :startDate and v.Void = false and v.VoucherType = :nc +order by v.Date desc + "; + lastBill = Session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("nc", VoucherType.NoCharge) + .SetMaxResults(1) + .UniqueResult(); + newID = lastBill == null ? "NC-1" : GetNewNc((string)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(); + foreach (var voucher in list) + { + if (voucher.BillID != newID) + { + voucher.SetValue(VoucherFields.BillID, newID); + Session.Update(voucher); + } + newID = GetNewNc(newID); + } + } + + private static string GetNewNc(string lastBill) + { + var parts = lastBill.Split('-'); + if (parts.Length != 2) + throw new ArgumentOutOfRangeException(); + int one; + if (parts[0] != "NC") + throw new ArgumentOutOfRangeException(); + if (!int.TryParse(parts[1], out one)) + throw new ArgumentOutOfRangeException(); + one += 1; + return string.Format("NC-{0}", one); + } + + private static string GetNewID(string lastBill) + { + var parts = lastBill.Split('-'); + if (parts.Length != 2) + throw new ArgumentOutOfRangeException(); + int one, two; + if (!int.TryParse(parts[0], out one)) + throw new ArgumentOutOfRangeException(); + if (!int.TryParse(parts[1], out two)) + throw new ArgumentOutOfRangeException(); + if (two >= 9999) + { + one += 1; + two = 1; + } + else + { + two += 1; + } + return string.Format("{0:00}-{1:0000}", one, two); + } + + #endregion + public void MoveNc(DateTime startDate, DateTime finishDate, decimal target) + { + const 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) +group by v.VoucherID +order by sum(i.Amount) desc + "; + var list = Session + .CreateQuery(query) + .SetParameter("startDate", startDate.AddHours(7)) + .SetParameter("finishDate", finishDate.AddDays(1).AddHours(7)) + .SetParameter("nc", VoucherType.NoCharge) + .SetParameter("staff", VoucherType.Staff) + .List(); + var totalAmount = GetFood(.1575M, startDate, finishDate) + GetFood(.2625M, startDate, finishDate); + var skip = false; + for (int i = 0; i < list.Count / 20; i++) + { + if (target / totalAmount > .75M) + break; + skip = !skip; + if (skip) + continue; + var item = (object[])list[i]; + var voucherID = (int)item[0]; + var amount = (decimal)item[1]; + using (var bi = new VoucherBI(Session)) + { + var voucher = bi.Get(x => x.VoucherID == voucherID); + voucher.VoucherType = VoucherType.NoCharge; + Session.Update(voucher); + } + totalAmount -= amount; + } + } + public Dictionary GetLiq(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 -inner join i.Product p -where v.Date >= :startDate and v.Date <= :finishDate and p.Vat.TaxID = :vatID and v.Void = false and v.VoucherType not in (:nc, :staff) +where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat 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("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 .CreateQuery(query) .SetParameter("startDate", startDate) .SetParameter("finishDate", finishDate) - .SetParameter("vatID", vatID) + .SetParameter("vat", vat) .SetParameter("nc", VoucherType.NoCharge) .SetParameter("staff", VoucherType.Staff) .UniqueResult(); return qty == null ? 0 : (decimal)qty; } - public decimal SetFood(int vatID, decimal amount, DateTime startDate, DateTime finishDate) + + 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 +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 qty = Session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("nc", VoucherType.NoCharge) + .SetParameter("staff", VoucherType.Staff) + .UniqueResult(); + return qty == null ? 0 : (decimal)qty; + } + public string GetFirstBill(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) +order by v.Date + "; + 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) + .SetMaxResults(1) + .UniqueResult(); + return qty == null ? "" : (string)qty; + } + + public string 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) +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) + .SetMaxResults(1) + .UniqueResult(); + return qty == null ? "" : (string)qty; + } + + public decimal GetFood(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) + "; + var qty = 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; + } + public decimal SetFood(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) { 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; + var left = GetFood(vat, startDate, finishDate) - amount; foreach (var item in list) { if (left <= 0) @@ -61,7 +449,7 @@ where v.Date >= :startDate and v.Date <= :finishDate and p.Vat.TaxID = :vatID an { if (left <= 0) break; - if (inventory.Product.Vat.TaxID == vatID) + if (inventory.Vat == vat) { using (var bi = new InventoryBI()) { @@ -85,7 +473,63 @@ where v.Date >= :startDate and v.Date <= :finishDate and p.Vat.TaxID = :vatID an } } } - return GetFood(vatID, startDate, finishDate); + return GetFood(vat, startDate, finishDate); + } + + public decimal SetLiq(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) + { + var rand = 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(vat, startDate, finishDate) - amount; + foreach (var item in list) + { + 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.Vat == vat) + { + using (var bi = new InventoryBI()) + { + 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); + + if (reduction > left) + { + discount = inventory.Quantity * inventory.Price * + (1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)); + discount = left / discount; + var i = bi.Get(x => x.InventoryID == inventory.InventoryID); + i.Discount = discount; + 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(vat, startDate, finishDate); } public decimal SetAmount(int vatID, decimal amount, DateTime startDate, DateTime finishDate) @@ -181,7 +625,9 @@ order by p.BaseCode return list; } - public decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate) + + #region Beer + public decimal GetQuantity(DateTime startDate, DateTime finishDate) { const string query = @" select sum(i.Quantity * p.Quantity) as Quantity @@ -189,20 +635,19 @@ 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 = :baseCode +where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Quantity != 0 "; var qty = Session .CreateQuery(query) .SetParameter("startDate", startDate) .SetParameter("finishDate", finishDate) - .SetParameter("baseCode", baseCode) .UniqueResult(); return qty == null ? 0 : (decimal)qty; } - public decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate) + public decimal SetQuantity(DateTime startDate, DateTime finishDate, decimal quantity) { 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 = GetQuantity(startDate, finishDate) - quantity; foreach (var item in list) { if (left <= 0) @@ -215,7 +660,7 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Ba { if (left <= 0) break; - if (inventory.Product.BaseCode == baseCode) + if (inventory.Product.Quantity != 0) { using (var bi = new InventoryBI()) { @@ -239,105 +684,10 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Ba } } } - return GetQuantity(baseCode, startDate, finishDate); - } - public void SetMove(int fromBaseCode, int toBaseCode, DateTime startDate, DateTime finishDate) - { - var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate)); - using (var bi = new InventoryBI()) - { - using (var pbi = new ProductBI()) - { - foreach (var item in list) - { - foreach (var kot in item.Kots) - { - foreach (var inventory in kot.Inventories) - { - if (inventory.Product.BaseCode == fromBaseCode) - { - var i = bi.Get(x => x.InventoryID == inventory.InventoryID); - i.Product = pbi.Get(x => x.ProductID == GetNewID(i.Product.ProductID, toBaseCode)); - GetNewID(i.InventoryID, toBaseCode); - bi.Update(i); - } - } - } - } - } - } - } - private static int GetNewID(int code, int toBaseCode) - { - // Name Mug, Pit, H H - // Dark 301, 305, 384 // BaseCode = 1 - // Wheat 300, 304, 383 // BaseCode = 2 - // Premium 299, 303, 382 // BaseCode = 3 - // Light 297, 302, 363 // BaseCode = 4 - // Dragon 677, 679, 678 // BaseCode = 5 - // Festival 409 // BaseCode = 6 - // Vanilla 408, 587 // BaseCode = 7 - // Strong 697, 708, 707 // BaseCode = 8 - if (code == 301 || code == 300 || code == 299 || code == 297 || code == 677 || code == 408 || code == 697) - { - if (toBaseCode == 1) - return 301; - if (toBaseCode == 2) - return 300; - if (toBaseCode == 3) - return 299; - if (toBaseCode == 4) - return 297; - if (toBaseCode == 5) - return 677; - if (toBaseCode == 6) - return code; - if (toBaseCode == 7) - return 408; - if (toBaseCode == 8) - return 697; - } - if (code == 305 || code == 304 || code == 303 || code == 302 || code == 679 || code == 409 || code == 708) - { - if (toBaseCode == 1) - return 305; - if (toBaseCode == 2) - return 304; - if (toBaseCode == 3) - return 303; - if (toBaseCode == 4) - return 302; - if (toBaseCode == 5) - return 679; - if (toBaseCode == 6) - return 409; - if (toBaseCode == 7) - return code; - if (toBaseCode == 8) - return 708; - } - if (code == 384 || code == 383 || code == 382 || code == 363 || code == 678 || code == 587 || code == 707) - { - if (toBaseCode == 1) - return 384; - if (toBaseCode == 2) - return 383; - if (toBaseCode == 3) - return 382; - if (toBaseCode == 4) - return 363; - if (toBaseCode == 5) - return 678; - if (toBaseCode == 6) - return code; - if (toBaseCode == 7) - return 587; - if (toBaseCode == 8) - return 707; - } - - return code; + return GetQuantity(startDate, finishDate); } + #endregion + #region Helper and Comments private static IList Randomize(IEnumerable list) { var tList = list.ToArray(); @@ -351,5 +701,162 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Ba } return tList.ToList(); } + // public decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate) + // { + // const string query = @" + //select 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 = :baseCode + // "; + // var qty = Session + // .CreateQuery(query) + // .SetParameter("startDate", startDate) + // .SetParameter("finishDate", finishDate) + // .SetParameter("baseCode", baseCode) + // .UniqueResult(); + // return qty == null ? 0 : (decimal)qty; + // } + // 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; + // foreach (var item in list) + // { + // 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.BaseCode == baseCode) + // { + // using (var bi = new InventoryBI()) + // { + // var inventoryQuantity = inventory.Quantity * inventory.Product.Quantity; + + // if (inventoryQuantity > left) + // { + // var newQuantity = inventory.Quantity * (inventoryQuantity - left) / inventoryQuantity; + // var i = bi.Get(x => x.InventoryID == inventory.InventoryID); + // i.Quantity = newQuantity; + // bi.Update(i); + // left = 0; + // } + // else + // { + // left -= inventoryQuantity; + // bi.Delete(x => x.InventoryID == inventory.InventoryID); + // } + // } + // } + // } + // } + // } + // return GetQuantity(baseCode, startDate, finishDate); + // } + //private static int GetNewID(int code, int toBaseCode) + //{ + // // Name Mug, Pit, H H + // // Dark 301, 305, 384 // BaseCode = 1 + // // Wheat 300, 304, 383 // BaseCode = 2 + // // Premium 299, 303, 382 // BaseCode = 3 + // // Light 297, 302, 363 // BaseCode = 4 + // // Dragon 677, 679, 678 // BaseCode = 5 + // // Festivals 762 764, 752 // BaseCode = 6 + // // Festivals 751, 753, 763 // BaseCode = 6 + // // Festivals 734, 736, 587 // BaseCode = 6 + // // Festivals 408, 409, 735 // BaseCode = 6 + // // Strong 697, 708, 707 // BaseCode = 7 + // var list = new List { 301, 300, 299, 297, 677, 762, 751, 734, 408, 697 }; + // if (list.Contains(code)) + // { + // if (toBaseCode == 1) + // return 301; + // if (toBaseCode == 2) + // return 300; + // if (toBaseCode == 3) + // return 299; + // if (toBaseCode == 4) + // return 297; + // if (toBaseCode == 5) + // return 677; + // if (toBaseCode == 6) + // return code; + // if (toBaseCode == 7) + // return 697; + // } + // list = new List { 305, 304, 303, 302, 679, 764, 753, 736, 409, 708 }; + // if (list.Contains(code)) + // { + // if (toBaseCode == 1) + // return 305; + // if (toBaseCode == 2) + // return 304; + // if (toBaseCode == 3) + // return 303; + // if (toBaseCode == 4) + // return 302; + // if (toBaseCode == 5) + // return 679; + // if (toBaseCode == 6) + // return code; + // if (toBaseCode == 7) + // return 708; + // } + // list = new List { 384, 383, 382, 363, 678, 752, 763, 587, 735, 707 }; + // if (list.Contains(code)) + // { + // if (toBaseCode == 1) + // return 384; + // if (toBaseCode == 2) + // return 383; + // if (toBaseCode == 3) + // return 382; + // if (toBaseCode == 4) + // return 363; + // if (toBaseCode == 5) + // return 678; + // if (toBaseCode == 6) + // return code; + // if (toBaseCode == 7) + // return 707; + // } + + // return code; + //} + //public void SetMove(int fromBaseCode, int toBaseCode, DateTime startDate, DateTime finishDate) + //{ + // var list = new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate); + // using (var bi = new InventoryBI()) + // { + // using (var pbi = new ProductBI()) + // { + // foreach (var item in list) + // { + // foreach (var kot in item.Kots) + // { + // foreach (var inventory in kot.Inventories) + // { + // if (inventory.Product.BaseCode == fromBaseCode) + // { + // var i = bi.Get(x => x.InventoryID == inventory.InventoryID); + // i.Product = pbi.Get(x => x.ProductID == GetNewID(i.Product.ProductID, toBaseCode)); + // GetNewID(i.InventoryID, toBaseCode); + // bi.Update(i); + // } + // } + // } + // } + // } + // } + //} + #endregion } } \ No newline at end of file diff --git a/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs index c3cdf1d..3183cfd 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs @@ -71,7 +71,7 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units) else outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], NC = (decimal)item[1] }); #endregion - #region NC + #region Staff query = @" select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount from Voucher v diff --git a/Tanshu.Accounts.Repository/Fluent/SetupStore.cs b/Tanshu.Accounts.Repository/Fluent/SetupStore.cs index 45b3b6e..bbd8028 100644 --- a/Tanshu.Accounts.Repository/Fluent/SetupStore.cs +++ b/Tanshu.Accounts.Repository/Fluent/SetupStore.cs @@ -1,4 +1,5 @@ -using FluentNHibernate.Automapping; +using System; +using FluentNHibernate.Automapping; using FluentNHibernate.Cfg; using FluentNHibernate.Cfg.Db; using NHibernate; @@ -60,14 +61,20 @@ namespace Tanshu.Accounts.Repository c.Add(); c.Add(); c.Add(); - c.Add(); + c.Add(); }); return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(p => p.FromConnectionStringWithKey("FluentCon"))) .Mappings(m => m.AutoMappings.Add(persistenceModel)) - .BuildConfiguration() - .SetInterceptor(new NHSQLInterceptor()); + .ExposeConfiguration(cfg => ApplyAdditionalConfiguration(cfg)) + .BuildConfiguration(); + //.SetInterceptor(new NHSQLInterceptor()); + } + private static void ApplyAdditionalConfiguration(Configuration cfg) + { + var timeout = TimeSpan.FromMinutes(10).TotalSeconds; + cfg.SetProperty("command_timeout", timeout.ToString()); } private void Init() { }