Regression: BillItemKey added the compare methods back
Regression: PrintLocation added the compare methods back Breaking: Kot.Code is now integers Breaking: Kot Update is now via Stored Procedure to get DB Values Breaking: Reprints Insert is now via Stored Procedure to get DV Values Breaking: Voucher.BillID and KotID are now integers Breaking: Voucher Insert/Update is now via Stored Procedures to get DV Values also Dirty Checking for Voucher has been overwritten to set dirty for LastEditDate update Fix: Login forms simplified Feature: PrintLocation and Products are cached application wide.
This commit is contained in:
67
Tanshu.Accounts.Repository/Cache.cs
Normal file
67
Tanshu.Accounts.Repository/Cache.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class Cache
|
||||
{
|
||||
private static IList<ProductGroup> cache = null;
|
||||
private static Dictionary<int, PrintLocation> locations = new Dictionary<int, PrintLocation>();
|
||||
private static string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
|
||||
public static IList<ProductGroup> ProductGroups()
|
||||
{
|
||||
if (cache == null)
|
||||
{
|
||||
using (var bi = new ProductGroupBI())
|
||||
{
|
||||
var list = bi.SaleList();
|
||||
foreach (var item in list)
|
||||
{
|
||||
NHibernateUtil.Initialize(item.Products);
|
||||
}
|
||||
cache = 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()];
|
||||
}
|
||||
public static void Invalidate()
|
||||
{
|
||||
cache = null;
|
||||
locations = new Dictionary<int, PrintLocation>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class DbValues
|
||||
{
|
||||
public static DateTime Date
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var query = session.CreateSQLQuery("SELECT Getdate();");
|
||||
return (DateTime)query.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string KotID
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"SELECT ISNULL('K-' + CAST(MAX(CAST(SUBSTRING(KotID, 3,8) AS int)) + 1 AS nvarchar(8)), 'K-1') FROM Vouchers";
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string KotCode
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"SELECT ISNULL('S-' + CAST(MAX(CAST(SUBSTRING(Code, 3,8) AS int)) + 1 AS nvarchar(8)), 'S-1') FROM Kots";
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string BillID(VoucherType voucherType)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var query = "";
|
||||
switch (voucherType)
|
||||
{
|
||||
case VoucherType.Regular:
|
||||
case VoucherType.TakeAway:
|
||||
query = @"
|
||||
DECLARE @BillID nvarchar(10)
|
||||
SELECT @BillID = ISNULL(CAST(MAX(CAST(REPLACE(BillID, '-', '') AS int)) + 1 AS nvarchar(9)), '010001') FROM Vouchers WHERE BillID LIKE '__-____'
|
||||
AND BillID NOT LIKE 'NC-%' AND BillID NOT LIKE 'ST-%'
|
||||
IF LEN(@BillID) = 5
|
||||
SET @BillID = '0' + @BillID
|
||||
SET @BillID = SUBSTRING(@BillID, 1, 2) + '-' + SUBSTRING(@BillID, 3, 7)
|
||||
IF SUBSTRING(@BillID,3,7) = '-0000'
|
||||
SET @BillID = SUBSTRING(@BillID, 1, 2) + '-0001'
|
||||
SELECT @BillID";
|
||||
break;
|
||||
case VoucherType.NoCharge:
|
||||
query = @"SELECT ISNULL('NC-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'NC-1') FROM Vouchers WHERE BillID LIKE 'NC-%'";
|
||||
break;
|
||||
case VoucherType.Staff:
|
||||
query = @"SELECT ISNULL('ST-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'ST-1') FROM Vouchers WHERE BillID LIKE 'ST-%'";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("voucherType");
|
||||
}
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,20 +143,21 @@ order by v.Date desc
|
||||
.SetParameter("staff", VoucherType.Staff)
|
||||
.SetMaxResults(1)
|
||||
.UniqueResult();
|
||||
var newID = lastBill == null ? "01-0001" : GetNewID((string)lastBill);
|
||||
var newID = lastBill == null ? 10001 : GetNewID((int)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.BillID = newID;
|
||||
throw new NotImplementedException();
|
||||
//voucher.BillID = newID;
|
||||
_session.Update(voucher);
|
||||
}
|
||||
newID = GetNewID(newID);
|
||||
}
|
||||
|
||||
query = @"
|
||||
select v.BillID
|
||||
select isnull(v.BillID + 1, 1)
|
||||
from Voucher v
|
||||
where v.Date < :startDate and v.Void = false and v.VoucherType = :nc
|
||||
order by v.Date desc
|
||||
@ -167,53 +168,26 @@ order by v.Date desc
|
||||
.SetParameter("nc", VoucherType.NoCharge)
|
||||
.SetMaxResults(1)
|
||||
.UniqueResult();
|
||||
newID = lastBill == null ? "NC-1" : GetNewNc((string)lastBill);
|
||||
newID = (int)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.BillID = newID;
|
||||
throw new NotImplementedException();
|
||||
//voucher.BillID = newID;
|
||||
_session.Update(voucher);
|
||||
}
|
||||
newID = GetNewNc(newID);
|
||||
newID += 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetNewNc(string lastBill)
|
||||
private static int GetNewID(int 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);
|
||||
lastBill += 1;
|
||||
if (lastBill % 10000 == 0)
|
||||
lastBill += 1;
|
||||
return lastBill;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,31 +1,8 @@
|
||||
using System.Configuration;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using System;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class PrintLocationBI : UnitOfWork<PrintLocation>
|
||||
{
|
||||
public static PrintLocation BasePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
{
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static PrintLocation KotPrinter(Guid productGroupID)
|
||||
{
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
{
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ??
|
||||
bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using NHibernate;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate.Transform;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -17,12 +19,29 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
public new IList<ProductGroup> List(Expression<Func<ProductGroup, bool>> query)
|
||||
{
|
||||
_session.FlushMode = FlushMode.Never;
|
||||
return _session.QueryOver<ProductGroup>()
|
||||
.Where(query)
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
}
|
||||
public IList<ProductGroup> SaleList()
|
||||
{
|
||||
ProductGroup pgAlias = null;
|
||||
Product pAlias = null;
|
||||
ICriterion isActive = Restrictions.Where<Product>(x => x.IsActive);
|
||||
|
||||
return _session.QueryOver<ProductGroup>(() => pgAlias)
|
||||
.Left.JoinAlias(x => x.Products, () => pAlias, isActive)
|
||||
.Where(x => x.IsActive)
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.ThenBy(() => pAlias.SortOrder).Asc
|
||||
.ThenBy(() => pAlias.Name).Asc
|
||||
.TransformUsing(Transformers.DistinctRootEntity)
|
||||
.List();
|
||||
}
|
||||
public IList<string> GetProductGroupTypes()
|
||||
{
|
||||
const string query = @"select distinct(pg.GroupType) from ProductGroup pg order by pg.GroupType";
|
||||
|
||||
145
Tanshu.Accounts.Repository/QueryStore.cs
Normal file
145
Tanshu.Accounts.Repository/QueryStore.cs
Normal file
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using NHibernate;
|
||||
using NHibernate.SqlCommand;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
// Add the following in app settings in the config file to enable logging
|
||||
//<add key="nhibernate-logger" value="Tanshu.Accounts.Repository.EventsLogFactory, Tanshu.Accounts.Repository"/>
|
||||
public class EventsLogger : IInternalLogger
|
||||
{
|
||||
private readonly string _key;
|
||||
public EventsLogger(string key)
|
||||
{
|
||||
_key = key;
|
||||
}
|
||||
public bool IsDebugEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsErrorEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsFatalEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsInfoEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public bool IsWarnEnabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#region Methods (14)
|
||||
|
||||
// Public Methods (14)
|
||||
|
||||
public void Debug(object message)
|
||||
{
|
||||
if (message == null) return;
|
||||
var msg = message.ToString();
|
||||
if (!msg.Contains("oucher") && !_key.Contains("oucher")) return;
|
||||
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
||||
Console.WriteLine(message.ToString().Trim());
|
||||
}
|
||||
|
||||
public void Debug(object message, Exception exception)
|
||||
{
|
||||
if (message == null || exception == null) return;
|
||||
var msg = message.ToString();
|
||||
if (!msg.Contains("oucher") && !_key.Contains("oucher")) return;
|
||||
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
||||
Console.WriteLine(message.ToString().Trim());
|
||||
Console.WriteLine(exception.ToString());
|
||||
}
|
||||
|
||||
public void DebugFormat(string format, params object[] args)
|
||||
{
|
||||
Console.Write(new[]
|
||||
{
|
||||
string.Format("---+ {0} +---", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")),
|
||||
string.Format(format, args),
|
||||
});
|
||||
}
|
||||
|
||||
public void Error(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Error(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void ErrorFormat(string format, params object[] args)
|
||||
{
|
||||
DebugFormat(format, args);
|
||||
}
|
||||
|
||||
public void Fatal(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Fatal(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void Info(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Info(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void InfoFormat(string format, params object[] args)
|
||||
{
|
||||
DebugFormat(format, args);
|
||||
}
|
||||
|
||||
public void Warn(object message)
|
||||
{
|
||||
Debug(message);
|
||||
}
|
||||
|
||||
public void Warn(object message, Exception exception)
|
||||
{
|
||||
Debug(message, exception);
|
||||
}
|
||||
|
||||
public void WarnFormat(string format, params object[] args)
|
||||
{
|
||||
DebugFormat(format, args);
|
||||
}
|
||||
|
||||
#endregion Methods
|
||||
}
|
||||
public class EventsLogFactory : ILoggerFactory
|
||||
{
|
||||
public IInternalLogger LoggerFor(Type type)
|
||||
{
|
||||
return new EventsLogger(type.ToString());
|
||||
}
|
||||
|
||||
public IInternalLogger LoggerFor(string keyName)
|
||||
{
|
||||
return new EventsLogger(keyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -250,7 +250,7 @@ order by v.BillID, s.Settled
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = item.Date,
|
||||
BillID = item.Voucher.BillID,
|
||||
BillID = item.Voucher.BillID.Value.ToString(),
|
||||
Settlement = string.Format("Reprinted by {0}", item.User.Name),
|
||||
Amount = item.Voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1
|
||||
});
|
||||
|
||||
@ -79,7 +79,6 @@ namespace Tanshu.Accounts.Repository
|
||||
db.Driver<NHibernate.Driver.SqlClientDriver>();
|
||||
db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
|
||||
db.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
|
||||
db.ConnectionStringName = "Con";
|
||||
db.Timeout = 10;
|
||||
|
||||
@ -91,8 +90,9 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
var mapping = GetMappings();
|
||||
configure.AddDeserializedMapping(mapping, "NHSchemaTest");
|
||||
SchemaMetadataUpdater.QuoteTableAndColumns(configure);
|
||||
|
||||
//SchemaMetadataUpdater.QuoteTableAndColumns(configure);
|
||||
//configure.SetInterceptor(new NHSQLInterceptor());
|
||||
configure.SetInterceptor(new VoucherDirty());
|
||||
return configure;
|
||||
}
|
||||
private static HbmMapping GetMappings()
|
||||
@ -122,7 +122,6 @@ namespace Tanshu.Accounts.Repository
|
||||
};
|
||||
mapper.AddMappings(entities);
|
||||
var mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
|
||||
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
||||
@ -64,6 +64,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CheckoutBI.cs" />
|
||||
<Compile Include="Cache.cs" />
|
||||
<Compile Include="GroupBI.cs" />
|
||||
<Compile Include="CustomerBI.cs" />
|
||||
<Compile Include="FoodTableBI.cs" />
|
||||
@ -76,6 +77,7 @@
|
||||
<Compile Include="ProductBI.cs" />
|
||||
<Compile Include="ProductGroupBI.cs" />
|
||||
<Compile Include="ProductGroupModifierBI.cs" />
|
||||
<Compile Include="QueryStore.cs" />
|
||||
<Compile Include="ReprintBI.cs" />
|
||||
<Compile Include="RoleBI.cs" />
|
||||
<Compile Include="SalesAnalysisBI.cs" />
|
||||
@ -85,10 +87,10 @@
|
||||
</Compile>
|
||||
<Compile Include="UserBI.cs" />
|
||||
<Compile Include="VoucherBI.cs" />
|
||||
<Compile Include="VoucherDirtyInterceptor.cs" />
|
||||
<Compile Include="VoucherSettlementBI.cs" />
|
||||
<Compile Include="WaiterBI.cs" />
|
||||
<Compile Include="Session.cs" />
|
||||
<Compile Include="DbValues.cs" />
|
||||
<Compile Include="SetupStore.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -21,17 +21,14 @@ namespace Tanshu.Accounts.Repository
|
||||
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Name"]))
|
||||
.List();
|
||||
}
|
||||
public bool ChangePassword(User userData, string newPassword)
|
||||
public void ChangePassword(User user, string password)
|
||||
{
|
||||
var dbUser = Get(x => x.Name == userData.Name && x.Password == userData.Password);
|
||||
if (dbUser == null)
|
||||
return false;
|
||||
dbUser.Password = newPassword;
|
||||
_session.Update(dbUser);
|
||||
return true;
|
||||
user.Password = Tanshu.Common.Md5.Hash(password, "v2");
|
||||
_session.Update(user);
|
||||
}
|
||||
public User ValidateUser(string name, string password)
|
||||
{
|
||||
password = Tanshu.Common.Md5.Hash(password, "v2");
|
||||
return Get(x => x.Name == name && x.Password == password);
|
||||
}
|
||||
public User MsrValidateUser(string msrString)
|
||||
|
||||
@ -13,24 +13,15 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public new Guid Insert(Voucher voucher)
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.CreationDate = dt;
|
||||
voucher.LastEditDate = dt;
|
||||
voucher.Date = dt;
|
||||
voucher.KotID = DbValues.KotID;
|
||||
voucher.BillID = voucher.Printed ? DbValues.BillID(voucher.VoucherType) : voucher.KotID;
|
||||
_session.Save(voucher);
|
||||
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == Guid.Empty))
|
||||
{
|
||||
addedKot = item;
|
||||
item.Voucher = voucher;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.Table = voucher.Table;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
UpdateBillType(voucher);
|
||||
_session.Save(item);
|
||||
foreach (var inv in item.Inventories)
|
||||
@ -70,13 +61,6 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
public new Guid? Update(Voucher voucher)
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.LastEditDate = dt;
|
||||
if (voucher.Date == null)
|
||||
{
|
||||
voucher.Date = dt;
|
||||
voucher.BillID = DbValues.BillID(voucher.VoucherType);
|
||||
}
|
||||
_session.Update(voucher);
|
||||
|
||||
Kot addedKot = null;
|
||||
@ -84,11 +68,9 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
addedKot = item;
|
||||
item.Voucher = voucher;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.Table = voucher.Table;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
_session.Save(item);
|
||||
foreach (var inv in item.Inventories)
|
||||
{
|
||||
@ -285,6 +267,7 @@ namespace Tanshu.Accounts.Repository
|
||||
Update(oldVoucher);
|
||||
|
||||
var status = oldVoucher.Printed ? "printed" : "running";
|
||||
|
||||
var tableFirst = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == first.Table.FoodTableID).SingleOrDefault();
|
||||
if (tableFirst.VoucherID.HasValue)
|
||||
throw new ValidationException("A bill exists on this table, cannot overwrite");
|
||||
|
||||
43
Tanshu.Accounts.Repository/VoucherDirtyInterceptor.cs
Normal file
43
Tanshu.Accounts.Repository/VoucherDirtyInterceptor.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class VoucherDirty : EmptyInterceptor
|
||||
{
|
||||
public override int[] FindDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
|
||||
{
|
||||
var result = new List<int>();
|
||||
|
||||
// we do not care about other entities here
|
||||
if (!(entity is Voucher))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var length = propertyNames.Length;
|
||||
|
||||
// iterate all properties
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
bool areEqual;
|
||||
if (currentState[i] == null)
|
||||
areEqual = previousState[i] == null;
|
||||
else
|
||||
areEqual = currentState[i].Equals(previousState[i]);
|
||||
var isResettingProperty = propertyNames[i] == "LastEditDate";
|
||||
|
||||
if (!areEqual || isResettingProperty)
|
||||
{
|
||||
result.Add(i); // the index of "Code" property will be added always
|
||||
}
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,6 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
}
|
||||
voucher.User = user;
|
||||
voucher.LastEditDate = DbValues.Date;
|
||||
_session.Update(voucher);
|
||||
|
||||
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) == 0 || voucher.Void)
|
||||
|
||||
Reference in New Issue
Block a user