Merge branch 'management'

This commit is contained in:
Tanshu 2013-02-12 18:56:31 +05:30
commit 330d66a7f8
15 changed files with 1568 additions and 497 deletions

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Contracts.Attributes;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.Entities
{

@ -179,7 +179,11 @@ namespace Tanshu.Accounts.PointOfSale
btnDiscountReport.Visible = Session.IsAllowed(RoleConstants.VOID_OR_REPRINTED_BILL_REPORT);
btnChangePassword.Visible = Session.IsAuthenticated;
#if (DEBUG)
btnManagement.Visible = true;
#else
btnManagement.Visible = false;
#endif
}
private void btnGroupRoles_Click(object sender, EventArgs e)
@ -264,12 +268,6 @@ namespace Tanshu.Accounts.PointOfSale
frm.ShowDialog();
}
private void btnManagement_Click(object sender, EventArgs e)
{
using (var frm = new QuantityForm())
frm.ShowDialog();
}
private void btnDiscountReport_Click(object sender, EventArgs e)
{
using (var frm = new DiscountReportForm())
@ -277,6 +275,10 @@ namespace Tanshu.Accounts.PointOfSale
}
private void btnManagement_Click(object sender, EventArgs e)
{
using (var frm = new ManagementForm())
frm.ShowDialog();
}
}
}

