From caf9b3106c209b9410ba7a3f4d9c01af91980fe2 Mon Sep 17 00:00:00 2001 From: tanshu Date: Mon, 4 Jan 2016 10:52:01 +0530 Subject: [PATCH] Feature: Added Machine Locations so that setting the location in the config file is not needed. Feature: Settings database table added to store string based settings. It is right now used to store bill header and footer. Hard Coded header/footer removed from file. Feature: Tax Analysis form created to easily show the tax calculation. Feature: Management form uses background workers. Dont' know if it is functional though. Chore: Reorder Table form moved to masters from sales folder. Refactor: ManagementBI and SalesAnalysisBI --- Sql/2014.12.19 Add Machine Location.sql | 9 + ...14.12.20 UpdateBillID Stored Procedure.sql | 7 + ...01.01 Bill header and footer in the DB.sql | 27 ++ .../Data Contracts Display/SalesAnalysisBO.cs | 8 + .../Data Contracts/MachineLocationBO.cs | 26 ++ .../Data Contracts/SettingBO.cs | 29 ++ .../Tanshu.Accounts.Contracts.csproj | 2 + Tanshu.Accounts.PointOfSale/MainForm.cs | 46 +- .../MainForm.designer.cs | 118 +++-- .../Management/ManagementForm.cs | 415 +++++++++++------- .../Management/ManagementForm.designer.cs | 9 - .../Management/ManagementForm.resx | 3 - .../Masters/MachineEditForm.Designer.cs | 136 ++++++ .../Masters/MachineEditForm.cs | 89 ++++ .../Masters/MachineEditForm.resx | 123 ++++++ .../Masters/MachineListForm.Designer.cs | 152 +++++++ .../Masters/MachineListForm.cs | 53 +++ .../Masters/MachineListForm.resx | 126 ++++++ .../ReorderTableForm.Designer.cs | 0 .../{Sales => Masters}/ReorderTableForm.cs | 0 .../{Sales => Masters}/ReorderTableForm.resx | 0 .../Products/ModifierListForm.Designer.cs | 2 +- .../Products/ModifierListForm.cs | 2 +- .../Profiling/BlockTimer.cs | 25 -- .../Reports/SaleAnalysisForm.cs | 32 +- .../Reports/TaxAnalysisForm.cs | 82 ++++ .../Reports/TaxAnalysisForm.designer.cs | 128 ++++++ .../Reports/TaxAnalysisForm.resx | 120 +++++ .../Tanshu.Accounts.PointOfSale.csproj | 37 +- Tanshu.Accounts.Print/ThermalBill.cs | 13 +- Tanshu.Accounts.Repository/Cache.cs | 133 +++--- .../MachineLocationBI.cs | 17 + Tanshu.Accounts.Repository/ManagementBI.cs | 319 ++++++++------ Tanshu.Accounts.Repository/SalesAnalysisBI.cs | 96 ++-- Tanshu.Accounts.Repository/SettingBI.cs | 10 + Tanshu.Accounts.Repository/SetupStore.cs | 4 +- .../Tanshu.Accounts.Repository.csproj | 2 + 37 files changed, 1893 insertions(+), 507 deletions(-) create mode 100644 Sql/2014.12.19 Add Machine Location.sql create mode 100644 Sql/2014.12.20 UpdateBillID Stored Procedure.sql create mode 100644 Sql/2016.01.01 Bill header and footer in the DB.sql create mode 100644 Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs create mode 100644 Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs create mode 100644 Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.Designer.cs create mode 100644 Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs create mode 100644 Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.resx create mode 100644 Tanshu.Accounts.PointOfSale/Masters/MachineListForm.Designer.cs create mode 100644 Tanshu.Accounts.PointOfSale/Masters/MachineListForm.cs create mode 100644 Tanshu.Accounts.PointOfSale/Masters/MachineListForm.resx rename Tanshu.Accounts.PointOfSale/{Sales => Masters}/ReorderTableForm.Designer.cs (100%) rename Tanshu.Accounts.PointOfSale/{Sales => Masters}/ReorderTableForm.cs (100%) rename Tanshu.Accounts.PointOfSale/{Sales => Masters}/ReorderTableForm.resx (100%) delete mode 100644 Tanshu.Accounts.PointOfSale/Profiling/BlockTimer.cs create mode 100644 Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.cs create mode 100644 Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.designer.cs create mode 100644 Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.resx create mode 100644 Tanshu.Accounts.Repository/MachineLocationBI.cs create mode 100644 Tanshu.Accounts.Repository/SettingBI.cs diff --git a/Sql/2014.12.19 Add Machine Location.sql b/Sql/2014.12.19 Add Machine Location.sql new file mode 100644 index 0000000..99417a3 --- /dev/null +++ b/Sql/2014.12.19 Add Machine Location.sql @@ -0,0 +1,9 @@ +BEGIN TRANSACTION +CREATE TABLE dbo.MachineLocations ( + MachineLocationID uniqueidentifier PRIMARY KEY NOT NULL, + Machine nvarchar(50) NOT NULL, + Location nvarchar(50) NOT NULL, + CONSTRAINT IX_MachineLocations UNIQUE(Machine)); +GO +INSERT INTO Auth_Roles (RoleID, Name) VALUES ('f12b573f-edcb-490d-91c3-fa76f6502ffd', 'Machines'); +COMMIT \ No newline at end of file diff --git a/Sql/2014.12.20 UpdateBillID Stored Procedure.sql b/Sql/2014.12.20 UpdateBillID Stored Procedure.sql new file mode 100644 index 0000000..9c6871c --- /dev/null +++ b/Sql/2014.12.20 UpdateBillID Stored Procedure.sql @@ -0,0 +1,7 @@ +CREATE PROCEDURE UpdateBillID +@VoucherID uniqueidentifier, +@BillID int +AS +BEGIN + UPDATE Vouchers SET BillID = @BillID WHERE VoucherID = @VoucherID; +END diff --git a/Sql/2016.01.01 Bill header and footer in the DB.sql b/Sql/2016.01.01 Bill header and footer in the DB.sql new file mode 100644 index 0000000..b9d3791 --- /dev/null +++ b/Sql/2016.01.01 Bill header and footer in the DB.sql @@ -0,0 +1,27 @@ +BEGIN TRANSACTION +GO +CREATE TABLE dbo.Settings + ( SettingID uniqueidentifier NOT NULL, + Name nvarchar(255) NOT NULL, + Details nvarchar(MAX) NOT NULL + ) ON [PRIMARY] + TEXTIMAGE_ON [PRIMARY] +GO +ALTER TABLE dbo.Settings ADD CONSTRAINT PK_Settings PRIMARY KEY (SettingID) +GO +CREATE UNIQUE INDEX IX_Settings ON dbo.Settings (Name) +GO +INSERT INTO Settings (SettingID, Name, Details) +VALUES ('FB738BA2-A3C9-40ED-891C-B930E6454974', 'Header', +' Hops n Grains' + CHAR(13) + CHAR(10) + +' The Microbrewery' + CHAR(13) + CHAR(10) + +' SCO 358, Sector 9, Panchkula' + CHAR(13) + CHAR(10) + +' A Unit of Peitho Foods Pvt. Ltd.' + CHAR(13) + CHAR(10) + +' CIN: U15139CH2010PTC032202' + CHAR(13) + CHAR(10) + +'(Reg Add: Plot No. 907, Indl Area II, Chd)' + CHAR(13) + CHAR(10) + +' TIN: 06592507323' + CHAR(13) + CHAR(10) + +' Service Tax: AAFCP5097GSD001' + CHAR(13) + CHAR(10)) +GO +INSERT INTO Settings (SettingID, Name, Details) VALUES ('F7799871-D16E-4C4D-9B57-2299A5839ACB', 'Footer','Call: 0172-4026666, 8054923853, 8054923856') +GO +COMMIT \ No newline at end of file diff --git a/Tanshu.Accounts.Contracts/Data Contracts Display/SalesAnalysisBO.cs b/Tanshu.Accounts.Contracts/Data Contracts Display/SalesAnalysisBO.cs index a4e13a6..7ed60c6 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts Display/SalesAnalysisBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts Display/SalesAnalysisBO.cs @@ -9,6 +9,14 @@ namespace Tanshu.Accounts.Contracts public virtual decimal Amount { get; set; } } + public class TaxAnalysis + { + public virtual string Name { get; set; } + public virtual decimal TaxRate { get; set; } + public virtual decimal NetSale { get; set; } + public virtual decimal TaxAmount { get; set; } + } + public class SalesAnalysisDetail { public virtual string Product { get; set; } diff --git a/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs new file mode 100644 index 0000000..588f26b --- /dev/null +++ b/Tanshu.Accounts.Contracts/Data Contracts/MachineLocationBO.cs @@ -0,0 +1,26 @@ +using System; +using System.Runtime.Serialization; +using NHibernate.Mapping.ByCode.Conformist; +using NHibernate.Mapping.ByCode; + +namespace Tanshu.Accounts.Entities +{ + public class MachineLocation + { + public virtual Guid MachineLocationID { get; set; } + public virtual string Machine { get; set; } + public virtual string Location { get; set; } + } + public class MachineLocationMap : ClassMapping + { + public MachineLocationMap() + { + Table("MachineLocations"); + Schema("dbo"); + Lazy(true); + Id(x => x.MachineLocationID, map => map.Generator(Generators.GuidComb)); + Property(x => x.Machine, map => { map.Unique(true); map.NotNullable(true); }); + Property(x => x.Location, map => map.NotNullable(true)); + } + } +} diff --git a/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs new file mode 100644 index 0000000..13e254a --- /dev/null +++ b/Tanshu.Accounts.Contracts/Data Contracts/SettingBO.cs @@ -0,0 +1,29 @@ +using System; +using System.Runtime.Serialization; +using Tanshu.Accounts.Contracts; +using NHibernate.Mapping.ByCode.Conformist; +using NHibernate.Mapping.ByCode; +using System.Collections.Generic; + +namespace Tanshu.Accounts.Entities +{ + public class Setting + { + public virtual Guid SettingID { get; set; } + public virtual string Name { get; set; } + public virtual string Details { get; set; } + } + public class SettingMap : ClassMapping + { + + public SettingMap() + { + Table("Settings"); + Schema("dbo"); + Lazy(false); + Id(x => x.SettingID, map => map.Generator(Generators.GuidComb)); + Property(x => x.Name, map => { map.NotNullable(true); map.Unique(true); }); + Property(x => x.Details, map => map.NotNullable(true)); + } + } +} diff --git a/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj b/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj index 8f655e3..ad9a2a6 100644 --- a/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj +++ b/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj @@ -65,6 +65,8 @@ + + diff --git a/Tanshu.Accounts.PointOfSale/MainForm.cs b/Tanshu.Accounts.PointOfSale/MainForm.cs index f8fd1e1..c442916 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.cs @@ -1,4 +1,5 @@ using System; +using System.Linq.Expressions; using System.Text.RegularExpressions; using System.Windows.Forms; using Tanshu.Accounts.Contracts; @@ -10,9 +11,6 @@ using Tanshu.Accounts.PointOfSale.Sales; using Tanshu.Accounts.Repository; using Tanshu.Common; using Tanshu.Common.KeyboardControl; -using NHibernate.Tool.hbm2ddl; -using System.Collections.Generic; -using System.Linq.Expressions; namespace Tanshu.Accounts.PointOfSale { @@ -20,12 +18,10 @@ namespace Tanshu.Accounts.PointOfSale { public MainForm() { - //using (var frm = new SplashForm()) - // frm.ShowDialog(); - SessionManager.Initialize(); //new SchemaExport(SessionManager.Configuration).Create(false, true); InitializeComponent(); + Text = "Point of Sale: Login (" + Environment.MachineName + ")"; } private User form_userEvent(object sender, UserEventArgs e) @@ -56,7 +52,6 @@ namespace Tanshu.Accounts.PointOfSale frmSale.ShowDialog(); Cache.Invalidate(); } - } private void btnProduct_Click(object sender, EventArgs e) @@ -136,9 +131,24 @@ namespace Tanshu.Accounts.PointOfSale #if (DEBUG) MessageBox.Show("This software does not print kots!!!", "Debug Mode", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); #endif + CheckMachine(); CheckRoles(); } + private void CheckMachine() + { + if (string.IsNullOrEmpty(Cache.Location)) + { + MessageBox.Show("No Machine Location"); + using (var frm = new MachineEditForm(Environment.MachineName)) + frm.ShowDialog(); + if (string.IsNullOrEmpty(Cache.Location)) + { + MessageBox.Show("Machine Location not set"); + Close(); + } + } + } private void CheckRoles() { btnSale.Visible = Session.IsAllowed("Sales"); @@ -147,6 +157,7 @@ namespace Tanshu.Accounts.PointOfSale btnProductGroup.Visible = Session.IsAllowed("Products"); btnModifiers.Visible = Session.IsAllowed("Modifiers"); btnReorderTables.Visible = Session.IsAllowed("Tables"); + btnMachines.Visible = Session.IsAllowed("Machines"); btnOpenBill.Visible = Session.IsAllowed("Open Bill"); @@ -159,6 +170,7 @@ namespace Tanshu.Accounts.PointOfSale btnCashierCheckout.Visible = Session.IsAllowed("Cashier Checkout"); btnSaleAnalysis.Visible = Session.IsAllowed("Sales Analysis"); + btnTaxAnalysis.Visible = Session.IsAllowed("Tax Analysis"); btnSaleDetail.Visible = Session.IsAllowed("Sales Detail"); btnBillDetails.Visible = Session.IsAllowed("Bill Details"); @@ -191,7 +203,7 @@ namespace Tanshu.Accounts.PointOfSale { if (login.LoginUser()) { - Text = "Main Menu - User: " + Session.User.Name; + Text = "Point of Sale: " + Session.User.Name + " (" + Environment.MachineName + ")"; btnLogin.Text = "Logout"; btnSwipeLogin.Visible = false; } @@ -199,7 +211,7 @@ namespace Tanshu.Accounts.PointOfSale else { login.LogoutUser(); - Text = "Main Menu - Login"; + Text = "Point of Sale: Login (" + Environment.MachineName + ")"; btnLogin.Text = "Login"; btnSwipeLogin.Visible = true; } @@ -297,5 +309,21 @@ namespace Tanshu.Accounts.PointOfSale frm.ShowDialog(); } } + + private void btnMachines_Click(object sender, EventArgs e) + { + if (Session.IsAllowed("Machines")) + using (var frm = new MachineListForm()) + { + frm.ShowDialog(); + } + } + + private void btnTaxAnalysis_Click(object sender, EventArgs e) + { + if (Session.IsAllowed("Tax Analysis")) + using (var frm = new frmTaxAnalysisForm()) + frm.ShowDialog(); + } } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/MainForm.designer.cs b/Tanshu.Accounts.PointOfSale/MainForm.designer.cs index 07e4c05..04e99b7 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.designer.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.designer.cs @@ -36,6 +36,7 @@ this.btnProduct = new System.Windows.Forms.Button(); this.btnProductGroup = new System.Windows.Forms.Button(); this.btnReorderTables = new System.Windows.Forms.Button(); + this.btnMachines = new System.Windows.Forms.Button(); this.btnModifiers = new System.Windows.Forms.Button(); this.btnOpenBill = new System.Windows.Forms.Button(); this.btnCreateUser = new System.Windows.Forms.Button(); @@ -43,13 +44,14 @@ this.btnGroupRoles = new System.Windows.Forms.Button(); this.btnCashierCheckout = new System.Windows.Forms.Button(); this.btnSaleAnalysis = new System.Windows.Forms.Button(); + this.btnTaxAnalysis = new System.Windows.Forms.Button(); this.btnSaleDetail = new System.Windows.Forms.Button(); this.btnBillDetails = new System.Windows.Forms.Button(); this.btnVoidOrReprints = new System.Windows.Forms.Button(); this.btnDiscountReport = new System.Windows.Forms.Button(); this.btnChangePassword = new System.Windows.Forms.Button(); - this.btnExit = new System.Windows.Forms.Button(); this.btnManagement = new System.Windows.Forms.Button(); + this.btnExit = new System.Windows.Forms.Button(); this.flowLayoutPanel1.SuspendLayout(); this.SuspendLayout(); // @@ -82,6 +84,7 @@ this.flowLayoutPanel1.Controls.Add(this.btnProduct); this.flowLayoutPanel1.Controls.Add(this.btnProductGroup); this.flowLayoutPanel1.Controls.Add(this.btnReorderTables); + this.flowLayoutPanel1.Controls.Add(this.btnMachines); this.flowLayoutPanel1.Controls.Add(this.btnModifiers); this.flowLayoutPanel1.Controls.Add(this.btnOpenBill); this.flowLayoutPanel1.Controls.Add(this.btnCreateUser); @@ -89,13 +92,14 @@ this.flowLayoutPanel1.Controls.Add(this.btnGroupRoles); this.flowLayoutPanel1.Controls.Add(this.btnCashierCheckout); this.flowLayoutPanel1.Controls.Add(this.btnSaleAnalysis); + this.flowLayoutPanel1.Controls.Add(this.btnTaxAnalysis); this.flowLayoutPanel1.Controls.Add(this.btnSaleDetail); this.flowLayoutPanel1.Controls.Add(this.btnBillDetails); this.flowLayoutPanel1.Controls.Add(this.btnVoidOrReprints); this.flowLayoutPanel1.Controls.Add(this.btnDiscountReport); this.flowLayoutPanel1.Controls.Add(this.btnChangePassword); - this.flowLayoutPanel1.Controls.Add(this.btnExit); this.flowLayoutPanel1.Controls.Add(this.btnManagement); + this.flowLayoutPanel1.Controls.Add(this.btnExit); this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; @@ -152,146 +156,166 @@ this.btnReorderTables.UseVisualStyleBackColor = true; this.btnReorderTables.Click += new System.EventHandler(this.btnReorderTables_Click); // + // btnMachines + // + this.btnMachines.Location = new System.Drawing.Point(315, 109); + this.btnMachines.Name = "btnMachines"; + this.btnMachines.Size = new System.Drawing.Size(150, 100); + this.btnMachines.TabIndex = 7; + this.btnMachines.Text = "Manage Machines"; + this.btnMachines.UseVisualStyleBackColor = true; + this.btnMachines.Click += new System.EventHandler(this.btnMachines_Click); + // // btnModifiers // - this.btnModifiers.Location = new System.Drawing.Point(315, 109); + this.btnModifiers.Location = new System.Drawing.Point(471, 109); this.btnModifiers.Name = "btnModifiers"; this.btnModifiers.Size = new System.Drawing.Size(150, 100); - this.btnModifiers.TabIndex = 7; + this.btnModifiers.TabIndex = 8; this.btnModifiers.Text = "Product Modifiers"; this.btnModifiers.UseVisualStyleBackColor = true; this.btnModifiers.Click += new System.EventHandler(this.btnModifiers_Click); // // btnOpenBill // - this.btnOpenBill.Location = new System.Drawing.Point(471, 109); + this.btnOpenBill.Location = new System.Drawing.Point(627, 109); this.btnOpenBill.Name = "btnOpenBill"; this.btnOpenBill.Size = new System.Drawing.Size(150, 100); - this.btnOpenBill.TabIndex = 8; + this.btnOpenBill.TabIndex = 9; this.btnOpenBill.Text = "Open Bill"; this.btnOpenBill.UseVisualStyleBackColor = true; this.btnOpenBill.Click += new System.EventHandler(this.btnOpenBill_Click); // // btnCreateUser // - this.btnCreateUser.Location = new System.Drawing.Point(627, 109); + this.btnCreateUser.Location = new System.Drawing.Point(3, 215); this.btnCreateUser.Name = "btnCreateUser"; this.btnCreateUser.Size = new System.Drawing.Size(150, 100); - this.btnCreateUser.TabIndex = 9; + this.btnCreateUser.TabIndex = 10; this.btnCreateUser.Text = "Create User"; this.btnCreateUser.UseVisualStyleBackColor = true; this.btnCreateUser.Click += new System.EventHandler(this.btnCreateUser_Click); // // btnUserRoles // - this.btnUserRoles.Location = new System.Drawing.Point(3, 215); + this.btnUserRoles.Location = new System.Drawing.Point(159, 215); this.btnUserRoles.Name = "btnUserRoles"; this.btnUserRoles.Size = new System.Drawing.Size(150, 100); - this.btnUserRoles.TabIndex = 10; + this.btnUserRoles.TabIndex = 11; this.btnUserRoles.Text = "Manage User Roles"; this.btnUserRoles.UseVisualStyleBackColor = true; this.btnUserRoles.Click += new System.EventHandler(this.btnUserRoles_Click); // // btnGroupRoles // - this.btnGroupRoles.Location = new System.Drawing.Point(159, 215); + this.btnGroupRoles.Location = new System.Drawing.Point(315, 215); this.btnGroupRoles.Name = "btnGroupRoles"; this.btnGroupRoles.Size = new System.Drawing.Size(150, 100); - this.btnGroupRoles.TabIndex = 11; + this.btnGroupRoles.TabIndex = 12; this.btnGroupRoles.Text = "Manage Group Roles"; this.btnGroupRoles.UseVisualStyleBackColor = true; this.btnGroupRoles.Click += new System.EventHandler(this.btnGroupRoles_Click); // // btnCashierCheckout // - this.btnCashierCheckout.Location = new System.Drawing.Point(315, 215); + this.btnCashierCheckout.Location = new System.Drawing.Point(471, 215); this.btnCashierCheckout.Name = "btnCashierCheckout"; this.btnCashierCheckout.Size = new System.Drawing.Size(150, 100); - this.btnCashierCheckout.TabIndex = 12; + this.btnCashierCheckout.TabIndex = 13; this.btnCashierCheckout.Text = "Cashier Checkout"; this.btnCashierCheckout.UseVisualStyleBackColor = true; this.btnCashierCheckout.Click += new System.EventHandler(this.btnCashierCheckout_Click); // // btnSaleAnalysis // - this.btnSaleAnalysis.Location = new System.Drawing.Point(471, 215); + this.btnSaleAnalysis.Location = new System.Drawing.Point(627, 215); this.btnSaleAnalysis.Name = "btnSaleAnalysis"; this.btnSaleAnalysis.Size = new System.Drawing.Size(150, 100); - this.btnSaleAnalysis.TabIndex = 13; + this.btnSaleAnalysis.TabIndex = 14; this.btnSaleAnalysis.Text = "Sale Analysis"; this.btnSaleAnalysis.UseVisualStyleBackColor = true; this.btnSaleAnalysis.Click += new System.EventHandler(this.btnSaleAnalysis_Click); // + // btnTaxAnalysis + // + this.btnTaxAnalysis.Location = new System.Drawing.Point(3, 321); + this.btnTaxAnalysis.Name = "btnTaxAnalysis"; + this.btnTaxAnalysis.Size = new System.Drawing.Size(150, 100); + this.btnTaxAnalysis.TabIndex = 15; + this.btnTaxAnalysis.Text = "Tax Analysis"; + this.btnTaxAnalysis.UseVisualStyleBackColor = true; + this.btnTaxAnalysis.Click += new System.EventHandler(this.btnTaxAnalysis_Click); + // // btnSaleDetail // - this.btnSaleDetail.Location = new System.Drawing.Point(627, 215); + this.btnSaleDetail.Location = new System.Drawing.Point(159, 321); this.btnSaleDetail.Name = "btnSaleDetail"; this.btnSaleDetail.Size = new System.Drawing.Size(150, 100); - this.btnSaleDetail.TabIndex = 14; + this.btnSaleDetail.TabIndex = 16; this.btnSaleDetail.Text = "Sale Detail"; this.btnSaleDetail.UseVisualStyleBackColor = true; this.btnSaleDetail.Click += new System.EventHandler(this.btnSaleDetail_Click); // // btnBillDetails // - this.btnBillDetails.Location = new System.Drawing.Point(3, 321); + this.btnBillDetails.Location = new System.Drawing.Point(315, 321); this.btnBillDetails.Name = "btnBillDetails"; this.btnBillDetails.Size = new System.Drawing.Size(150, 100); - this.btnBillDetails.TabIndex = 15; + this.btnBillDetails.TabIndex = 17; this.btnBillDetails.Text = "Bill Details"; this.btnBillDetails.UseVisualStyleBackColor = true; this.btnBillDetails.Click += new System.EventHandler(this.btnBillDetails_Click); // // btnVoidOrReprints // - this.btnVoidOrReprints.Location = new System.Drawing.Point(159, 321); + this.btnVoidOrReprints.Location = new System.Drawing.Point(471, 321); this.btnVoidOrReprints.Name = "btnVoidOrReprints"; this.btnVoidOrReprints.Size = new System.Drawing.Size(150, 100); - this.btnVoidOrReprints.TabIndex = 16; + this.btnVoidOrReprints.TabIndex = 18; this.btnVoidOrReprints.Text = "Voids or Reprints"; this.btnVoidOrReprints.UseVisualStyleBackColor = true; this.btnVoidOrReprints.Click += new System.EventHandler(this.btnVoidOrReprints_Click); // // btnDiscountReport // - this.btnDiscountReport.Location = new System.Drawing.Point(315, 321); + this.btnDiscountReport.Location = new System.Drawing.Point(627, 321); this.btnDiscountReport.Name = "btnDiscountReport"; this.btnDiscountReport.Size = new System.Drawing.Size(150, 100); - this.btnDiscountReport.TabIndex = 17; + this.btnDiscountReport.TabIndex = 19; this.btnDiscountReport.Text = "Discount Report"; this.btnDiscountReport.UseVisualStyleBackColor = true; this.btnDiscountReport.Click += new System.EventHandler(this.btnDiscountReport_Click); // // btnChangePassword // - this.btnChangePassword.Location = new System.Drawing.Point(471, 321); + this.btnChangePassword.Location = new System.Drawing.Point(3, 427); this.btnChangePassword.Name = "btnChangePassword"; this.btnChangePassword.Size = new System.Drawing.Size(150, 100); - this.btnChangePassword.TabIndex = 18; + this.btnChangePassword.TabIndex = 20; this.btnChangePassword.Text = "Change Password"; this.btnChangePassword.UseVisualStyleBackColor = true; this.btnChangePassword.Click += new System.EventHandler(this.btnChangePassword_Click); // - // btnExit - // - this.btnExit.Location = new System.Drawing.Point(627, 321); - this.btnExit.Name = "btnExit"; - this.btnExit.Size = new System.Drawing.Size(150, 100); - this.btnExit.TabIndex = 19; - this.btnExit.Text = "Exit"; - this.btnExit.UseVisualStyleBackColor = true; - this.btnExit.Click += new System.EventHandler(this.btnExit_Click); - // // btnManagement // - this.btnManagement.Location = new System.Drawing.Point(3, 427); + this.btnManagement.Location = new System.Drawing.Point(159, 427); this.btnManagement.Name = "btnManagement"; this.btnManagement.Size = new System.Drawing.Size(150, 100); - this.btnManagement.TabIndex = 20; + this.btnManagement.TabIndex = 21; this.btnManagement.Text = "Management"; this.btnManagement.UseVisualStyleBackColor = true; this.btnManagement.Click += new System.EventHandler(this.btnManagement_Click); // + // btnExit + // + this.btnExit.Location = new System.Drawing.Point(315, 427); + this.btnExit.Name = "btnExit"; + this.btnExit.Size = new System.Drawing.Size(150, 100); + this.btnExit.TabIndex = 22; + this.btnExit.Text = "Exit"; + this.btnExit.UseVisualStyleBackColor = true; + this.btnExit.Click += new System.EventHandler(this.btnExit_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -317,21 +341,23 @@ private System.Windows.Forms.Button btnProduct; private System.Windows.Forms.Button btnProductGroup; private System.Windows.Forms.Button btnCustomer; - private System.Windows.Forms.Button btnExit; + private System.Windows.Forms.Button btnSwipeLogin; + private System.Windows.Forms.Button btnReorderTables; + private System.Windows.Forms.Button btnMachines; + private System.Windows.Forms.Button btnModifiers; + private System.Windows.Forms.Button btnOpenBill; private System.Windows.Forms.Button btnCreateUser; private System.Windows.Forms.Button btnUserRoles; - private System.Windows.Forms.Button btnChangePassword; + private System.Windows.Forms.Button btnGroupRoles; private System.Windows.Forms.Button btnCashierCheckout; private System.Windows.Forms.Button btnSaleAnalysis; - private System.Windows.Forms.Button btnGroupRoles; private System.Windows.Forms.Button btnSaleDetail; - private System.Windows.Forms.Button btnSwipeLogin; - private System.Windows.Forms.Button btnOpenBill; private System.Windows.Forms.Button btnBillDetails; private System.Windows.Forms.Button btnVoidOrReprints; - private System.Windows.Forms.Button btnManagement; private System.Windows.Forms.Button btnDiscountReport; - private System.Windows.Forms.Button btnReorderTables; - private System.Windows.Forms.Button btnModifiers; + private System.Windows.Forms.Button btnChangePassword; + private System.Windows.Forms.Button btnManagement; + private System.Windows.Forms.Button btnExit; + private System.Windows.Forms.Button btnTaxAnalysis; } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs index e6296ec..3f5251a 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.cs @@ -15,9 +15,23 @@ namespace Tanshu.Accounts.Management { Stopwatch _stopwatch; Stopwatch _totalStopwatch; + private BackgroundWorker bwGo = new BackgroundWorker(); + private BackgroundWorker bwExcel = new BackgroundWorker(); public ManagementForm() { InitializeComponent(); + + bwGo.WorkerReportsProgress = true; + bwGo.WorkerSupportsCancellation = true; + bwGo.DoWork += new DoWorkEventHandler(DoGo); + bwGo.ProgressChanged += new ProgressChangedEventHandler(bwGo_ProgressChanged); + bwGo.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwGo_RunWorkerCompleted); + + bwExcel.WorkerReportsProgress = true; + bwExcel.WorkerSupportsCancellation = true; + bwExcel.DoWork += new DoWorkEventHandler(DoExcel); + bwExcel.ProgressChanged += new ProgressChangedEventHandler(bwGo_ProgressChanged); + bwExcel.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwExcel_RunWorkerCompleted); } private void Sale_Analysis_Form_Load(object sender, EventArgs e) @@ -29,91 +43,207 @@ namespace Tanshu.Accounts.Management #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.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! "; - if (!File.Exists(sale)) - error += "Sale not found! "; - if (!File.Exists(credit)) - error += "Credit not found"; - if (!string.IsNullOrEmpty(error)) + if (btnGo.Text == "Go") { - MessageBox.Show(error); + txtStatus.Text = ""; + btnGo.Text = "Cancel"; + _stopwatch = Stopwatch.StartNew(); + _totalStopwatch = Stopwatch.StartNew(); + bwGo.RunWorkerAsync(); } else + bwGo.CancelAsync(); + } + private void btnExcel_Click(object sender, EventArgs e) + { + if (btnExcel.Text == "Excel") { - btnGo.Enabled = false; - var beerDates = GetBeer(beer); - var saleDates = GetSale(sale); - var creditDates = GetCredit(credit); + txtStatus.Text = ""; + btnExcel.Text = "Cancel"; + _stopwatch = Stopwatch.StartNew(); + _totalStopwatch = Stopwatch.StartNew(); + bwExcel.RunWorkerAsync(); + } + else + bwExcel.CancelAsync(); + } - var info = string.Empty; - foreach (var item in saleDates) + private void DoGo(object sender, DoWorkEventArgs e) + { + var beer = GetBeer(); + var sale = GetSale(); + var credit = GetCredit(); + + var info = string.Empty; + foreach (var item in sale) + { + var startDate = item.StartDate; + var finishDate = item.FinishDate; + var sDate = startDate.AddHours(7); + var fDate = finishDate.AddDays(1).AddHours(7); + int count = 0; + bwGo.ReportProgress(++count, "Starting on " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString()); + using (var bi = new ManagementBI()) { - 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()) + bi.DeleteVoid(sDate, fDate); + bwGo.ReportProgress(++count, "Voids Deleted"); + if (bwGo.CancellationPending == true) { - 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(); + e.Cancel = true; + return; } - worker.ReportProgress(++count, "Cleanup done"); + bi.MoveStaffToNc(sDate, fDate); + bwGo.ReportProgress(++count, "Staff Moved"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + bi.ClearModifiers(sDate, fDate); + bwGo.ReportProgress(++count, "Modifiers Cleared"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + bi.CombineKots(sDate, fDate); + bwGo.ReportProgress(++count, "Kots Combined"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + bi.RemoveBlankKots(sDate, fDate); + bwGo.ReportProgress(++count, "Blank Kots Removed"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + bwGo.ReportProgress(++count, "Starting beer"); + foreach (var beerDate in beer) + { + if (beerDate.Date < startDate || beerDate.Date > finishDate) + continue; + bi.SetBeer(beerDate.Date.AddHours(7), beerDate.Date.AddDays(1).AddHours(7), beerDate.Quantity); + bwGo.ReportProgress(++count, "Beer set for " + beerDate.Date.ToShortDateString()); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + } + bi.RemoveBlankKots(sDate, fDate); + bwGo.ReportProgress(++count, "Blank Kots Removed"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + 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 + bwGo.ReportProgress(++count, "Moved to Nc"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + IList creditJ = credit.Where(x => x.Date >= startDate && x.Date <= finishDate).ToList(); + bi.SetQuantityAndDiscount(item.Sale, creditJ, startDate, finishDate); + bwGo.ReportProgress(++count, "Sale Done"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + bi.RemoveBlankKots(sDate, fDate); + bwGo.ReportProgress(++count, "Blank Kots Removed"); + if (bwGo.CancellationPending == true) + { + e.Cancel = true; + return; + } + bi.SaveChanges(); } + bwGo.ReportProgress(++count, "Cleanup done"); } } - private void bwGo_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) + private void DoExcel(object sender, DoWorkEventArgs e) { - DoGo(sender as BackgroundWorker); + var startDate = dtpStart.Value.Date; + var finishDate = dtpFinish.Value.Date; + string sheet; + int count = 0; + var info = new List(); + var rates = new List(); + using (var bi = new ManagementBI()) + { + for (var date = startDate; date <= finishDate; date = date.AddDays(1)) + { + if (bwExcel.CancellationPending == true) + { + e.Cancel = true; + return; + } + bwExcel.ReportProgress(++count, "Getting data for " + date.ToShortDateString()); + 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); + + 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); + } + + rates.Sort(); + + 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) + { + if (bwExcel.CancellationPending == true) + { + e.Cancel = true; + return; + } + bwExcel.ReportProgress(++count, "Compiling data for " + item.Date.ToShortDateString()); + 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)); + + } + } + e.Result = sheet; } + private void bwGo_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { var time = (_stopwatch.ElapsedMilliseconds / 1000).ToString() + "s / " + (_totalStopwatch.ElapsedMilliseconds / 1000).ToString() + "s"; @@ -123,16 +253,41 @@ namespace Tanshu.Accounts.Management } private void bwGo_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { - txtStatus.Text += "Done !!!"; _stopwatch.Stop(); _totalStopwatch.Stop(); - btnGo.Enabled = true; - } - #endregion - #region Get Data - private IList GetSale(string sale) + btnGo.Text = "Go"; + if (!e.Cancelled) + txtStatus.Text = "Done !!!\r\n" + txtStatus.Text; + else + txtStatus.Text = "Cancelled :(\r\n" + txtStatus.Text; + } + private void bwExcel_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { + _stopwatch.Stop(); + _totalStopwatch.Stop(); + + btnExcel.Text = "Excel"; + if (!e.Cancelled) + { + txtStatus.Text = "Done !!!\r\n" + txtStatus.Text; + var sheet = (string)e.Result; + Clipboard.SetText(sheet, TextDataFormat.Text); + } + else + { + txtStatus.Text = "Cancelled :(\r\n" + txtStatus.Text; + } + } + + #endregion + #region Get Data + private IList GetSale() + { + var currentDirectory = AppDomain.CurrentDomain.BaseDirectory; + var sale = Path.Combine(currentDirectory, "sale.json"); + if (!File.Exists(sale)) + throw new ArgumentException("Sale not found!"); var startDate = dtpStart.Value.Date; var finishDate = dtpFinish.Value.Date; var fileContents = new StreamReader(File.OpenRead(sale)).ReadToEnd(); @@ -141,16 +296,18 @@ namespace Tanshu.Accounts.Management IList list = new List(); foreach (var item in data) { - if (!item.SDate.HasValue || !item.FDate.HasValue) - continue; - if (item.FDate.Value.Date < startDate.Date || item.SDate.Value.Date > finishDate.Date) + if (item.FinishDate.Date < startDate.Date || item.StartDate.Date > finishDate.Date) continue; list.Add(item); } return list; } - private IList GetCredit(string credit) + private IList GetCredit() { + var currentDirectory = AppDomain.CurrentDomain.BaseDirectory; + var credit = Path.Combine(currentDirectory, "credit.json"); + if (!File.Exists(credit)) + throw new ArgumentException("Credit not found!"); var startDate = dtpStart.Value.Date; var finishDate = dtpFinish.Value.Date; var fileContents = new StreamReader(File.OpenRead(credit)).ReadToEnd(); @@ -159,16 +316,21 @@ namespace Tanshu.Accounts.Management IList list = new List(); foreach (var item in data) { - if (!item.CDate.HasValue) - continue; - if (item.CDate.Value.Date < startDate.Date || item.CDate.Value.Date > finishDate.Date) + if (item.Date.Date < startDate.Date || item.Date.Date > finishDate.Date) continue; list.Add(item); } + var am = list.GroupBy(x => x.Date).Where(x => x.Count() > 1).Select(x => x.Key); + if (am.Count() > 0) + throw new ArgumentException("Duplicate dates in credit: " + am.Select(x => x.ToString("dd-MMM-yyyy")).Aggregate((c, n) => c + ", " + n)); return list; } - private IList GetBeer(string beer) + private IList GetBeer() { + var currentDirectory = AppDomain.CurrentDomain.BaseDirectory; + var beer = Path.Combine(currentDirectory, "beer.json"); + if (!File.Exists(beer)) + throw new ArgumentException("Beer not found!"); var startDate = dtpStart.Value.Date; var finishDate = dtpFinish.Value.Date; var fileContents = new StreamReader(File.OpenRead(beer)).ReadToEnd(); @@ -177,9 +339,7 @@ namespace Tanshu.Accounts.Management IList list = new List(); foreach (var item in data) { - if (!item.bDate.HasValue) - continue; - if (item.bDate.Value.Date < startDate.Date || item.bDate.Value.Date > finishDate.Date) + if (item.Date.Date < startDate.Date || item.Date.Date > finishDate.Date) continue; list.Add(item); } @@ -375,83 +535,14 @@ namespace Tanshu.Accounts.Management private void btnFinalSanction_Click(object sender, EventArgs e) { + var startDate = dtpStart.Value.Date.AddHours(7); + var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(7); using (var bi = new ManagementBI()) { - bi.UpdateBillID(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7)); + bi.SetPayments(startDate, finishDate); + bi.UpdateBillID(startDate, finishDate); 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 = GetExcel(startDate, finishDate); - Clipboard.SetText(sheet, TextDataFormat.Text); - btnExcel.Enabled = true; - } - private static string GetExcel(DateTime startDate, DateTime finishDate) - { - var info = new List(); - var rates = new List(); - using (var bi = new ManagementBI()) - { - 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); - - 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); - } - - 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 74f5314..473c8de 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.designer.cs @@ -35,7 +35,6 @@ 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(); // @@ -106,13 +105,6 @@ 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; @@ -156,7 +148,6 @@ 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 e00c01d..19dc0dd 100644 --- a/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx +++ b/Tanshu.Accounts.PointOfSale/Management/ManagementForm.resx @@ -117,7 +117,4 @@ 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/Masters/MachineEditForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.Designer.cs new file mode 100644 index 0000000..335826b --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.Designer.cs @@ -0,0 +1,136 @@ +namespace Tanshu.Accounts.PointOfSale +{ + partial class MachineEditForm + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.txtMachine = new System.Windows.Forms.TextBox(); + this.Label2 = new System.Windows.Forms.Label(); + this.Label5 = new System.Windows.Forms.Label(); + this.btnOk = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.cmbLocation = new System.Windows.Forms.ComboBox(); + this.bsLocations = new System.Windows.Forms.BindingSource(this.components); + ((System.ComponentModel.ISupportInitialize)(this.bsLocations)).BeginInit(); + this.SuspendLayout(); + // + // txtMachine + // + this.txtMachine.AccessibleName = ""; + this.txtMachine.Location = new System.Drawing.Point(94, 12); + this.txtMachine.Name = "txtMachine"; + this.txtMachine.Size = new System.Drawing.Size(276, 20); + this.txtMachine.TabIndex = 0; + // + // Label2 + // + this.Label2.AutoSize = true; + this.Label2.Location = new System.Drawing.Point(40, 15); + this.Label2.Name = "Label2"; + this.Label2.Size = new System.Drawing.Size(48, 13); + this.Label2.TabIndex = 10; + this.Label2.Text = "Machine"; + // + // Label5 + // + this.Label5.AutoSize = true; + this.Label5.Location = new System.Drawing.Point(40, 41); + this.Label5.Name = "Label5"; + this.Label5.Size = new System.Drawing.Size(48, 13); + this.Label5.TabIndex = 11; + this.Label5.Text = "Location"; + // + // btnOk + // + this.btnOk.Location = new System.Drawing.Point(214, 65); + this.btnOk.Name = "btnOk"; + this.btnOk.Size = new System.Drawing.Size(75, 75); + this.btnOk.TabIndex = 6; + this.btnOk.Text = "&Ok"; + this.btnOk.UseVisualStyleBackColor = true; + this.btnOk.Click += new System.EventHandler(this.btnOk_Click); + // + // btnCancel + // + this.btnCancel.Location = new System.Drawing.Point(295, 65); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(75, 75); + this.btnCancel.TabIndex = 7; + this.btnCancel.Text = "&Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // cmbLocation + // + this.cmbLocation.DataSource = this.bsLocations; + this.cmbLocation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cmbLocation.Location = new System.Drawing.Point(94, 38); + this.cmbLocation.Name = "cmbLocation"; + this.cmbLocation.Size = new System.Drawing.Size(276, 21); + this.cmbLocation.TabIndex = 21; + // + // bsLocations + // + this.bsLocations.DataSource = typeof(string); + // + // MachineEditForm + // + this.AcceptButton = this.btnOk; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btnCancel; + this.ClientSize = new System.Drawing.Size(382, 153); + this.Controls.Add(this.cmbLocation); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnOk); + this.Controls.Add(this.Label5); + this.Controls.Add(this.txtMachine); + this.Controls.Add(this.Label2); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MachineEditForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Machine Location"; + this.Load += new System.EventHandler(this.MachineEditForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.bsLocations)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + internal System.Windows.Forms.TextBox txtMachine; + internal System.Windows.Forms.Label Label2; + internal System.Windows.Forms.Label Label5; + private System.Windows.Forms.Button btnOk; + private System.Windows.Forms.Button btnCancel; + internal System.Windows.Forms.ComboBox cmbLocation; + private System.Windows.Forms.BindingSource bsLocations; + } +} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs b/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs new file mode 100644 index 0000000..7ba8ccc --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.cs @@ -0,0 +1,89 @@ +using System; +using System.Windows.Forms; +using Tanshu.Accounts.Repository; +using Tanshu.Accounts.Entities; +using System.Linq; +using System.Collections.Generic; + +namespace Tanshu.Accounts.PointOfSale +{ + public partial class MachineEditForm : Form + { + private Guid? _machineLocationID; + private string _machineName; + public MachineEditForm(Guid machineLocationID) + : this() + { + _machineLocationID = machineLocationID; + } + + public MachineEditForm(string machineName) + : this() + { + _machineName = machineName; + } + + public MachineEditForm() + { + InitializeComponent(); + } + + private void MachineEditForm_Load(object sender, EventArgs e) + { + MachineLocation machineLocation; + using (var bi = new MachineLocationBI()) + { + bsLocations.DataSource = bi.LocationList(); + if (_machineLocationID.HasValue) + { + machineLocation = bi.Get(x => x.MachineLocationID == _machineLocationID.Value); + txtMachine.Text = machineLocation.Machine; + cmbLocation.SelectedItem = machineLocation.Location; + txtMachine.Focus(); + } + else if (!string.IsNullOrEmpty(_machineName)) + { + txtMachine.Text = _machineName; + txtMachine.ReadOnly = true; + cmbLocation.Focus(); + } + else + { + txtMachine.Focus(); + } + } + } + + private void btnCancel_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void btnOk_Click(object sender, EventArgs e) + { + MachineLocation machineLocation; + using (var bi = new MachineLocationBI()) + { + if (_machineLocationID.HasValue) + machineLocation = bi.Get(x => x.MachineLocationID == _machineLocationID.Value); + else + machineLocation = new MachineLocation(); + + if (string.IsNullOrEmpty(txtMachine.Text.Trim())) + return; + machineLocation.Machine = txtMachine.Text.Trim(); + var location = (string)cmbLocation.SelectedItem; + if (string.IsNullOrEmpty(location)) + return; + machineLocation.Location = location; + if (_machineLocationID.HasValue) + bi.Update(machineLocation); + else + bi.Insert(machineLocation); + bi.SaveChanges(); + } + MessageBox.Show("Update / Save Successful"); + this.Close(); + } + } +} diff --git a/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.resx b/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.resx new file mode 100644 index 0000000..ac1282d --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Masters/MachineEditForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.Designer.cs new file mode 100644 index 0000000..9c427f3 --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.Designer.cs @@ -0,0 +1,152 @@ +namespace Tanshu.Accounts.PointOfSale +{ + partial class MachineListForm + { + /// + /// 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.components = new System.ComponentModel.Container(); + this.btnAdd = new System.Windows.Forms.Button(); + this.btnEdit = new System.Windows.Forms.Button(); + this.btnExit = new System.Windows.Forms.Button(); + this.dgvProductGroups = new System.Windows.Forms.DataGridView(); + this.bsList = new System.Windows.Forms.BindingSource(this.components); + this.machineDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.locationDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dgvProductGroups)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit(); + this.SuspendLayout(); + // + // btnAdd + // + this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnAdd.Location = new System.Drawing.Point(12, 255); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(75, 75); + this.btnAdd.TabIndex = 68; + this.btnAdd.Text = "&Add"; + this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); + // + // btnEdit + // + this.btnEdit.AccessibleName = "Done"; + this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnEdit.Location = new System.Drawing.Point(93, 255); + this.btnEdit.Name = "btnEdit"; + this.btnEdit.Size = new System.Drawing.Size(75, 75); + this.btnEdit.TabIndex = 62; + this.btnEdit.Text = "&Edit"; + this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); + // + // btnExit + // + this.btnExit.AccessibleName = "Done"; + this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnExit.Location = new System.Drawing.Point(514, 255); + this.btnExit.Name = "btnExit"; + this.btnExit.Size = new System.Drawing.Size(75, 75); + this.btnExit.TabIndex = 61; + this.btnExit.Text = "E&xit"; + this.btnExit.Click += new System.EventHandler(this.btnExit_Click); + // + // dgvProductGroups + // + this.dgvProductGroups.AllowUserToAddRows = false; + this.dgvProductGroups.AllowUserToDeleteRows = false; + this.dgvProductGroups.AllowUserToResizeRows = false; + this.dgvProductGroups.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dgvProductGroups.AutoGenerateColumns = false; + this.dgvProductGroups.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.dgvProductGroups.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvProductGroups.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.machineDataGridViewTextBoxColumn, + this.locationDataGridViewTextBoxColumn}); + this.dgvProductGroups.DataSource = this.bsList; + this.dgvProductGroups.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; + this.dgvProductGroups.Location = new System.Drawing.Point(12, 12); + this.dgvProductGroups.MultiSelect = false; + this.dgvProductGroups.Name = "dgvProductGroups"; + this.dgvProductGroups.ReadOnly = true; + this.dgvProductGroups.RowHeadersVisible = false; + this.dgvProductGroups.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.dgvProductGroups.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvProductGroups.Size = new System.Drawing.Size(577, 237); + this.dgvProductGroups.TabIndex = 74; + // + // bsList + // + this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.MachineLocation); + // + // machineDataGridViewTextBoxColumn + // + this.machineDataGridViewTextBoxColumn.DataPropertyName = "Machine"; + this.machineDataGridViewTextBoxColumn.HeaderText = "Machine"; + this.machineDataGridViewTextBoxColumn.Name = "machineDataGridViewTextBoxColumn"; + this.machineDataGridViewTextBoxColumn.ReadOnly = true; + this.machineDataGridViewTextBoxColumn.Width = 73; + // + // locationDataGridViewTextBoxColumn + // + this.locationDataGridViewTextBoxColumn.DataPropertyName = "Location"; + this.locationDataGridViewTextBoxColumn.HeaderText = "Location"; + this.locationDataGridViewTextBoxColumn.Name = "locationDataGridViewTextBoxColumn"; + this.locationDataGridViewTextBoxColumn.ReadOnly = true; + this.locationDataGridViewTextBoxColumn.Width = 73; + // + // MachineListForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(601, 342); + this.Controls.Add(this.dgvProductGroups); + this.Controls.Add(this.btnAdd); + this.Controls.Add(this.btnEdit); + this.Controls.Add(this.btnExit); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "MachineListForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Machines"; + this.Load += new System.EventHandler(this.MachineListForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvProductGroups)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.bsList)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + internal System.Windows.Forms.Button btnAdd; + internal System.Windows.Forms.Button btnEdit; + internal System.Windows.Forms.Button btnExit; + private System.Windows.Forms.DataGridView dgvProductGroups; + private System.Windows.Forms.BindingSource bsList; + private System.Windows.Forms.DataGridViewTextBoxColumn machineDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn locationDataGridViewTextBoxColumn; + } +} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.cs b/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.cs new file mode 100644 index 0000000..892dbb5 --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using Tanshu.Accounts.Entities; +using Tanshu.Accounts.Repository; + +namespace Tanshu.Accounts.PointOfSale +{ + public partial class MachineListForm : Form + { + private IList _list; + public MachineListForm() + { + InitializeComponent(); + } + + private void btnAdd_Click(object sender, EventArgs e) + { + using (var frm = new MachineEditForm()) + frm.ShowDialog(); + using (var bi = new MachineLocationBI()) + _list = bi.List(); + bsList.DataSource = _list; + } + + private void MachineListForm_Load(object sender, EventArgs e) + { + using (var bi = new MachineLocationBI()) + _list = bi.List(); + bsList.DataSource = _list; + } + + private void btnEdit_Click(object sender, EventArgs e) + { + var id = ((MachineLocation)bsList.Current).MachineLocationID; + using (var frm = new MachineEditForm(id)) + frm.ShowDialog(); + using (var bi = new MachineLocationBI()) + _list = bi.List(); + bsList.DataSource = _list; + } + + private void btnExit_Click(object sender, EventArgs e) + { + this.Close(); + } + } +} diff --git a/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.resx b/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.resx new file mode 100644 index 0000000..0a4e906 --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Masters/MachineListForm.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + 17, 17 + + \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Sales/ReorderTableForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Masters/ReorderTableForm.Designer.cs similarity index 100% rename from Tanshu.Accounts.PointOfSale/Sales/ReorderTableForm.Designer.cs rename to Tanshu.Accounts.PointOfSale/Masters/ReorderTableForm.Designer.cs diff --git a/Tanshu.Accounts.PointOfSale/Sales/ReorderTableForm.cs b/Tanshu.Accounts.PointOfSale/Masters/ReorderTableForm.cs similarity index 100% rename from Tanshu.Accounts.PointOfSale/Sales/ReorderTableForm.cs rename to Tanshu.Accounts.PointOfSale/Masters/ReorderTableForm.cs diff --git a/Tanshu.Accounts.PointOfSale/Sales/ReorderTableForm.resx b/Tanshu.Accounts.PointOfSale/Masters/ReorderTableForm.resx similarity index 100% rename from Tanshu.Accounts.PointOfSale/Sales/ReorderTableForm.resx rename to Tanshu.Accounts.PointOfSale/Masters/ReorderTableForm.resx diff --git a/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.Designer.cs index a752e77..d0995d3 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.Designer.cs @@ -177,7 +177,7 @@ this.Name = "ModifierListForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Product Types"; - this.Load += new System.EventHandler(this.ProductGroupListForm_Load); + this.Load += new System.EventHandler(this.ModifierListForm_Load); ((System.ComponentModel.ISupportInitialize)(this.dgvProductGroups)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bsList)).EndInit(); this.ResumeLayout(false); diff --git a/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.cs b/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.cs index 9cfa29a..1c26b97 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ModifierListForm.cs @@ -29,7 +29,7 @@ namespace Tanshu.Accounts.PointOfSale bsList.DataSource = _list; } - private void ProductGroupListForm_Load(object sender, EventArgs e) + private void ModifierListForm_Load(object sender, EventArgs e) { using (var bi = new ModifierBI()) _list = bi.List(); diff --git a/Tanshu.Accounts.PointOfSale/Profiling/BlockTimer.cs b/Tanshu.Accounts.PointOfSale/Profiling/BlockTimer.cs deleted file mode 100644 index 4b6cb34..0000000 --- a/Tanshu.Accounts.PointOfSale/Profiling/BlockTimer.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Tanshu.Accounts.PointOfSale -{ - public class BlockTimer : IDisposable - { - private readonly string _description; - private readonly long _start; - - public BlockTimer(string description) - { - _description = description; - _start = DateTime.Now.Ticks; - } - - public void Dispose() - { - var totalTime = DateTime.Now.Ticks - _start; - Console.WriteLine(_description); - Console.Write(" - Total Execution Time: "); - Console.Write(new TimeSpan(totalTime).TotalMilliseconds.ToString()); - Console.WriteLine(" ms."); - } - } -} diff --git a/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs b/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs index e2f6610..ef97bc5 100644 --- a/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs +++ b/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs @@ -40,8 +40,38 @@ namespace Tanshu.Accounts.PointOfSale if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit")) return; + var start = dtpStart.Value.Date.AddHours(6); + var finish = dtpFinish.Value.Date.AddDays(1).AddHours(5); + _list = new List(); + if (finish > start) + { + var bi = new SalesAnalysisBI(); + var list = new List(); + list.AddRange(bi.GetSale(start, finish)); + list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 }); + list.AddRange(bi.GetSettlements(start, finish)); + list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 }); + var sc = bi.GetServiceCharge(start, finish); + if (sc != null) + list.Add(sc); + + foreach (var item in bi.GetServiceTax(start, finish)) + { + if (item.TaxAmount != 0) + { + list.Add(new SalesAnalysis() { GroupType = item.Name, Amount = item.TaxAmount }); + } + } + foreach (var item in bi.GetVat(start, finish)) + { + if (item.TaxAmount != 0) + { + list.Add(new SalesAnalysis() { GroupType = item.Name, Amount = item.TaxAmount }); + } + } + _list = list; + } - _list = new SalesAnalysisBI().GetSaleAnalysis(dtpStart.Value, dtpFinish.Value); dgvSale.AutoGenerateColumns = true; dgvSale.DataSource = _list; diff --git a/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.cs b/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.cs new file mode 100644 index 0000000..259cdcc --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Tanshu.Accounts.Repository; +using Tanshu.Accounts.Contracts; + +namespace Tanshu.Accounts.PointOfSale +{ + public partial class frmTaxAnalysisForm : Form + { + IList _list; + bool _loading; + public frmTaxAnalysisForm() + { + _loading = true; + InitializeComponent(); + } + + private void SaleAnalysisForm_Load(object sender, EventArgs e) + { + dtpStart.Format = DateTimePickerFormat.Custom; + dtpStart.CustomFormat = "dd-MMM-yyyy"; + dtpStart.Value = DateTime.Now.Date; + dtpFinish.Format = DateTimePickerFormat.Custom; + dtpFinish.CustomFormat = "dd-MMM-yyyy"; + dtpFinish.Value = DateTime.Now.Date; + _loading = false; + ShowStatement(); + } + + private void dtpStart_ValueChanged(object sender, EventArgs e) + { + ShowStatement(); + } + + private void ShowStatement() + { + if (_loading) + return; + if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && + !Session.IsAllowed("Accounts Audit")) + return; + var start = dtpStart.Value.Date.AddHours(6); + var finish = dtpFinish.Value.Date.AddDays(1).AddHours(5); + _list = new List(); + if (finish > start) + { + var bi = new SalesAnalysisBI(); + var list = new List(); + list.AddRange(bi.GetServiceTax(start, finish)); + list.AddRange(bi.GetVat(start, finish)); + _list = list; + } + + + dgvSale.AutoGenerateColumns = true; + dgvSale.DataSource = _list; + dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; + dgvSale.Columns[1].DefaultCellStyle.Format = "#.##%;(#.##%);0%"; + dgvSale.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; + dgvSale.Columns[2].DefaultCellStyle.Format = "#,##0.00;(#,##0.00);0"; + dgvSale.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; + dgvSale.Columns[3].DefaultCellStyle.Format = "#,##0.00;(#,##0.00);0"; + dgvSale.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; + } + + private void dtpFinish_ValueChanged(object sender, EventArgs e) + { + ShowStatement(); + } + + private void btnPrint_Click(object sender, EventArgs e) + { + if (_list != null) + { + var startDate = dtpStart.Value.Date.AddHours(6); + var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(5); + //Accounts.Print.Thermal.PrintSale(Session.User.Name, _list, startDate, finishDate); + } + } + } +} diff --git a/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.designer.cs b/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.designer.cs new file mode 100644 index 0000000..6a695ac --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.designer.cs @@ -0,0 +1,128 @@ +namespace Tanshu.Accounts.PointOfSale +{ + partial class frmTaxAnalysisForm + { + /// + /// 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.dgvSale = new System.Windows.Forms.DataGridView(); + this.dtpFinish = new System.Windows.Forms.DateTimePicker(); + this.dtpStart = new System.Windows.Forms.DateTimePicker(); + this.label10 = new System.Windows.Forms.Label(); + this.btnPrint = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dgvSale)).BeginInit(); + this.SuspendLayout(); + // + // dgvSale + // + this.dgvSale.AllowUserToAddRows = false; + this.dgvSale.AllowUserToDeleteRows = false; + this.dgvSale.AllowUserToResizeRows = false; + this.dgvSale.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dgvSale.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvSale.Location = new System.Drawing.Point(12, 41); + this.dgvSale.MultiSelect = false; + this.dgvSale.Name = "dgvSale"; + this.dgvSale.ReadOnly = true; + this.dgvSale.RowHeadersVisible = false; + this.dgvSale.RowTemplate.Height = 19; + this.dgvSale.RowTemplate.ReadOnly = true; + this.dgvSale.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvSale.Size = new System.Drawing.Size(383, 466); + this.dgvSale.TabIndex = 14; + // + // dtpFinish + // + this.dtpFinish.CustomFormat = "dd-MMM-yyyy"; + this.dtpFinish.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dtpFinish.Location = new System.Drawing.Point(168, 12); + this.dtpFinish.Name = "dtpFinish"; + this.dtpFinish.Size = new System.Drawing.Size(90, 20); + this.dtpFinish.TabIndex = 21; + this.dtpFinish.ValueChanged += new System.EventHandler(this.dtpFinish_ValueChanged); + // + // dtpStart + // + this.dtpStart.CustomFormat = "dd-MMM-yyyy"; + this.dtpStart.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dtpStart.Location = new System.Drawing.Point(12, 12); + this.dtpStart.Name = "dtpStart"; + this.dtpStart.Size = new System.Drawing.Size(90, 20); + this.dtpStart.TabIndex = 20; + this.dtpStart.ValueChanged += new System.EventHandler(this.dtpStart_ValueChanged); + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Location = new System.Drawing.Point(108, 16); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(54, 13); + this.label10.TabIndex = 22; + this.label10.Text = "<- Date ->"; + // + // btnPrint + // + this.btnPrint.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnPrint.Location = new System.Drawing.Point(320, 12); + this.btnPrint.Name = "btnPrint"; + this.btnPrint.Size = new System.Drawing.Size(75, 23); + this.btnPrint.TabIndex = 28; + this.btnPrint.Text = "Print"; + this.btnPrint.UseVisualStyleBackColor = true; + this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click); + // + // frmTaxAnalysisForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(407, 519); + this.Controls.Add(this.btnPrint); + this.Controls.Add(this.dgvSale); + this.Controls.Add(this.dtpFinish); + this.Controls.Add(this.dtpStart); + this.Controls.Add(this.label10); + this.MaximizeBox = false; + this.Name = "frmTaxAnalysisForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Sale Analysis Form"; + this.Load += new System.EventHandler(this.SaleAnalysisForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvSale)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataGridView dgvSale; + private System.Windows.Forms.DateTimePicker dtpFinish; + private System.Windows.Forms.DateTimePicker dtpStart; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.Button btnPrint; + } +} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.resx b/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.resx new file mode 100644 index 0000000..19dc0dd --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Reports/TaxAnalysisForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Tanshu.Accounts.PointOfSale.csproj b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj index ea39357..c962f8d 100644 --- a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj +++ b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj @@ -112,6 +112,18 @@ ManagementForm.cs + + Form + + + MachineListForm.cs + + + Form + + + MachineEditForm.cs + Form @@ -142,7 +154,6 @@ ProductGroupListForm.cs - True True @@ -154,6 +165,12 @@ BillDetailsForm.cs + + Form + + + TaxAnalysisForm.cs + Form @@ -172,10 +189,10 @@ SaleDetail.cs - + Form - + ReorderTableForm.cs @@ -293,6 +310,14 @@ ManagementForm.cs + + MachineListForm.cs + Designer + + + MachineEditForm.cs + Designer + ModifierEditForm.cs Designer @@ -322,6 +347,10 @@ BillDetailsForm.cs Designer + + TaxAnalysisForm.cs + Designer + DiscountReportForm.cs Designer @@ -334,7 +363,7 @@ SaleDetail.cs Designer - + ReorderTableForm.cs diff --git a/Tanshu.Accounts.Print/ThermalBill.cs b/Tanshu.Accounts.Print/ThermalBill.cs index 034dd4f..b9a883f 100644 --- a/Tanshu.Accounts.Print/ThermalBill.cs +++ b/Tanshu.Accounts.Print/ThermalBill.cs @@ -104,7 +104,8 @@ namespace Tanshu.Accounts.Print billText += DrawLine; } billText += "\n\r" + "Cashier : " + voucher.User.Name + " / " + voucher.Waiter.Name; - billText += "\n\r" + "Call: 0172-4026666, 8054923853, 8054923856"; + using (var bis = new SettingBI()) + billText += "\n\r" + bis.Get(x => x.Name == "Footer").Details; return billText; } } @@ -150,14 +151,8 @@ namespace Tanshu.Accounts.Print private static string Header(Voucher voucher) { var billText = ""; - billText += "\n\r" + "Hops n Grains".Center42(); - billText += "\n\r" + "The Microbrewery".Center42(); - billText += "\n\r" + "SCO 358, Sector 9, Panchkula".Center42(); - billText += "\n\r" + "A Unit of Peitho Foods Pvt. Ltd.".Center42(); - billText += "\n\r" + "CIN: U15139CH2010PTC032202".Center42(); - billText += "\n\r" + "(Reg Add: SCO 1, Pocket 1, Manimajra, Chd)".Center42(); - billText += "\n\r" + "TIN: 06592507323".Center42(); - billText += "\n\r" + "Service Tax: AAFCP5097GSD001".Center42(); + using (var bi = new SettingBI()) + billText += "\n\r" + bi.Get(x => x.Name == "Header").Details; switch (voucher.VoucherType) { case VoucherType.Regular: diff --git a/Tanshu.Accounts.Repository/Cache.cs b/Tanshu.Accounts.Repository/Cache.cs index 805f0e6..5248480 100644 --- a/Tanshu.Accounts.Repository/Cache.cs +++ b/Tanshu.Accounts.Repository/Cache.cs @@ -1,27 +1,72 @@ -using NHibernate; -using Tanshu.Accounts.Entities; -using System.Linq; -using System; +using System; using System.Collections.Generic; -using System.Linq.Expressions; -using System.Configuration; +using NHibernate; +using Tanshu.Accounts.Entities; using Tanshu.Accounts.Entities.Auth; namespace Tanshu.Accounts.Repository { public class Cache { - private static IList cache = null; - private static Dictionary locations = new Dictionary(); - private static Dictionary> modifiers = new Dictionary>(); - private static string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant(); - - private static IList roles = null; - + private static IList _productGroups = null; + private static Dictionary> _modifiers = new Dictionary>(); + private static string _machine = Environment.MachineName; + private static string _location = null; + private static Dictionary _locations = new Dictionary(); + private static IList _roles = null; private static bool _log = false; + + public static string Location + { + get + { + if (string.IsNullOrEmpty(_location)) + { + using (var bi = new MachineLocationBI()) + { + var loc = bi.Get(x => x.Machine == _machine); + if (loc != null) + _location = loc.Location; + } + } + return _location; + } + } + public static PrintLocation BasePrinter + { + get + { + if (string.IsNullOrEmpty(Location)) + throw new ArgumentException("No location for Machine"); + if (!_locations.ContainsKey(Location.GetHashCode())) + { + using (var bi = new PrintLocationBI()) + { + var loc = bi.Get(x => x.Location == Location && x.ProductGroup == null); + _locations.Add(Location.GetHashCode(), loc); + } + } + return _locations[Location.GetHashCode()]; + } + } + public static PrintLocation KotPrinter(Guid productGroupID) + { + if (string.IsNullOrEmpty(Location)) + throw new ArgumentException("No location for Machine"); + if (!_locations.ContainsKey(Location.GetHashCode() ^ productGroupID.GetHashCode())) + { + using (var bi = new PrintLocationBI()) + { + var loc = bi.Get(x => x.Location == Location && x.ProductGroup.ProductGroupID == productGroupID) ?? + bi.Get(x => x.Location == Location && x.ProductGroup == null); + _locations.Add(Location.GetHashCode() ^ productGroupID.GetHashCode(), loc); + } + } + return _locations[Location.GetHashCode() ^ productGroupID.GetHashCode()]; + } public static IList ProductGroups() { - if (cache == null) + if (_productGroups == null) { using (var bi = new ProductGroupBI()) { @@ -30,72 +75,46 @@ namespace Tanshu.Accounts.Repository { NHibernateUtil.Initialize(item.Products); } - cache = list; + _productGroups = list; } } - return cache; - } - public static PrintLocation BasePrinter - { - get - { - if (!locations.ContainsKey(location.GetHashCode())) - { - using (var bi = new PrintLocationBI()) - { - var loc = bi.Get(x => x.Location == location && x.ProductGroup == null); - locations.Add(location.GetHashCode(), loc); - } - } - return locations[location.GetHashCode()]; - } - } - public static PrintLocation KotPrinter(Guid productGroupID) - { - if (!locations.ContainsKey(location.GetHashCode() ^ productGroupID.GetHashCode())) - { - using (var bi = new PrintLocationBI()) - { - var loc = bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ?? - bi.Get(x => x.Location == location && x.ProductGroup == null); - locations.Add(location.GetHashCode() ^ productGroupID.GetHashCode(), loc); - } - } - return locations[location.GetHashCode() ^ productGroupID.GetHashCode()]; + return _productGroups; } public static IList ProductGroupModifiers(Guid productGroupID) { - if (!modifiers.ContainsKey(productGroupID)) + if (!_modifiers.ContainsKey(productGroupID)) { using (var bi = new ProductGroupModifierBI()) { var list = bi.List(productGroupID); - modifiers.Add(productGroupID, list); + _modifiers.Add(productGroupID, list); } } - return modifiers[productGroupID]; + return _modifiers[productGroupID]; } public static IList UserRoles(Guid userID) { - if (roles == null) + if (_roles == null) { using (var bi = new UserBI()) { - roles = bi.Roles(userID); + _roles = bi.Roles(userID); } } - return roles; - } - public static void ClearRoles() - { - roles = null; + return _roles; } + public static void ClearRoles() + { + _roles = null; + } public static void Invalidate() { - cache = null; - locations = new Dictionary(); - modifiers = new Dictionary>(); + _productGroups = null; + _machine = Environment.MachineName; + _location = null; + _locations = new Dictionary(); + _modifiers = new Dictionary>(); } public static bool Log { diff --git a/Tanshu.Accounts.Repository/MachineLocationBI.cs b/Tanshu.Accounts.Repository/MachineLocationBI.cs new file mode 100644 index 0000000..73ba937 --- /dev/null +++ b/Tanshu.Accounts.Repository/MachineLocationBI.cs @@ -0,0 +1,17 @@ +using NHibernate; +using Tanshu.Accounts.Entities; +using System.Collections.Generic; + + +namespace Tanshu.Accounts.Repository +{ + public class MachineLocationBI : UnitOfWork + { + public IList LocationList() + { + const string query = @"select distinct(pl.Location) from PrintLocation pl order by pl.Location"; + var hnq = _session.CreateQuery(query); + return hnq.List(); + } + } +} diff --git a/Tanshu.Accounts.Repository/ManagementBI.cs b/Tanshu.Accounts.Repository/ManagementBI.cs index 18d679c..8774f92 100644 --- a/Tanshu.Accounts.Repository/ManagementBI.cs +++ b/Tanshu.Accounts.Repository/ManagementBI.cs @@ -29,35 +29,35 @@ namespace Tanshu.Accounts.Repository IFormatProvider culture = new CultureInfo("en-US", true); private DateTime? dateStart; private DateTime? dateFinish; - public string StartDate { get; set; } - public string FinishDate { get; set; } + public string _startDate { get; set; } + public string _finishDate { get; set; } public IList Sale { get; set; } - public DateTime? SDate + public DateTime StartDate { 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; + if (!dateStart.HasValue) + { + DateTime tDate; + if (!DateTime.TryParseExact(_startDate, "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) + throw new ArgumentException(); + dateStart = tDate; + } + return dateStart.Value; } } - public DateTime? FDate + public DateTime FinishDate { 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; + if (!dateFinish.HasValue) + { + DateTime tDate; + if (!DateTime.TryParseExact(_finishDate, "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) + throw new ArgumentException(); + dateFinish = tDate; + } + return dateFinish.Value; } } } @@ -71,20 +71,20 @@ namespace Tanshu.Accounts.Repository { IFormatProvider culture = new CultureInfo("en-US", true); private DateTime? date; - public string Date { get; set; } + public string _date { get; set; } public IList Beers { get; set; } - public DateTime? bDate + public DateTime Date { get { - if (date.HasValue) - return date; - DateTime tDate; - if (!DateTime.TryParseExact(Date, "d MMM yy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) - date = null; - else + if (!date.HasValue) + { + DateTime tDate; + if (!DateTime.TryParseExact(_date, "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) + throw new ArgumentException(); date = tDate; - return tDate; + } + return date.Value; } } public decimal Quantity @@ -109,20 +109,20 @@ namespace Tanshu.Accounts.Repository { IFormatProvider culture = new CultureInfo("en-US", true); private DateTime? date; - public string Date { get; set; } + public string _date { get; set; } public decimal Amount { get; set; } - public DateTime? CDate + public DateTime Date { get { - if (date.HasValue) - return date; - DateTime tDate; - if (!DateTime.TryParseExact(Date, "dd/MM/yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) - date = null; - else + if (!date.HasValue) + { + DateTime tDate; + if (!DateTime.TryParseExact(_date, "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out tDate)) + throw new ArgumentException(); date = tDate; - return tDate; + } + return date.Value; } } } @@ -351,6 +351,22 @@ group by v.VoucherID, v.VoucherType"; } var amount = -1 * (decimal)item.Value[1]; var roundoff = Math.Round(amount) - amount; + query = @"select count(*) from VoucherSettlement vs +where vs.Voucher.VoucherID = :voucherID and ( +(vs.Amount = :amount and vs.Settled = :soAmount) or +(vs.Amount = :roundOff and vs.Settled = :soRoundOff) or +(vs.Amount = :paid and vs.Settled = :so))"; + var existing = _session.CreateQuery(query) + .SetParameter("voucherID", item.Key) + .SetParameter("amount", amount) + .SetParameter("roundOff", roundoff) + .SetParameter("paid", -1 * (amount + roundoff)) + .SetParameter("soAmount", SettleOption.Amount) + .SetParameter("soRoundOff", SettleOption.RoundOff) + .SetParameter("so", settlementType) + .UniqueResult(); + if (existing == 3) + continue; query = @"delete from VoucherSettlement vs where vs.Voucher.VoucherID = :voucherID"; _session .CreateQuery(query) @@ -450,8 +466,8 @@ order by sum(i.Amount) desc "; var list = _session .CreateQuery(query) - .SetParameter("startDate", startDate.AddHours(7)) - .SetParameter("finishDate", finishDate.AddDays(1).AddHours(7)) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) .SetParameter("nc", VoucherType.NoCharge) .SetParameter("staff", VoucherType.Staff) .SetParameter("vatLiquor", new Guid("2C8AD8EC-E09A-4194-B348-01243474CF26")) @@ -501,7 +517,6 @@ order by i.VatRate } return info; } - public decimal GetServiceTax(DateTime startDate, DateTime finishDate) { const string query = @" @@ -560,7 +575,7 @@ order by v.Date desc return (int)qty; } - public decimal GetSaleAmount(decimal vat, DateTime startDate, DateTime finishDate) + private 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 @@ -579,109 +594,167 @@ where v.Date >= :startDate and v.Date <= :finishDate and i.VatRate = :vat and v. .UniqueResult(); return qty == null ? 0 : (decimal)qty; } - public decimal SetSaleQuantity(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) + public class DateVatSale { - 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); - 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; - var inventoryAmount = item.Value; - - if (inventoryAmount > left) - { - 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 GetSaleAmount(vat, startDate, finishDate); + public DateTime Date { get; set; } + public decimal VatRate { get; set; } + public decimal Net { get; set; } + public decimal Gross { get; set; } } - public decimal SetSaleDiscount(decimal vat, decimal amount, DateTime startDate, DateTime finishDate) + public List GetSaleAmount(DateTime startDate, DateTime finishDate) + { + var list = new List(); + const string query = @" + select i.VatRate, sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 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 v.Void = false and v.VoucherType not in (:nc, :staff) + group by i.VatRate + "; + IList q; + for (var date = startDate.Date; date <= finishDate.Date; date = date.AddDays(1)) + { + q = _session + .CreateQuery(query) + .SetParameter("startDate", date.AddHours(7)) + .SetParameter("finishDate", date.AddDays(1).AddHours(7)) + .SetParameter("nc", VoucherType.NoCharge) + .SetParameter("staff", VoucherType.Staff) + .List(); + foreach (var item in q) + { + list.Add(new DateVatSale() { Date = date, VatRate = (decimal)item[0], Net = (decimal)item[1], Gross = (decimal)item[2] }); + } + } + return list; + } + private class InvDate : Inventory + { + public DateTime Date { get; set; } + public decimal Net + { + get + { + if (IsScTaxable) + return Quantity * Price * (1 - Discount) * (1 + ServiceCharge); + return Quantity * Price * (1 - Discount); + } + } + } + public void SetQuantityAndDiscount(IList sale, IList credit, DateTime startDate, DateTime finishDate) { var rand = new Random(); 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) +select v.Date, i.InventoryID, i.Quantity, i.Price, i.Discount, i.ServiceCharge, i.IsScTaxable, i.ServiceTaxRate, i.VatRate 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("startDate", startDate.AddHours(7)) + .SetParameter("finishDate", finishDate.AddDays(1).AddHours(7)) .SetParameter("regular", VoucherType.Regular) - .SetParameter("vat", vat) - .SetParameter("maxDiscount", .9M) .SetParameter("takeAway", VoucherType.TakeAway) .List(); - Dictionary inventories = new Dictionary(); - list = Randomize(list); - foreach (var item in list) + List inventories = new List(); + foreach (var item in Randomize(list)) { - inventories.Add((Guid)item[0], new object[] { Convert.ToDecimal(item[1]), Convert.ToDecimal(item[2]), Convert.ToDecimal(item[3]) }); + inventories.Add(new InvDate() + { + Date = ((DateTime)item[0]).AddHours(-7).Date, + InventoryID = (Guid)item[1], + Quantity = (decimal)item[2], + Price = (decimal)item[3], + Discount = (decimal)item[4], + ServiceCharge = (decimal)item[5], + IsScTaxable = (bool)item[6], + ServiceTaxRate = (decimal)item[7], + VatRate = (decimal)item[8] + }); } + var sales = GetSaleAmount(startDate, finishDate); + List continueDates = new List(); + List continueVat = new List(); + var creditSale = credit.Sum(x => x.Amount); + //this is approx, but more than actual as the formula does not take into account service tax + var creditLiqSale = creditSale - sale.Where(x => x.IsLiq == false).Sum(x => x.Amount * (1 + x.Rate)); + var actualLiqSale = sales.Where(x => sale.Where(y => y.IsLiq == true).Select(y => y.Rate).Contains(x.VatRate)).Sum(x => x.Gross); + var max = 1 - (creditLiqSale / actualLiqSale); + max = Math.Min(.90M, Math.Round(max, 2) * 2); + max = Math.Max(.10M, max); + int run = 0; - var left = GetSaleAmount(vat, startDate, finishDate) - amount; - foreach (var item in inventories) + while (continueVat.Intersect(sale.Select(x => x.Rate)).Count() != continueVat.Union(sale.Select(x => x.Rate)).Count() && continueDates.Intersect(credit.Select(x => x.Date)).Count() != continueDates.Union(credit.Select(x => x.Date)).Count() && ++run <= 10) { - if (left <= 0) - break; - 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); + foreach (var inv in inventories) + { + if (sale.Count(x => x.Rate == inv.VatRate) == 0) + throw new ArgumentException("Unknown type of vat rate encountered"); - 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; + var creditForDay = credit.SingleOrDefault(x => x.Date == inv.Date).Amount; + var grossSaleForDay = sales.Where(x => x.Date == inv.Date).Sum(x => x.Gross); + if (creditForDay >= grossSaleForDay && !continueDates.Contains(inv.Date)) + continueDates.Add(inv.Date); + var targetVatAmountForPeriod = sale.SingleOrDefault(x => x.Rate == inv.VatRate).Amount; + var vatRemainingForPeriod = sales.Where(x => x.VatRate == inv.VatRate).Sum(x => x.Net); + if (vatRemainingForPeriod <= targetVatAmountForPeriod && !continueVat.Contains(inv.VatRate)) + continueVat.Add(inv.VatRate); + + if (continueDates.Contains(inv.Date) || continueVat.Contains(inv.VatRate)) + continue; + + var vatLeft = vatRemainingForPeriod - targetVatAmountForPeriod; + var creditLeft = grossSaleForDay - creditForDay; + var left = Math.Min(vatLeft, creditLeft); //Net Gross conversion + + var isLiq = sale.SingleOrDefault(x => x.Rate == inv.VatRate).IsLiq; + if (isLiq) + { + if (inv.Discount >= max || inv.Price == 0) + continue; + var minimum = inv.Discount == 0 ? 10 : Convert.ToInt32(inv.Discount * 100) + 1; + var discount = Convert.ToDecimal(rand.Next(minimum, Convert.ToInt32(max * 100))) / 100; + + if (inv.Net * (discount - inv.Discount) > left) + { + discount = Math.Round(left * (1 - inv.Discount) / inv.Net, 2); + } + query = @"update Inventory set Discount = :discount where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("discount", discount).SetParameter("inventoryID", inv.InventoryID).ExecuteUpdate(); + // reduce from daily + var saleItem = sales.Single(x => x.Date == inv.Date && x.VatRate == inv.VatRate); + inv.Discount += 1 - discount; + saleItem.Net -= Math.Round(inv.Net); + saleItem.Gross -= Math.Round(inv.Amount); + } + else + { + if (inv.Net > left) + { + var ratio = (inv.Net - left) / inv.Net; + query = @"update Inventory set Quantity = Quantity * :ratio where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("ratio", ratio).SetParameter("inventoryID", inv.InventoryID).ExecuteUpdate(); + // reduce from daily + var saleItem = sales.Single(x => x.Date == inv.Date && x.VatRate == inv.VatRate); + inv.Quantity -= inv.Quantity * ratio; + saleItem.Net -= Math.Round(inv.Net); + saleItem.Gross -= Math.Round(inv.Amount); + } + else + { + query = @"delete from Inventory where InventoryID = :inventoryID"; + _session.CreateQuery(query).SetParameter("inventoryID", inv.InventoryID).ExecuteUpdate(); + // reduce from daily + var saleItem = sales.Single(x => x.Date == inv.Date && x.VatRate == inv.VatRate); + saleItem.Net -= inv.Net; + saleItem.Gross -= inv.Amount; + } + } } } - return GetSaleAmount(vat, startDate, finishDate); } diff --git a/Tanshu.Accounts.Repository/SalesAnalysisBI.cs b/Tanshu.Accounts.Repository/SalesAnalysisBI.cs index 2510754..9bb41ce 100644 --- a/Tanshu.Accounts.Repository/SalesAnalysisBI.cs +++ b/Tanshu.Accounts.Repository/SalesAnalysisBI.cs @@ -19,27 +19,7 @@ namespace Tanshu.Accounts.Repository _session = SessionManager.Session; } - public IList GetSaleAnalysis(DateTime startDate, DateTime finishDate) - { - var start = startDate.Date.AddHours(6); - var finish = finishDate.Date.AddDays(1).AddHours(5); - List list = new List(); - if (finish <= start) - return list; - list.AddRange(GetSale(start, finish)); - list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 }); - list.AddRange(GetSettlements(start, finish)); - list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 }); - var sc = GetServiceCharge(start, finish); - if (sc != null) - list.Add(sc); - var st = GetServiceTax(start, finish); - if (st != null) - list.Add(st); - list.AddRange(GetVat(start, finish)); - return list; - } - private IList GetSale(DateTime startDate, DateTime finishDate) + public IList GetSale(DateTime startDate, DateTime finishDate) { const string query = @" select g.GroupType as GroupType, Sum(i.Quantity * i.Price * (1 - i.Discount)) as Amount @@ -74,7 +54,7 @@ order by g.GroupType outList.Add(new SalesAnalysis() { GroupType = "Total Settled", Amount = amount }); return outList; } - private IList GetSettlements(DateTime startDate, DateTime finishDate) + public IList GetSettlements(DateTime startDate, DateTime finishDate) { const string query = @" select s.Settled, Sum(s.Amount) @@ -99,7 +79,7 @@ order by s.Settled outList.Add(new SalesAnalysis() { GroupType = "Total", Amount = amount }); return outList; } - private SalesAnalysis GetServiceCharge(DateTime startDate, DateTime finishDate) + public SalesAnalysis GetServiceCharge(DateTime startDate, DateTime finishDate) { var query = @" select coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * i.ServiceCharge), 0) @@ -124,45 +104,19 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou return new SalesAnalysis() { GroupType = "Service Charge", Amount = amt }; return null; } - private SalesAnalysis GetServiceTax(DateTime startDate, DateTime finishDate) + public IList GetServiceTax(DateTime startDate, DateTime finishDate) { + var outList = new List(); var query = @" -select coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate), 0) +select i.ServiceTaxRate, coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate), 0), +coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 0) 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 exists (select Voucher from VoucherSettlement vs where vs.Voucher = v and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff) -"; - var amt = _session - .CreateQuery(query) - .SetParameter("startDate", startDate) - .SetParameter("finishDate", finishDate) - .SetParameter("noCharge", SettleOption.NoCharge) - .SetParameter("unsettled", SettleOption.Unsettled) - .SetParameter("amount", SettleOption.Amount) - .SetParameter("roundoff", SettleOption.RoundOff) - .SetParameter("staff", SettleOption.Staff) - .UniqueResult(); - if (amt != 0) - return new SalesAnalysis() { GroupType = "Service Tax", Amount = amt }; - return null; - } - private IList GetVat(DateTime startDate, DateTime finishDate) - { - var outList = new List(); - var query = @" -select va.Name, i.VatRate, coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate), 0) -from Voucher v -inner join v.Kots k -inner join k.Inventories i -inner join i.Vat va -where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false -and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v -and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff) -group by i.VatRate, va.Name -"; +group by i.ServiceTaxRate"; var list = _session .CreateQuery(query) .SetParameter("startDate", startDate) @@ -174,8 +128,38 @@ group by i.VatRate, va.Name .SetParameter("staff", SettleOption.Staff) .List(); foreach (var item in list) - if ((decimal)item[2] != 0) - outList.Add(new SalesAnalysis() { GroupType = string.Format("{0} - {1:#.##%}", (string)item[0], (decimal)item[1]), Amount = (decimal)item[2] }); + outList.Add(new TaxAnalysis() { Name = string.Format("Service Tax - {0:#.##%;(#.##%);0%}", (decimal)item[0]), TaxRate = (decimal)item[0], TaxAmount = (decimal)item[1], NetSale = (decimal)item[2] }); + return outList; + } + public IList GetVat(DateTime startDate, DateTime finishDate) + { + var outList = new List(); + var query = @" +select va.Name, i.VatRate, coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate), 0), +coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 0) +from Voucher v +inner join v.Kots k +inner join k.Inventories i +inner join i.Vat va +where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false +and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v +and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff and vs.Settled != :void and vs.Settled != :tip) +group by i.VatRate, va.Name +"; + var list = _session + .CreateQuery(query) + .SetParameter("startDate", startDate) + .SetParameter("finishDate", finishDate) + .SetParameter("noCharge", SettleOption.NoCharge) + .SetParameter("unsettled", SettleOption.Unsettled) + .SetParameter("amount", SettleOption.Amount) + .SetParameter("roundoff", SettleOption.RoundOff) + .SetParameter("staff", SettleOption.Staff) + .SetParameter("void", SettleOption.Void) + .SetParameter("tip", SettleOption.Tip) + .List(); + foreach (var item in list) + outList.Add(new TaxAnalysis() { Name = string.Format("{0} - {1:#.##%;(#.##%);0%}", (string)item[0], (decimal)item[1]), TaxRate = (decimal)item[1], TaxAmount = (decimal)item[2], NetSale = (decimal)item[3] }); return outList; } } diff --git a/Tanshu.Accounts.Repository/SettingBI.cs b/Tanshu.Accounts.Repository/SettingBI.cs new file mode 100644 index 0000000..7c2cb09 --- /dev/null +++ b/Tanshu.Accounts.Repository/SettingBI.cs @@ -0,0 +1,10 @@ +using NHibernate; +using Tanshu.Accounts.Entities; + + +namespace Tanshu.Accounts.Repository +{ + public class SettingBI : UnitOfWork + { + } +} diff --git a/Tanshu.Accounts.Repository/SetupStore.cs b/Tanshu.Accounts.Repository/SetupStore.cs index 03e0824..a37f1a0 100644 --- a/Tanshu.Accounts.Repository/SetupStore.cs +++ b/Tanshu.Accounts.Repository/SetupStore.cs @@ -119,7 +119,9 @@ namespace Tanshu.Accounts.Repository typeof(PrintLocationMap), typeof(TaxMap), typeof(VoucherSettlementMap), - typeof(FoodTableMap) + typeof(FoodTableMap), + typeof(MachineLocationMap), + typeof(SettingMap) }; mapper.AddMappings(entities); var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities(); diff --git a/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj b/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj index d830f07..5b20478 100644 --- a/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj +++ b/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj @@ -65,6 +65,8 @@ + +