@ -55,9 +55,10 @@
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(3, 3);
this.btnLogin.Location = new System.Drawing.Point(4, 4);
this.btnLogin.Margin = new System.Windows.Forms.Padding(4);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(150, 100);
this.btnLogin.Size = new System.Drawing.Size(200, 123);
this.btnLogin.TabIndex = 1;
this.btnLogin.Text = "&Login";
this.btnLogin.UseVisualStyleBackColor = true;
@ -65,9 +66,10 @@
//
// btnSale
//
this.btnSale.Location = new System.Drawing.Point(315, 3);
this.btnSale.Location = new System.Drawing.Point(420, 4);
this.btnSale.Margin = new System.Windows.Forms.Padding(4);
this.btnSale.Name = "btnSale";
this.btnSale.Size = new System.Drawing.Size(150, 100);
this.btnSale.Size = new System.Drawing.Size(200, 123);
this.btnSale.TabIndex = 3;
this.btnSale.Text = "&Sale";
this.btnSale.UseVisualStyleBackColor = true;
@ -98,15 +100,17 @@
this.flowLayoutPanel1.Controls.Add(this.btnManagement);
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(792, 537);
this.flowLayoutPanel1.Size = new System.Drawing.Size(1056, 661);
this.flowLayoutPanel1.TabIndex = 0;
//
// btnSwipeLogin
//
this.btnSwipeLogin.Location = new System.Drawing.Point(159, 3);
this.btnSwipeLogin.Location = new System.Drawing.Point(212, 4);
this.btnSwipeLogin.Margin = new System.Windows.Forms.Padding(4);
this.btnSwipeLogin.Name = "btnSwipeLogin";
this.btnSwipeLogin.Size = new System.Drawing.Size(150, 100);
this.btnSwipeLogin.Size = new System.Drawing.Size(200, 123);
this.btnSwipeLogin.TabIndex = 2;
this.btnSwipeLogin.Text = "Swipe Login";
this.btnSwipeLogin.UseVisualStyleBackColor = true;
@ -114,9 +118,10 @@
//
// btnCustomer
//
this.btnCustomer.Location = new System.Drawing.Point(471, 3);
this.btnCustomer.Location = new System.Drawing.Point(628, 4);
this.btnCustomer.Margin = new System.Windows.Forms.Padding(4);
this.btnCustomer.Name = "btnCustomer";
this.btnCustomer.Size = new System.Drawing.Size(150, 100);
this.btnCustomer.Size = new System.Drawing.Size(200, 123);
this.btnCustomer.TabIndex = 4;
this.btnCustomer.Text = "Customers";
this.btnCustomer.UseVisualStyleBackColor = true;
@ -124,9 +129,10 @@
//
// btnProduct
//
this.btnProduct.Location = new System.Drawing.Point(627, 3);
this.btnProduct.Location = new System.Drawing.Point(836, 4);
this.btnProduct.Margin = new System.Windows.Forms.Padding(4);
this.btnProduct.Name = "btnProduct";
this.btnProduct.Size = new System.Drawing.Size(150, 100);
this.btnProduct.Size = new System.Drawing.Size(200, 123);
this.btnProduct.TabIndex = 5;
this.btnProduct.Text = "Products";
this.btnProduct.UseVisualStyleBackColor = true;
@ -134,9 +140,10 @@
//
// btnProductGroup
//
this.btnProductGroup.Location = new System.Drawing.Point(3, 109);
this.btnProductGroup.Location = new System.Drawing.Point(4, 135);
this.btnProductGroup.Margin = new System.Windows.Forms.Padding(4);
this.btnProductGroup.Name = "btnProductGroup";
this.btnProductGroup.Size = new System.Drawing.Size(150, 100);
this.btnProductGroup.Size = new System.Drawing.Size(200, 123);
this.btnProductGroup.TabIndex = 6;
this.btnProductGroup.Text = "Product Groups";
this.btnProductGroup.UseVisualStyleBackColor = true;
@ -144,9 +151,10 @@
//
// btnOpenBill
//
this.btnOpenBill.Location = new System.Drawing.Point(159, 109);
this.btnOpenBill.Location = new System.Drawing.Point(212, 135);
this.btnOpenBill.Margin = new System.Windows.Forms.Padding(4);
this.btnOpenBill.Name = "btnOpenBill";
this.btnOpenBill.Size = new System.Drawing.Size(150, 100);
this.btnOpenBill.Size = new System.Drawing.Size(200, 123);
this.btnOpenBill.TabIndex = 7;
this.btnOpenBill.Text = "Open Bill";
this.btnOpenBill.UseVisualStyleBackColor = true;
@ -154,9 +162,10 @@
//
// btnAdvanceReceive
//
this.btnAdvanceReceive.Location = new System.Drawing.Point(315, 109);
this.btnAdvanceReceive.Location = new System.Drawing.Point(420, 135);
this.btnAdvanceReceive.Margin = new System.Windows.Forms.Padding(4);
this.btnAdvanceReceive.Name = "btnAdvanceReceive";
this.btnAdvanceReceive.Size = new System.Drawing.Size(150, 100);
this.btnAdvanceReceive.Size = new System.Drawing.Size(200, 123);
this.btnAdvanceReceive.TabIndex = 8;
this.btnAdvanceReceive.Text = "Receive Advance";
this.btnAdvanceReceive.UseVisualStyleBackColor = true;
@ -164,9 +173,10 @@
//
// btnAdvanceAdjust
//
this.btnAdvanceAdjust.Location = new System.Drawing.Point(471, 109);
this.btnAdvanceAdjust.Location = new System.Drawing.Point(628, 135);
this.btnAdvanceAdjust.Margin = new System.Windows.Forms.Padding(4);
this.btnAdvanceAdjust.Name = "btnAdvanceAdjust";
this.btnAdvanceAdjust.Size = new System.Drawing.Size(150, 100);
this.btnAdvanceAdjust.Size = new System.Drawing.Size(200, 123);
this.btnAdvanceAdjust.TabIndex = 9;
this.btnAdvanceAdjust.Text = "Adjust Advance";
this.btnAdvanceAdjust.UseVisualStyleBackColor = true;
@ -174,9 +184,10 @@
//
// btnCreateUser
//
this.btnCreateUser.Location = new System.Drawing.Point(627, 109);
this.btnCreateUser.Location = new System.Drawing.Point(836, 135);
this.btnCreateUser.Margin = new System.Windows.Forms.Padding(4);
this.btnCreateUser.Name = "btnCreateUser";
this.btnCreateUser.Size = new System.Drawing.Size(150, 100);
this.btnCreateUser.Size = new System.Drawing.Size(200, 123);
this.btnCreateUser.TabIndex = 10;
this.btnCreateUser.Text = "Create User";
this.btnCreateUser.UseVisualStyleBackColor = true;
@ -184,9 +195,10 @@
//
// btnUserRoles
//
this.btnUserRoles.Location = new System.Drawing.Point(3, 215);
this.btnUserRoles.Location = new System.Drawing.Point(4, 266);
this.btnUserRoles.Margin = new System.Windows.Forms.Padding(4);
this.btnUserRoles.Name = "btnUserRoles";
this.btnUserRoles.Size = new System.Drawing.Size(150, 100);
this.btnUserRoles.Size = new System.Drawing.Size(200, 123);
this.btnUserRoles.TabIndex = 11;
this.btnUserRoles.Text = "Manage User Roles";
this.btnUserRoles.UseVisualStyleBackColor = true;
@ -194,9 +206,10 @@
//
// btnGroupRoles
//
this.btnGroupRoles.Location = new System.Drawing.Point(159, 215);
this.btnGroupRoles.Location = new System.Drawing.Point(212, 266);
this.btnGroupRoles.Margin = new System.Windows.Forms.Padding(4);
this.btnGroupRoles.Name = "btnGroupRoles";
this.btnGroupRoles.Size = new System.Drawing.Size(150, 100);
this.btnGroupRoles.Size = new System.Drawing.Size(200, 123);
this.btnGroupRoles.TabIndex = 12;
this.btnGroupRoles.Text = "Manage Group Roles";
this.btnGroupRoles.UseVisualStyleBackColor = true;
@ -204,9 +217,10 @@
//
// btnCashierCheckout
//
this.btnCashierCheckout.Location = new System.Drawing.Point(315, 215);
this.btnCashierCheckout.Location = new System.Drawing.Point(420, 266);
this.btnCashierCheckout.Margin = new System.Windows.Forms.Padding(4);
this.btnCashierCheckout.Name = "btnCashierCheckout";
this.btnCashierCheckout.Size = new System.Drawing.Size(150, 100);
this.btnCashierCheckout.Size = new System.Drawing.Size(200, 123);
this.btnCashierCheckout.TabIndex = 13;
this.btnCashierCheckout.Text = "Cashier Checkout";
this.btnCashierCheckout.UseVisualStyleBackColor = true;
@ -214,9 +228,10 @@
//
// btnSaleAnalysis
//
this.btnSaleAnalysis.Location = new System.Drawing.Point(471, 215);
this.btnSaleAnalysis.Location = new System.Drawing.Point(628, 266);
this.btnSaleAnalysis.Margin = new System.Windows.Forms.Padding(4);
this.btnSaleAnalysis.Name = "btnSaleAnalysis";
this.btnSaleAnalysis.Size = new System.Drawing.Size(150, 100);
this.btnSaleAnalysis.Size = new System.Drawing.Size(200, 123);
this.btnSaleAnalysis.TabIndex = 14;
this.btnSaleAnalysis.Text = "Sale Analysis";
this.btnSaleAnalysis.UseVisualStyleBackColor = true;
@ -224,9 +239,10 @@
//
// btnSaleDetail
//
this.btnSaleDetail.Location = new System.Drawing.Point(627, 215);
this.btnSaleDetail.Location = new System.Drawing.Point(836, 266);
this.btnSaleDetail.Margin = new System.Windows.Forms.Padding(4);
this.btnSaleDetail.Name = "btnSaleDetail";
this.btnSaleDetail.Size = new System.Drawing.Size(150, 100);
this.btnSaleDetail.Size = new System.Drawing.Size(200, 123);
this.btnSaleDetail.TabIndex = 15;
this.btnSaleDetail.Text = "Sale Detail";
this.btnSaleDetail.UseVisualStyleBackColor = true;
@ -234,9 +250,10 @@
//
// btnBillDetails
//
this.btnBillDetails.Location = new System.Drawing.Point(3, 321);
this.btnBillDetails.Location = new System.Drawing.Point(4, 397);
this.btnBillDetails.Margin = new System.Windows.Forms.Padding(4);
this.btnBillDetails.Name = "btnBillDetails";
this.btnBillDetails.Size = new System.Drawing.Size(150, 100);
this.btnBillDetails.Size = new System.Drawing.Size(200, 123);
this.btnBillDetails.TabIndex = 16;
this.btnBillDetails.Text = "Bill Details";
this.btnBillDetails.UseVisualStyleBackColor = true;
@ -244,9 +261,10 @@
//
// btnVoidOrReprints
//
this.btnVoidOrReprints.Location = new System.Drawing.Point(159, 321);
this.btnVoidOrReprints.Location = new System.Drawing.Point(212, 397);
this.btnVoidOrReprints.Margin = new System.Windows.Forms.Padding(4);
this.btnVoidOrReprints.Name = "btnVoidOrReprints";
this.btnVoidOrReprints.Size = new System.Drawing.Size(150, 100);
this.btnVoidOrReprints.Size = new System.Drawing.Size(200, 123);
this.btnVoidOrReprints.TabIndex = 19;
this.btnVoidOrReprints.Text = "Voids or Reprints";
this.btnVoidOrReprints.UseVisualStyleBackColor = true;
@ -254,9 +272,10 @@
//
// btnDiscountReport
//
this.btnDiscountReport.Location = new System.Drawing.Point(315, 321);
this.btnDiscountReport.Location = new System.Drawing.Point(420, 397);
this.btnDiscountReport.Margin = new System.Windows.Forms.Padding(4);
this.btnDiscountReport.Name = "btnDiscountReport";
this.btnDiscountReport.Size = new System.Drawing.Size(150, 100);
this.btnDiscountReport.Size = new System.Drawing.Size(200, 123);
this.btnDiscountReport.TabIndex = 21;
this.btnDiscountReport.Text = "Discount Report";
this.btnDiscountReport.UseVisualStyleBackColor = true;
@ -264,9 +283,10 @@
//
// btnChangePassword
//
this.btnChangePassword.Location = new System.Drawing.Point(471, 321);
this.btnChangePassword.Location = new System.Drawing.Point(628, 397);
this.btnChangePassword.Margin = new System.Windows.Forms.Padding(4);
this.btnChangePassword.Name = "btnChangePassword";
this.btnChangePassword.Size = new System.Drawing.Size(150, 100);
this.btnChangePassword.Size = new System.Drawing.Size(200, 123);
this.btnChangePassword.TabIndex = 17;
this.btnChangePassword.Text = "Change Password";
this.btnChangePassword.UseVisualStyleBackColor = true;
@ -274,9 +294,10 @@
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(627, 321);
this.btnExit.Location = new System.Drawing.Point(836, 397);
this.btnExit.Margin = new System.Windows.Forms.Padding(4);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(150, 100);
this.btnExit.Size = new System.Drawing.Size(200, 123);
this.btnExit.TabIndex = 18;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
@ -284,20 +305,23 @@
//
// btnManagement
//
this.btnManagement.Location = new System.Drawing.Point(3, 427);
this.btnManagement.Location = new System.Drawing.Point(4, 528);
this.btnManagement.Margin = new System.Windows.Forms.Padding(4);
this.btnManagement.Name = "btnManagement";
this.btnManagement.Size = new System.Drawing.Size(150, 100);
this.btnManagement.Size = new System.Drawing.Size(200, 123);
this.btnManagement.TabIndex = 20;
this.btnManagement.Text = "Mgt";
this.btnManagement.Text = "Management";
this.btnManagement.UseVisualStyleBackColor = true;
this.btnManagement.Click += new System.EventHandler(this.btnManagement_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(792, 537);
this.ClientSize = new System.Drawing.Size(1056, 661);
this.Controls.Add(this.flowLayoutPanel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "MainForm";

@ -0,0 +1,538 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
namespace Tanshu.Accounts.Management
{
public partial class ManagementForm : Form
{
public ManagementForm()
{
InitializeComponent();
}
private void Sale_Analysis_Form_Load(object sender, EventArgs e)
{
dtpStart.Value = DateTime.Today;
dtpFinish.Value = DateTime.Today;
}
private void btnGo_Click(object sender, EventArgs e)
{
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
var beer = Path.Combine(currentDirectory, "beer.csv");
var sale = Path.Combine(currentDirectory, "sale.csv");
var credit = Path.Combine(currentDirectory, "credit.csv");
var error = string.Empty;
if (!File.Exists(beer))
error += "Beer not found! ";
if (!File.Exists(sale))
error += "Sale not found! ";
if (!File.Exists(credit))
error += "Credit not found";
if (!string.IsNullOrEmpty(error))
{
MessageBox.Show(error);
}
else
{
btnGo.Enabled = false;
var beerDates = GetBeer(beer);
var saleDates = GetSale(sale);
var creditDates = GetCredit(credit);
var info = string.Empty;
foreach (var item in saleDates)
{
var startDate = item.StartDate;
var finishDate = item.FinishDate;
Debug.WriteLine("Starting on " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString());
ProcessData(true, startDate, finishDate, item.Sale15 + item.Sale25);
Debug.WriteLine("Starting beer");
ProcessBeer(beerDates, startDate, finishDate);
Debug.WriteLine("Starting sale");
info += ProcessSale(item, creditDates);
Debug.WriteLine("Starting cleanup");
ProcessData(false, startDate, finishDate, item.Sale15 + item.Sale25);
Debug.WriteLine("Cleanup done");
}
MessageBox.Show(info);
btnGo.Enabled = true;
}
}
#region Get Data
protected class SaleData
{
public DateTime StartDate { get; set; }
public DateTime FinishDate { get; set; }
public decimal Sale125 { get; set; }
public decimal Sale25 { get; set; }
public decimal Sale15 { get; set; }
public decimal Sale0 { get; set; }
}
private IEnumerable<SaleData> GetSale(string sale)
{
IFormatProvider culture = new CultureInfo("en-US", true);
var startDate = dtpStart.Value.Date;
var finishDate = dtpFinish.Value.Date;
var dates = new List<SaleData>();
using (var reader = new StreamReader(File.OpenRead(sale)))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
if (values.Length != 6)
{
MessageBox.Show("Error reading line: " + line);
continue;
}
DateTime dateStart;
DateTime dateFinish;
if (!DateTime.TryParseExact(values[0], "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dateStart))
continue;
if (!DateTime.TryParseExact(values[1], "dd-MM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dateFinish))
continue;
if (dateFinish.Date < startDate.Date || dateStart.Date > finishDate.Date)
continue;
dates.Add(new SaleData
{
StartDate = dateStart,
FinishDate = dateFinish,
Sale125 = TryConvert(values[2]),
Sale25 = TryConvert(values[3]),
Sale15 = TryConvert(values[4]),
Sale0 = TryConvert(values[5])
});
}
}
return dates;
}
private Dictionary<DateTime, decimal> GetCredit(string credit)
{
IFormatProvider culture = new CultureInfo("en-US", true);
var startDate = dtpStart.Value.Date.AddHours(7);
var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(7);
var dates = new Dictionary<DateTime, decimal>();
using (var reader = new StreamReader(File.OpenRead(credit)))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
if (values.Length != 2)
{
MessageBox.Show("Error reading line: " + line);
continue;
}
DateTime dateOut;
if (!DateTime.TryParseExact(values[0], "dd/MM/yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out dateOut))
continue;
if (dateOut.Date < startDate.Date || dateOut.Date >= finishDate.Date)
continue;
var amount = TryConvert(values[1]);
if (!dates.ContainsKey(dateOut))
dates.Add(dateOut, amount);
}
}
return dates;
}
private Dictionary<DateTime, decimal> GetBeer(string beer)
{
IFormatProvider culture = new CultureInfo("en-US", true);
var startDate = dtpStart.Value.Date.AddHours(7);
var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(7);
var dates = new Dictionary<DateTime, decimal>();
using (var reader = new StreamReader(File.OpenRead(beer)))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
DateTime dateOut;
if (!DateTime.TryParseExact(values[0], "dd-MMM-yy", culture, DateTimeStyles.NoCurrentDateDefault, out dateOut))
continue;
if (dateOut.Date < startDate.Date || dateOut.Date >= finishDate.Date)
continue;
decimal amount = 0;
if (values.Length > 1) // Dark - Location 1, Basecode 1
amount += TryConvert(values[1]);
if (values.Length > 2) // Wheat - Location 2, Basecode 2
amount += TryConvert(values[2]);
if (values.Length > 3) // Light - Location 3, Basecode 4
amount += TryConvert(values[3]);
if (values.Length > 4) // Premium - Location 4, Basecode 3
amount += TryConvert(values[4]);
dates.Add(dateOut, amount);
}
}
return dates;
}
#endregion
private static void ProcessData(bool opening, DateTime startIn, DateTime finishIn, decimal liqTarget)
{
var startDate = startIn.AddHours(7);
var finishDate = finishIn.AddDays(1).AddHours(7);
if (opening)
{
using (var bi = new ManagementBI())
{
bi.DeleteVoid(startDate, finishDate);
}
using (var bi = new ManagementBI())
{
bi.DeleteStaff(startDate, finishDate);
}
using (var bi = new ManagementBI())
{
bi.ClearModifiers(startDate, finishDate);
}
using (var bi = new ManagementBI())
{
bi.CombineKots(startDate, finishDate);
}
using (var bi = new ManagementBI())
{
bi.RemoveBlankKots(startDate, finishDate);
}
using (var bi = new ManagementBI())
{
bi.MoveNc(startDate, finishDate, liqTarget);
}
}
else
{
using (var bi = new ManagementBI())
{
bi.SetPayments(startDate, finishDate);
}
}
}
private static void ProcessBeer(Dictionary<DateTime, decimal> dates, DateTime startIn, DateTime finishIn)
{
using (var bi = new ManagementBI())
{
var info = string.Empty;
foreach (var item in dates)
{
if (item.Key < startIn || item.Key > finishIn)
continue;
var stDt = item.Key.AddHours(7);
var fiDt = stDt.AddDays(1);
var original = bi.GetQuantity(stDt, fiDt);
if (original < item.Value)
{
info += "Original for " + item.Key.ToString() + " is " + original.ToString() + " desired is " + item.Value.ToString() + "\r\n";
}
else if (original == item.Value)
{
info += item.Key.ToString() + " is " + original.ToString() + " matches!" + "\r\n";
}
else
{
bi.SetQuantity(stDt, fiDt, item.Value);
}
}
}
}
private static string ProcessSale(SaleData item, Dictionary<DateTime, decimal> creditDates)
{
var info = string.Empty;
var startDate = item.StartDate.AddHours(7);
var finishDate = item.FinishDate.AddHours(7).AddDays(1);
var creditInfo = creditDates.Where(x => x.Key >= item.StartDate && x.Key <= item.FinishDate).ToDictionary(x => x.Key, x => x.Value);
info += "From " + startDate.ToShortDateString() + " to " + finishDate.ToShortDateString() + "\r\n";
using (var bi = new ManagementBI())
{
info += "25%\t" + bi.GetFood(.26250M, startDate, finishDate) + "\t";
var ret = bi.SetLiq(.26250M, item.Sale25, startDate, finishDate);
info += ret + "\t" + item.Sale25.ToString() + "\r\n";
}
using (var bi = new ManagementBI())
{
info += "15%\t" + bi.GetFood(.1575M, startDate, finishDate) + "\t";
var ret = bi.SetLiq(.1575M, item.Sale15, startDate, finishDate);
info += ret + "\t" + item.Sale15.ToString() + "\r\n";
}
using (var bi = new ManagementBI())
{
info += "12.5%\t" + bi.GetFood(.13125M, startDate, finishDate) + "\t";
var ret = bi.SetFood(.13125M, item.Sale125, startDate, finishDate);
info += ret + "\t" + item.Sale125.ToString() + "\r\n";
}
using (var bi = new ManagementBI())
{
info += "0%\t" + bi.GetFood(0M, startDate, finishDate) + "\t";
var ret = bi.SetFood(0M, item.Sale0, startDate, finishDate);
info += ret + "\t" + item.Sale0.ToString() + "\r\n";
}
return info;
}
private static decimal TryConvert(string amount)
{
decimal result = 0;
decimal.TryParse(amount, out result);
return result;
}
private void button1_Click(object sender, EventArgs e)
{
var startDate = dtpStart.Value.Date;
var finishDate = dtpFinish.Value.Date;
var daybook = @"
<ENVELOPE>
<HEADER>
<TALLYREQUEST>Import Data</TALLYREQUEST>
</HEADER>
<BODY>
<IMPORTDATA>
<REQUESTDESC>
<REPORTNAME>All Masters</REPORTNAME>
<STATICVARIABLES>
<SVCURRENTCOMPANY>Peitho Foods Pvt. Ltd.(2012-13)</SVCURRENTCOMPANY>
</STATICVARIABLES>
</REQUESTDESC>
<REQUESTDATA>
<TALLYMESSAGE xmlns:UDF=""TallyUDF"">
";
for (var date = startDate; date <= finishDate; date = date.AddDays(1))
{
daybook += GetVoucher(date);
}
daybook += @"
</TALLYMESSAGE>
</REQUESTDATA>
</IMPORTDATA>
</BODY>
</ENVELOPE>
";
Clipboard.SetText(daybook, TextDataFormat.Text);
}
private static string GetVoucher(DateTime date)
{
var currentStart = date.AddHours(7);
var currentFinish = date.AddDays(1).AddHours(7);
var voucher = string.Empty;
var cash = 0M;
using (var bi = new ManagementBI())
{
var sale = Math.Round(bi.GetFood(.26250M, currentStart, currentFinish));
var vat = 0M;
if (sale != 0)
{
cash += sale;
voucher += GetLedger("Sale @ 25 %", sale.ToString("#0.00"));
vat = Math.Round(bi.GetVat(.26250M, currentStart, currentFinish));
cash += vat;
voucher += GetLedger("Output Vat @ 25%", vat.ToString("#0.00"));
}
sale = Math.Round(bi.GetFood(.1575M, currentStart, currentFinish));
if (sale != 0)
{
cash += sale;
voucher += GetLedger("Sale @ 15%", sale.ToString("#0.00"));
vat = Math.Round(bi.GetVat(.1575M, currentStart, currentFinish));
cash += vat;
voucher += GetLedger("Output Vat @ 15%", vat.ToString("#0.00"));
}
sale = Math.Round(bi.GetFood(.13125M, currentStart, currentFinish));
if (sale != 0)
{
cash += sale;
voucher += GetLedger("Sale 12.5%", sale.ToString("#0.00"));
vat = Math.Round(bi.GetVat(.13125M, currentStart, currentFinish));
cash += vat;
voucher += GetLedger("Output Vat 12.5%", vat.ToString("#0.00"));
}
sale = Math.Round(bi.GetFood(0M, currentStart, currentFinish));
if (sale != 0)
{
cash += sale;
voucher += GetLedger("Sale Tax Free", sale.ToString("#0.00"));
}
vat = Math.Round(bi.GetServiceTax(currentStart, currentFinish));
if (vat != 0)
{
cash += vat;
voucher += GetLedger("Central Service Tax@3.708%", vat.ToString("#0.00"));
}
if (cash != 0)
{
voucher = GetLedger("Cash", cash.ToString("#0.00")) + voucher;
}
}
return voucher != "" ? GetVoucher(date.ToString("yyyyMMdd"), voucher) : "";
}
private static string GetVoucher(string date, string ledgers)
{
#region Voucher Template
var template = @"
<VOUCHER REMOTEID=""{0}"" VCHTYPE=""Journal"" ACTION=""Create"">
<DATE>{1}</DATE>
<GUID>{0}</GUID>
<VOUCHERTYPENAME>Journal</VOUCHERTYPENAME>
<VOUCHERNUMBER>349</VOUCHERNUMBER>
<PARTYLEDGERNAME>Cash</PARTYLEDGERNAME>
<CSTFORMISSUETYPE/>
<CSTFORMRECVTYPE/>
<FBTPAYMENTTYPE>Default</FBTPAYMENTTYPE>
<VCHGSTCLASS/>
<ENTEREDBY>Admin</ENTEREDBY>
<DIFFACTUALQTY>No</DIFFACTUALQTY>
<AUDITED>No</AUDITED>
<FORJOBCOSTING>No</FORJOBCOSTING>
<ISOPTIONAL>No</ISOPTIONAL>
<EFFECTIVEDATE>{1}</EFFECTIVEDATE>
<USEFORINTEREST>No</USEFORINTEREST>
<USEFORGAINLOSS>No</USEFORGAINLOSS>
<USEFORGODOWNTRANSFER>No</USEFORGODOWNTRANSFER>
<USEFORCOMPOUND>No</USEFORCOMPOUND>
<ALTERID> 3525</ALTERID>
<EXCISEOPENING>No</EXCISEOPENING>
<ISCANCELLED>No</ISCANCELLED>
<HASCASHFLOW>Yes</HASCASHFLOW>
<ISPOSTDATED>No</ISPOSTDATED>
<USETRACKINGNUMBER>No</USETRACKINGNUMBER>
<ISINVOICE>No</ISINVOICE>
<MFGJOURNAL>No</MFGJOURNAL>
<HASDISCOUNTS>No</HASDISCOUNTS>
<ASPAYSLIP>No</ASPAYSLIP>
<ISDELETED>No</ISDELETED>
<ASORIGINAL>No</ASORIGINAL>
{2}
</VOUCHER>
";
var servicetaxtemplate = @"";
#endregion
return string.Format(template, Guid.NewGuid(), date, ledgers);
}
private static string GetLedger(string ledgername, string amount)
{
var isDeemedPositive = string.Empty;
var isPartyLedger = string.Empty;
switch (ledgername)
{
case "Cash":
isDeemedPositive = "Yes";
isPartyLedger = "Yes";
amount = "-" + amount;
break;
case "Sale 12.5%":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Sale @ 15%":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Sale @ 25 %":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Sale Tax Free":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Output Vat 12.5%":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Output Vat @ 15%":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Output Vat @ 25%":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
case "Central Service Tax@3.708%":
isDeemedPositive = "No";
isPartyLedger = "No";
break;
}
#region Voucher Template
const string template = @"
<ALLLEDGERENTRIES.LIST>
<LEDGERNAME>{0}</LEDGERNAME>
<GSTCLASS/>
<ISDEEMEDPOSITIVE>{1}</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISPARTYLEDGER>{2}</ISPARTYLEDGER>
<AMOUNT>{3}</AMOUNT>
</ALLLEDGERENTRIES.LIST>
";
var servicetaxtemplate = @"";
#endregion
return string.Format(template, ledgername, isDeemedPositive, isPartyLedger, amount);
}
private void button2_Click(object sender, EventArgs e)
{
using (var bi = new ManagementBI())
{
bi.FinalSanction(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7));
}
}
private void button3_Click(object sender, EventArgs e)
{
button3.Enabled = false;
var startDate = dtpStart.Value.Date;
var finishDate = dtpFinish.Value.Date;
var sheet = "Date\t Bill Start\t Bill Final\t Sale 0%\t Sale 12.5%\t Sale 15%\t Sale 25%\t Vat 12.5%\t Vat 15%\t Vat 25%\t Service Tax\n";
for (var date = startDate; date <= finishDate; date = date.AddDays(1))
{
sheet += GetExcel(date);
}
Clipboard.SetText(sheet, TextDataFormat.Text);
button3.Enabled = true;
}
private static string GetExcel(DateTime date)
{
using (var bi = new ManagementBI())
{
var currentStart = date.AddHours(7);
var currentFinish = date.AddDays(1).AddHours(7);
var cash = bi.GetFirstBill(date);
if (cash == "")
return "";
cash = string.Format("{0:dd-MMM-yyyy}\t'{1}\t'{2}\t", date, cash, bi.GetLastBill(date));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(0M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(.13125M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(.1575M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetFood(.2625M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetVat(.13125M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetVat(.1575M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\t", Math.Round(bi.GetVat(.2625M, currentStart, currentFinish)));
cash += string.Format("{0:#0}\n", Math.Round(bi.GetServiceTax(currentStart, currentFinish)));
return cash;
}
}
}
}

@ -0,0 +1,148 @@
namespace Tanshu.Accounts.Management
{
partial class ManagementForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dtpFinish = new System.Windows.Forms.DateTimePicker();
this.dtpStart = new System.Windows.Forms.DateTimePicker();
this.label10 = new System.Windows.Forms.Label();
this.btnGo = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// dtpFinish
//
this.dtpFinish.CustomFormat = "dd-MMM-yyyy";
this.dtpFinish.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dtpFinish.Location = new System.Drawing.Point(224, 15);
this.dtpFinish.Margin = new System.Windows.Forms.Padding(4);
this.dtpFinish.Name = "dtpFinish";
this.dtpFinish.Size = new System.Drawing.Size(119, 22);
this.dtpFinish.TabIndex = 21;
//
// dtpStart
//
this.dtpStart.CustomFormat = "dd-MMM-yyyy";
this.dtpStart.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.dtpStart.Location = new System.Drawing.Point(16, 15);
this.dtpStart.Margin = new System.Windows.Forms.Padding(4);
this.dtpStart.Name = "dtpStart";
this.dtpStart.Size = new System.Drawing.Size(119, 22);
this.dtpStart.TabIndex = 20;
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(144, 20);
this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(72, 17);
this.label10.TabIndex = 22;
this.label10.Text = "<- Date ->";
//
// btnGo
//
this.btnGo.Enabled = false;
this.btnGo.Location = new System.Drawing.Point(16, 255);
this.btnGo.Margin = new System.Windows.Forms.Padding(4);
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(200, 28);
this.btnGo.TabIndex = 24;
this.btnGo.Text = "Go";
this.btnGo.UseVisualStyleBackColor = true;
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 255);
this.button1.Margin = new System.Windows.Forms.Padding(4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(200, 28);
this.button1.TabIndex = 25;
this.button1.Text = "Tally";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 219);
this.button2.Margin = new System.Windows.Forms.Padding(4);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(200, 28);
this.button2.TabIndex = 26;
this.button2.Text = "Final Sanction";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(224, 219);
this.button3.Margin = new System.Windows.Forms.Padding(4);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(200, 28);
this.button3.TabIndex = 27;
this.button3.Text = "Excel";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// ManagementForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(479, 298);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.btnGo);
this.Controls.Add(this.dtpFinish);
this.Controls.Add(this.dtpStart);
this.Controls.Add(this.label10);
this.Margin = new System.Windows.Forms.Padding(4);
this.MaximizeBox = false;
this.Name = "ManagementForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sale Analysis Form";
this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.DateTimePicker dtpFinish;
private System.Windows.Forms.DateTimePicker dtpStart;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Button btnGo;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
}
}

@ -1,116 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.Management
{
public partial class QuantityForm : Form
{
public QuantityForm()
{
InitializeComponent();
}
private void ShowStatement()
{
}
private void Sale_Analysis_Form_Load(object sender, EventArgs e)
{
dtpStart.Value = DateTime.Today;
dtpFinish.Value = DateTime.Today;
}
private void btnGo_Click(object sender, EventArgs e)
{
int baseCode = 0;
if (rbLight.Checked)
{
baseCode = 1;
}
else if (rbPremium.Checked)
{
baseCode = 2;
}
else if (rbWheat.Checked)
{
baseCode = 3;
}
else if (rbDark.Checked)
{
baseCode = 4;
}
else if (rbFestival.Checked)
{
baseCode = 5;
}
dtpStart.Value = dtpStart.Value.Date.AddHours(7);
dtpFinish.Value = dtpFinish.Value.Date.AddDays(1).AddHours(7);
var quantity = GetQuantity(baseCode);
var newQuantity = Convert.ToDecimal(txtQuantity.Text);
if (MessageBox.Show(quantity.ToString(), "Quantity of Beer", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes && quantity > newQuantity)
{
MessageBox.Show(SetQuantity(baseCode, newQuantity).ToString());
}
}
private decimal GetQuantity(int baseCode)
{
using (var bi = new ManagementBI())
return bi.GetQuantity(baseCode, dtpStart.Value, dtpFinish.Value);
}
private decimal SetQuantity(int baseCode, decimal quantity)
{
using (var bi = new ManagementBI())
return bi.SetQuantity(baseCode, quantity, dtpStart.Value, dtpFinish.Value);
}
private void btnGetClipboard_Click(object sender, EventArgs e)
{
//Clipboard format -- Date,BaseCode,Quantity"
var fmtCsv = DataFormats.CommaSeparatedValue;
// read the CSV
var dataobject = Clipboard.GetDataObject();
if (dataobject == null)
{
MessageBox.Show(@"No Data in clipboard");
return;
}
var stream = (System.IO.Stream)dataobject.GetData(fmtCsv);
var enc = new System.Text.UTF8Encoding();
IFormatProvider culture = new CultureInfo("en-US", true);
using (var reader = new System.IO.StreamReader(stream, enc))
{
using (var bi = new ManagementBI())
{
string line;
while ((line = reader.ReadLine()) != null)
{
DateTime startDate;
int baseCode;
decimal quantity;
var data = line.Split(',');
if (!DateTime.TryParseExact(data[0], "dd-MMM-yyyy", culture, DateTimeStyles.NoCurrentDateDefault, out startDate))
continue;
var finishDate = startDate.AddDays(1).AddHours(7);
startDate = startDate.AddHours(7);
if (!int.TryParse(data[1], out baseCode))
continue;
if (baseCode <=0)
continue;
if (!decimal.TryParse(data[2], out quantity))
continue;
bi.SetQuantity(baseCode, quantity, startDate, finishDate);
}
}
}
}
}
}

@ -1,209 +0,0 @@
namespace Tanshu.Accounts.Management
{
partial class QuantityForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dtpFinish = new System.Windows.Forms.DateTimePicker();
this.dtpStart = new System.Windows.Forms.DateTimePicker();
this.label10 = new System.Windows.Forms.Label();
this.flpProducts = new System.Windows.Forms.FlowLayoutPanel();
this.rbLight = new System.Windows.Forms.RadioButton();
this.rbPremium = new System.Windows.Forms.RadioButton();
this.rbWheat = new System.Windows.Forms.RadioButton();
this.rbDark = new System.Windows.Forms.RadioButton();
this.rbFestival = new System.Windows.Forms.RadioButton();
this.txtQuantity = new System.Windows.Forms.TextBox();
this.btnGo = new System.Windows.Forms.Button();
this.btnGetClipboard = new System.Windows.Forms.Button();
this.flpProducts.SuspendLayout();
this.SuspendLayout();
//
// 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;
//
// 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;
//
// 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 ->";
//
// flpProducts
//
this.flpProducts.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.flpProducts.Controls.Add(this.rbLight);
this.flpProducts.Controls.Add(this.rbPremium);
this.flpProducts.Controls.Add(this.rbWheat);
this.flpProducts.Controls.Add(this.rbDark);
this.flpProducts.Controls.Add(this.rbFestival);
this.flpProducts.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flpProducts.Location = new System.Drawing.Point(12, 38);
this.flpProducts.Name = "flpProducts";
this.flpProducts.Size = new System.Drawing.Size(335, 137);
this.flpProducts.TabIndex = 23;
//
// rbLight
//
this.rbLight.AutoSize = true;
this.rbLight.Location = new System.Drawing.Point(3, 3);
this.rbLight.Name = "rbLight";
this.rbLight.Size = new System.Drawing.Size(48, 17);
this.rbLight.TabIndex = 0;
this.rbLight.TabStop = true;
this.rbLight.Text = "Light";
this.rbLight.UseVisualStyleBackColor = true;
//
// rbPremium
//
this.rbPremium.AutoSize = true;
this.rbPremium.Location = new System.Drawing.Point(3, 26);
this.rbPremium.Name = "rbPremium";
this.rbPremium.Size = new System.Drawing.Size(65, 17);
this.rbPremium.TabIndex = 1;
this.rbPremium.TabStop = true;
this.rbPremium.Text = "Premium";
this.rbPremium.UseVisualStyleBackColor = true;
//
// rbWheat
//
this.rbWheat.AutoSize = true;
this.rbWheat.Location = new System.Drawing.Point(3, 49);
this.rbWheat.Name = "rbWheat";
this.rbWheat.Size = new System.Drawing.Size(57, 17);
this.rbWheat.TabIndex = 2;
this.rbWheat.TabStop = true;
this.rbWheat.Text = "Wheat";
this.rbWheat.UseVisualStyleBackColor = true;
//
// rbDark
//
this.rbDark.AutoSize = true;
this.rbDark.Location = new System.Drawing.Point(3, 72);
this.rbDark.Name = "rbDark";
this.rbDark.Size = new System.Drawing.Size(48, 17);
this.rbDark.TabIndex = 3;
this.rbDark.TabStop = true;
this.rbDark.Text = "Dark";
this.rbDark.UseVisualStyleBackColor = true;
//
// rbFestival
//
this.rbFestival.AutoSize = true;
this.rbFestival.Location = new System.Drawing.Point(3, 95);
this.rbFestival.Name = "rbFestival";
this.rbFestival.Size = new System.Drawing.Size(61, 17);
this.rbFestival.TabIndex = 4;
this.rbFestival.TabStop = true;
this.rbFestival.Text = "Festival";
this.rbFestival.UseVisualStyleBackColor = true;
//
// txtQuantity
//
this.txtQuantity.Location = new System.Drawing.Point(12, 181);
this.txtQuantity.Name = "txtQuantity";
this.txtQuantity.Size = new System.Drawing.Size(335, 20);
this.txtQuantity.TabIndex = 5;
//
// btnGo
//
this.btnGo.Location = new System.Drawing.Point(12, 207);
this.btnGo.Name = "btnGo";
this.btnGo.Size = new System.Drawing.Size(150, 23);
this.btnGo.TabIndex = 24;
this.btnGo.Text = "Go";
this.btnGo.UseVisualStyleBackColor = true;
this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
//
// btnGetClipboard
//
this.btnGetClipboard.Location = new System.Drawing.Point(168, 207);
this.btnGetClipboard.Name = "btnGetClipboard";
this.btnGetClipboard.Size = new System.Drawing.Size(179, 23);
this.btnGetClipboard.TabIndex = 25;
this.btnGetClipboard.Text = "Go Clipboard";
this.btnGetClipboard.UseVisualStyleBackColor = true;
this.btnGetClipboard.Click += new System.EventHandler(this.btnGetClipboard_Click);
//
// QuantityForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(359, 242);
this.Controls.Add(this.btnGetClipboard);
this.Controls.Add(this.btnGo);
this.Controls.Add(this.flpProducts);
this.Controls.Add(this.dtpFinish);
this.Controls.Add(this.dtpStart);
this.Controls.Add(this.label10);
this.Controls.Add(this.txtQuantity);
this.MaximizeBox = false;
this.Name = "QuantityForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sale Analysis Form";
this.Load += new System.EventHandler(this.Sale_Analysis_Form_Load);
this.flpProducts.ResumeLayout(false);
this.flpProducts.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.DateTimePicker dtpFinish;
private System.Windows.Forms.DateTimePicker dtpStart;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.FlowLayoutPanel flpProducts;
private System.Windows.Forms.RadioButton rbLight;
private System.Windows.Forms.RadioButton rbPremium;
private System.Windows.Forms.RadioButton rbWheat;
private System.Windows.Forms.RadioButton rbDark;
private System.Windows.Forms.RadioButton rbFestival;
private System.Windows.Forms.TextBox txtQuantity;
private System.Windows.Forms.Button btnGo;
private System.Windows.Forms.Button btnGetClipboard;
}
}

@ -1,14 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Tanshu.Accounts.PointOfSale
{
public class BlockTimer : IDisposable
{
private string _description;
private long _start;
private readonly string _description;
private readonly long _start;
public BlockTimer(string description)
{
@ -18,7 +15,7 @@ namespace Tanshu.Accounts.PointOfSale
public void Dispose()
{
long totalTime = DateTime.Now.Ticks - _start;
var totalTime = DateTime.Now.Ticks - _start;
Console.WriteLine(_description);
Console.Write(" - Total Execution Time: ");
Console.Write(new TimeSpan(totalTime).TotalMilliseconds.ToString());

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
using System.Linq;
namespace Tanshu.Accounts.PointOfSale
{

@ -126,11 +126,11 @@
<Compile Include="CurrencyCounter.Designer.cs">
<DependentUpon>CurrencyCounter.cs</DependentUpon>
</Compile>
<Compile Include="Management\QuantityForm.cs">
<Compile Include="Management\ManagementForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Management\QuantityForm.designer.cs">
<DependentUpon>QuantityForm.cs</DependentUpon>
<Compile Include="Management\ManagementForm.designer.cs">
<DependentUpon>ManagementForm.cs</DependentUpon>
</Compile>
<Compile Include="Products\ProductListForm.cs">
<SubType>Form</SubType>
@ -293,8 +293,8 @@
<EmbeddedResource Include="CurrencyCounter.resx">
<DependentUpon>CurrencyCounter.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Management\QuantityForm.resx">
<DependentUpon>QuantityForm.cs</DependentUpon>
<EmbeddedResource Include="Management\ManagementForm.resx">
<DependentUpon>ManagementForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Products\ProductListForm.resx">
<DependentUpon>ProductListForm.cs</DependentUpon>

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities;
using NHibernate;
namespace Tanshu.Accounts.Repository

@ -1,12 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using NHibernate;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using Tanshu.Data.DAO;
using Tanshu.Common.Helpers;
namespace Tanshu.Accounts.Repository
{
@ -27,56 +25,447 @@ namespace Tanshu.Accounts.Repository
public ManagementBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
#region Cleanup
public void DeleteVoid(DateTime startDate, DateTime finishDate)
{
IList<Voucher> list;
using (var bi = new VoucherBI(Session))
{
list = bi.List(x => x.Date >= startDate && x.Date <= finishDate && x.Void);
}
foreach (var item in list)
{
using (var bi = new VoucherBI())
{
using (var ri = new ReprintBI())
{
ri.DeleteList(x => x.Voucher.VoucherID == item.VoucherID);
bi.Delete(item.VoucherID);
}
}
}
}
public void DeleteStaff(DateTime startDate, DateTime finishDate)
{
IList<Voucher> list;
using (var bi = new VoucherBI(Session))
{
list = bi.List(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.Staff);
}
foreach (var item in list)
{
using (var bi = new VoucherBI())
{
using (var ri = new ReprintBI())
{
ri.DeleteList(x => x.Voucher.VoucherID == item.VoucherID);
bi.Delete(item.VoucherID);
}
}
}
}
public void SetPayments(DateTime startDate, DateTime finishDate)
{
using (var bi = new VoucherBI(Session))
{
var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate);
foreach (var voucher in list)
{
var settlementType = SettleOption.Cash;
switch (voucher.VoucherType)
{
case VoucherType.NoCharge:
settlementType = SettleOption.NoCharge;
break;
case VoucherType.Staff:
settlementType = SettleOption.Staff;
break;
}
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
var roundoff = Math.Round(amount) - amount;
voucher.Settlements.Clear();
voucher.Settlements.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount });
voucher.Settlements.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff });
voucher.Settlements.Add(new VoucherSettlement() { Amount = -1 * (amount + roundoff), Settled = settlementType });
Session.Update(voucher);
}
}
}
public void ClearModifiers(DateTime startDate, DateTime finishDate)
{
using (var bi = new VoucherBI(Session))
{
var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate);
foreach (var voucher in list)
{
foreach (var kot in voucher.Kots)
{
foreach (var inventory in kot.Inventories)
{
if (inventory.InventoryModifier.Count > 0)
inventory.InventoryModifier.Clear();
}
}
Session.Update(voucher);
}
}
}
public void CombineKots(DateTime startDate, DateTime finishDate)
{
using (var bi = new VoucherBI(Session))
{
var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate);
foreach (var voucher in list)
{
if (voucher.Kots.Count == 0)
continue;
var kots = voucher.Kots.OrderBy(x => x.Date);
var kot = kots.First();
for (var kotIndex = kots.Count(); kotIndex > 1; kotIndex--)
{
var otherKot = kots.ElementAt(kotIndex - 1);
for (var i = otherKot.Inventories.Count; i > 0; i--)
{
var inventory = otherKot.Inventories[i - 1];
var oldProduct = kot.Inventories.SingleOrDefault(x => x.Product.ProductID == inventory.Product.ProductID);
if (oldProduct == null)
{
inventory.Kot = kot;
}
else
{
oldProduct.Quantity += inventory.Quantity;
otherKot.Inventories.RemoveAt(i - 1);
}
}
}
Session.Update(voucher);
}
}
}
public void RemoveBlankKots(DateTime startDate, DateTime finishDate)
{
using (var bi = new VoucherBI(Session))
{
var list = bi.List(x => x.Date >= startDate && x.Date <= finishDate);
foreach (var voucher in list)
{
for (var kotIndex = voucher.Kots.Count; kotIndex > 0; kotIndex--)
{
var kot = voucher.Kots[kotIndex - 1];
if (kot.Inventories.Count == 0)
voucher.Kots.RemoveAt(kotIndex - 1);
}
Session.Update(voucher);
}
}
}
public decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate)
public void FinalSanction(DateTime startDate, DateTime finishDate)
{
var query = @"
select v.BillID
from Voucher v
where v.Date < :startDate and v.Void = false and v.VoucherType not in (:nc, :staff)
order by v.Date desc
";
var lastBill = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.SetMaxResults(1)
.UniqueResult();
var newID = lastBill == null ? "01-0001" : GetNewID((string)lastBill);
var list = Session.QueryOver<Voucher>().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff && x.Void == false).OrderBy(x => x.Date).Asc.List();
foreach (var voucher in list)
{
if (voucher.BillID != newID)
{
voucher.SetValue(VoucherFields.BillID, newID);
Session.Update(voucher);
}
newID = GetNewID(newID);
}
query = @"
select v.BillID
from Voucher v
where v.Date < :startDate and v.Void = false and v.VoucherType = :nc
order by v.Date desc
";
lastBill = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("nc", VoucherType.NoCharge)
.SetMaxResults(1)
.UniqueResult();
newID = lastBill == null ? "NC-1" : GetNewNc((string)lastBill);
list = Session.QueryOver<Voucher>().Where(x => x.Date >= startDate && x.Date <= finishDate && x.VoucherType == VoucherType.NoCharge && x.Void == false).OrderBy(x => x.Date).Asc.List();
foreach (var voucher in list)
{
if (voucher.BillID != newID)
{
voucher.SetValue(VoucherFields.BillID, newID);
Session.Update(voucher);
}
newID = GetNewNc(newID);
}
}
private static string GetNewNc(string lastBill)
{
var parts = lastBill.Split('-');
if (parts.Length != 2)
throw new ArgumentOutOfRangeException();
int one;
if (parts[0] != "NC")
throw new ArgumentOutOfRangeException();
if (!int.TryParse(parts[1], out one))
throw new ArgumentOutOfRangeException();
one += 1;
return string.Format("NC-{0}", one);
}
private static string GetNewID(string lastBill)
{
var parts = lastBill.Split('-');
if (parts.Length != 2)
throw new ArgumentOutOfRangeException();
int one, two;
if (!int.TryParse(parts[0], out one))
throw new ArgumentOutOfRangeException();
if (!int.TryParse(parts[1], out two))
throw new ArgumentOutOfRangeException();
if (two >= 9999)
{
one += 1;
two = 1;
}
else
{
two += 1;
}
return string.Format("{0:00}-{1:0000}", one, two);
}
#endregion
public void MoveNc(DateTime startDate, DateTime finishDate, decimal target)
{
const string query = @"
select sum(i.Quantity * p.Quantity) as Quantity
select v.VoucherID, sum(i.Amount)
from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.BaseCode = :baseCode
where v.Date >= :startDate and v.Date <= :finishDate and i.Vat in (.1575, .2625) and v.Void = false and v.VoucherType not in (:nc, :staff)
group by v.VoucherID
order by sum(i.Amount) desc
";
var list = Session
.CreateQuery(query)
.SetParameter("startDate", startDate.AddHours(7))
.SetParameter("finishDate", finishDate.AddDays(1).AddHours(7))
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.List();
var totalAmount = GetFood(.1575M, startDate, finishDate) + GetFood(.2625M, startDate, finishDate);
var skip = false;
for (int i = 0; i < list.Count / 20; i++)
{
if (target / totalAmount > .75M)
break;
skip = !skip;
if (skip)
continue;
var item = (object[])list[i];
var voucherID = (int)item[0];
var amount = (decimal)item[1];
using (var bi = new VoucherBI(Session))
{
var voucher = bi.Get(x => x.VoucherID == voucherID);
voucher.VoucherType = VoucherType.NoCharge;
Session.Update(voucher);
}
totalAmount -= amount;
}
}
public Dictionary<DateTime, decimal> GetLiq(decimal vat, DateTime startDate, DateTime finishDate)
{
const string query = @"
select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) as Amount
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void = false and v.VoucherType not in (:nc, :staff)
";
var dict = new Dictionary<DateTime, decimal>();
for (var date = startDate; date <= finishDate; date = date.AddDays(1))
{
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", date.AddHours(7))
.SetParameter("finishDate", date.AddDays(1).AddHours(7))
.SetParameter("vat", vat)
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.UniqueResult();
dict.Add(date, qty == null ? 0 : (decimal)qty);
}
return dict;
}
public Dictionary<DateTime, decimal> GetGrossSale(DateTime startDate, DateTime finishDate)
{
const string query = @"
select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) * (1 + i.Vat) as Amount
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff)
";
var dict = new Dictionary<DateTime, decimal>();
for (var date = startDate; date <= finishDate; date = date.AddDays(1))
{
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", date.AddHours(7))
.SetParameter("finishDate", date.AddDays(1).AddHours(7))
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.UniqueResult();
dict.Add(date, qty == null ? 0 : (decimal)qty);
}
return dict;
}
public decimal GetVat(decimal vat, DateTime startDate, DateTime finishDate)
{
const string query = @"
select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.Vat) as Amount
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void = false and v.VoucherType not in (:nc, :staff)
";
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("baseCode", baseCode)
.SetParameter("vat", vat)
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.UniqueResult();
return qty == null ? 0 : (decimal)qty;
}
public decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate)
public decimal GetServiceTax(DateTime startDate, DateTime finishDate)
{
var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false));
var current = GetQuantity(baseCode, startDate, finishDate);
const string query = @"
select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTax) as Amount
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff)
";
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.UniqueResult();
return qty == null ? 0 : (decimal)qty;
}
public string GetFirstBill(DateTime date)
{
const string query = @"
select v.BillID
from Voucher v
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff)
order by v.Date
";
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", date.AddHours(7))
.SetParameter("finishDate", date.AddDays(1).AddHours(7))
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.SetMaxResults(1)
.UniqueResult();
return qty == null ? "" : (string)qty;
}
public string GetLastBill(DateTime date)
{
const string query = @"
select v.BillID
from Voucher v
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and v.VoucherType not in (:nc, :staff)
order by v.Date desc
";
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", date.AddHours(7))
.SetParameter("finishDate", date.AddDays(1).AddHours(7))
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.SetMaxResults(1)
.UniqueResult();
return qty == null ? "" : (string)qty;
}
public decimal GetFood(decimal vat, DateTime startDate, DateTime finishDate)
{
const string query = @"
select sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)) as Amount
from Voucher v
inner join v.Kots k
inner join k.Inventories i
where v.Date >= :startDate and v.Date <= :finishDate and i.Vat = :vat and v.Void = false and v.VoucherType not in (:nc, :staff)
";
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.SetParameter("vat", vat)
.SetParameter("nc", VoucherType.NoCharge)
.SetParameter("staff", VoucherType.Staff)
.UniqueResult();
return qty == null ? 0 : (decimal)qty;
}
public decimal SetFood(decimal vat, decimal amount, DateTime startDate, DateTime finishDate)
{
var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff));
var left = GetFood(vat, startDate, finishDate) - amount;
foreach (var item in list)
{
if (current <= quantity)
continue;
if (left <= 0)
break;
foreach (var kot in item.Kots)
{
if (current <= quantity)
continue;
if (left <= 0)
break;
foreach (var inventory in kot.Inventories)
{
if (current <= quantity)
continue;
if (inventory.Product.BaseCode == baseCode)
if (left <= 0)
break;
if (inventory.Vat == vat)
{
using (var bi = new InventoryBI())
{
if (inventory.Quantity * inventory.Product.Quantity > current - quantity)
var inventoryAmount = inventory.Quantity * inventory.Price * (1 - inventory.Discount) *
(1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0));
if (inventoryAmount > left)
{
current = quantity;
inventory.Quantity = (current - quantity) / inventory.Product.Quantity;
var newQuantity = inventory.Quantity * (inventoryAmount - left) / inventoryAmount;
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
i.Quantity = current - quantity;
i.Quantity = newQuantity;
bi.Update(i);
left = 0;
}
else
{
current -= inventory.Quantity * inventory.Product.Quantity;
left -= inventoryAmount;
bi.Delete(x => x.InventoryID == inventory.InventoryID);
}
}
@ -84,77 +473,221 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Ba
}
}
}
return GetQuantity(baseCode, startDate, finishDate);
return GetFood(vat, startDate, finishDate);
}
// public decimal GetBalance(decimal? tax, DateTime startDate, DateTime endDate)
// {
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
// using (IConnectionDAO connection = factory.Connection)
// {
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
// {
// return dao.GetBalance(tax);
// }
// }
// }
// public List<Guid> GetUpdateBillList(decimal tax, bool voided, bool paid, bool creditCard, DateTime startDate, DateTime endDate)
// {
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
// using (IConnectionDAO connection = factory.Connection)
// {
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
// {
// return dao.GetUpdateBillList(tax, voided, paid, creditCard);
// }
// }
// }
// public decimal Update(Guid voucherID, decimal tax, DateTime startDate, DateTime endDate)
// {
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
// using (IConnectionDAO connection = factory.Connection)
// {
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
// {
// return dao.Update(voucherID, tax);
// }
// }
// }
// public void Reorder(DateTime startDate, DateTime endDate, ShowProgessDelegate showProgressDelegate)
// {
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
// using (IConnectionDAO connection = factory.Connection)
// {
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
// {
// dao.Reorder(showProgressDelegate);
// }
// }
// }
public decimal SetLiq(decimal vat, decimal amount, DateTime startDate, DateTime finishDate)
{
var rand = new Random();
var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff));
var left = GetFood(vat, startDate, finishDate) - amount;
foreach (var item in list)
{
if (left <= 0)
break;
foreach (var kot in item.Kots)
{
if (left <= 0)
break;
foreach (var inventory in kot.Inventories)
{
if (left <= 0)
break;
if (inventory.Vat == vat)
{
using (var bi = new InventoryBI())
{
var minimum = inventory.Discount == 0 ? 10 : Convert.ToInt32(inventory.Discount * 100);
if (minimum >= 90)
continue;
var discount = Convert.ToDecimal(rand.Next(minimum, 90)) / 100;
if (discount == inventory.Discount)
continue;
var reduction = inventory.Quantity * inventory.Price *
(1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0)) *
(discount - inventory.Discount);
if (reduction > left)
{
discount = inventory.Quantity * inventory.Price *
(1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0));
discount = left / discount;
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
i.Discount = discount;
bi.Update(i);
left = 0;
}
else
{
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
i.Discount = discount;
bi.Update(i);
left -= reduction;
}
}
}
}
}
}
return GetFood(vat, startDate, finishDate);
}
public decimal SetAmount(int vatID, decimal amount, DateTime startDate, DateTime finishDate)
{
var random = new Random();
var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false && x.VoucherType != VoucherType.NoCharge && x.VoucherType != VoucherType.Staff));
var left = GetFood(vatID, startDate, finishDate) - amount;
foreach (var item in list)
{
if (left <= 0)
break;
var discount = Convert.ToDecimal(random.Next(20, 70));
discount -= discount % 5;
discount = discount / 100;
foreach (var kot in item.Kots)
{
if (left <= 0)
break;
foreach (var inventory in kot.Inventories)
{
if (left <= 0)
break;
if (inventory.Product.Vat.TaxID == vatID)
{
using (var bi = new InventoryBI())
{
if (discount < inventory.Discount)
continue;
var inventoryAmount = inventory.Quantity * inventory.Price * (1 - inventory.Discount) *
(1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0));
var reduction = inventory.Quantity * inventory.Price * (discount - inventory.Discount) *
(1 + (inventory.IsScTaxable ? inventory.ServiceCharge : 0));
if (reduction > left)
{
var newDiscount = (1 - inventory.Discount) * left / inventoryAmount;
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
i.Discount = newDiscount;
bi.Update(i);
left = 0;
}
else
{
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
i.Discount = discount;
bi.Update(i);
left -= reduction;
}
}
}
}
}
}
return GetFood(vatID, startDate, finishDate);
}
public IList GetNcable(DateTime startDate, DateTime finishDate)
{
const string query = @"
select v.VoucherID, sum(case when p.TaxID = 1 then i.ServiceCharge else 0 end) , sum(i.Quantity * p.Quantity) as Quantity
from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
group by p.BaseCode
order by p.BaseCode
";
var list = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.List();
return list;
}
public IList GetMove(DateTime startDate, DateTime finishDate)
{
const string query = @"
select p.BaseCode, sum(i.Quantity * p.Quantity) as Quantity
from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.BaseCode != 0
group by p.BaseCode
order by p.BaseCode
";
var list = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.List();
return list;
}
// public bool MergeData(DateTime startDate, DateTime endDate, string sourceDB, string targetDB)
// {
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
// using (IConnectionDAO connection = factory.Connection)
// {
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
// {
// return dao.MergeData(sourceDB, targetDB);
// }
// }
// }
// public List<PendingBills> GetPaidBills(DateTime startDate, DateTime finishDate)
// {
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
// using (IConnectionDAO connection = factory.Connection)
// {
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, finishDate, connection))
// {
// return dao.GetPaidBills();
// }
// }
// }
#region Beer
public decimal GetQuantity(DateTime startDate, DateTime finishDate)
{
const string query = @"
select sum(i.Quantity * p.Quantity) as Quantity
from Voucher v
inner join v.Kots k
inner join k.Inventories i
inner join i.Product p
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Quantity != 0
";
var qty = Session
.CreateQuery(query)
.SetParameter("startDate", startDate)
.SetParameter("finishDate", finishDate)
.UniqueResult();
return qty == null ? 0 : (decimal)qty;
}
public decimal SetQuantity(DateTime startDate, DateTime finishDate, decimal quantity)
{
var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false));
var left = GetQuantity(startDate, finishDate) - quantity;
foreach (var item in list)
{
if (left <= 0)
break;
foreach (var kot in item.Kots)
{
if (left <= 0)
break;
foreach (var inventory in kot.Inventories)
{
if (left <= 0)
break;
if (inventory.Product.Quantity != 0)
{
using (var bi = new InventoryBI())
{
var inventoryQuantity = inventory.Quantity * inventory.Product.Quantity;
if (inventoryQuantity > left)
{
var newQuantity = inventory.Quantity * (inventoryQuantity - left) / inventoryQuantity;
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
i.Quantity = newQuantity;
bi.Update(i);
left = 0;
}
else
{
left -= inventoryQuantity;
bi.Delete(x => x.InventoryID == inventory.InventoryID);
}
}
}
}
}
}
return GetQuantity(startDate, finishDate);
}
#endregion
#region Helper and Comments
private static IList<T> Randomize<T>(IEnumerable<T> list)
{
var tList = list.ToArray();
@ -168,5 +701,162 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.Ba
}
return tList.ToList();
}
// public decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate)
// {
// const string query = @"
//select sum(i.Quantity * p.Quantity) as Quantity
//from Voucher v
//inner join v.Kots k
//inner join k.Inventories i
//inner join i.Product p
//where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false and p.BaseCode = :baseCode
// ";
// var qty = Session
// .CreateQuery(query)
// .SetParameter("startDate", startDate)
// .SetParameter("finishDate", finishDate)
// .SetParameter("baseCode", baseCode)
// .UniqueResult();
// return qty == null ? 0 : (decimal)qty;
// }
// public decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate)
// {
// var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false));
// var left = GetQuantity(baseCode, startDate, finishDate) - quantity;
// foreach (var item in list)
// {
// if (left <= 0)
// break;
// foreach (var kot in item.Kots)
// {
// if (left <= 0)
// break;
// foreach (var inventory in kot.Inventories)
// {
// if (left <= 0)
// break;
// if (inventory.Product.BaseCode == baseCode)
// {
// using (var bi = new InventoryBI())
// {
// var inventoryQuantity = inventory.Quantity * inventory.Product.Quantity;
// if (inventoryQuantity > left)
// {
// var newQuantity = inventory.Quantity * (inventoryQuantity - left) / inventoryQuantity;
// var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
// i.Quantity = newQuantity;
// bi.Update(i);
// left = 0;
// }
// else
// {
// left -= inventoryQuantity;
// bi.Delete(x => x.InventoryID == inventory.InventoryID);
// }
// }
// }
// }
// }
// }
// return GetQuantity(baseCode, startDate, finishDate);
// }
//private static int GetNewID(int code, int toBaseCode)
//{
// // Name Mug, Pit, H H
// // Dark 301, 305, 384 // BaseCode = 1
// // Wheat 300, 304, 383 // BaseCode = 2
// // Premium 299, 303, 382 // BaseCode = 3
// // Light 297, 302, 363 // BaseCode = 4
// // Dragon 677, 679, 678 // BaseCode = 5
// // Festivals 762 764, 752 // BaseCode = 6
// // Festivals 751, 753, 763 // BaseCode = 6
// // Festivals 734, 736, 587 // BaseCode = 6
// // Festivals 408, 409, 735 // BaseCode = 6
// // Strong 697, 708, 707 // BaseCode = 7
// var list = new List<int> { 301, 300, 299, 297, 677, 762, 751, 734, 408, 697 };
// if (list.Contains(code))
// {
// if (toBaseCode == 1)
// return 301;
// if (toBaseCode == 2)
// return 300;
// if (toBaseCode == 3)
// return 299;
// if (toBaseCode == 4)
// return 297;
// if (toBaseCode == 5)
// return 677;
// if (toBaseCode == 6)
// return code;
// if (toBaseCode == 7)
// return 697;
// }
// list = new List<int> { 305, 304, 303, 302, 679, 764, 753, 736, 409, 708 };
// if (list.Contains(code))
// {
// if (toBaseCode == 1)
// return 305;
// if (toBaseCode == 2)
// return 304;
// if (toBaseCode == 3)
// return 303;
// if (toBaseCode == 4)
// return 302;
// if (toBaseCode == 5)
// return 679;
// if (toBaseCode == 6)
// return code;
// if (toBaseCode == 7)
// return 708;
// }
// list = new List<int> { 384, 383, 382, 363, 678, 752, 763, 587, 735, 707 };
// if (list.Contains(code))
// {
// if (toBaseCode == 1)
// return 384;
// if (toBaseCode == 2)
// return 383;
// if (toBaseCode == 3)
// return 382;
// if (toBaseCode == 4)
// return 363;
// if (toBaseCode == 5)
// return 678;
// if (toBaseCode == 6)
// return code;
// if (toBaseCode == 7)
// return 707;
// }
// return code;
//}
//public void SetMove(int fromBaseCode, int toBaseCode, DateTime startDate, DateTime finishDate)
//{
// var list = new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate);
// using (var bi = new InventoryBI())
// {
// using (var pbi = new ProductBI())
// {
// foreach (var item in list)
// {
// foreach (var kot in item.Kots)
// {
// foreach (var inventory in kot.Inventories)
// {
// if (inventory.Product.BaseCode == fromBaseCode)
// {
// var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
// i.Product = pbi.Get(x => x.ProductID == GetNewID(i.Product.ProductID, toBaseCode));
// GetNewID(i.InventoryID, toBaseCode);
// bi.Update(i);
// }
// }
// }
// }
// }
// }
//}
#endregion
}
}

@ -71,7 +71,7 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units)
else
outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], NC = (decimal)item[1] });
#endregion
#region NC
#region Staff
query = @"
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
from Voucher v

@ -1,4 +1,5 @@
using FluentNHibernate.Automapping;
using System;
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
@ -60,14 +61,20 @@ namespace Tanshu.Accounts.Repository
c.Add<FormulaConvention>();
c.Add<InverseConvention>();
c.Add<PropertyAccessConvention>();
c.Add<EnumConvention>();
c.Add<EnumConvention>();
});
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(p => p.FromConnectionStringWithKey("FluentCon")))
.Mappings(m => m.AutoMappings.Add(persistenceModel))
.BuildConfiguration()
.SetInterceptor(new NHSQLInterceptor());
.ExposeConfiguration(cfg => ApplyAdditionalConfiguration(cfg))
.BuildConfiguration();
//.SetInterceptor(new NHSQLInterceptor());
}
private static void ApplyAdditionalConfiguration(Configuration cfg)
{
var timeout = TimeSpan.FromMinutes(10).TotalSeconds;
cfg.SetProperty("command_timeout", timeout.ToString());
}
private void Init()
{ }