narsil/Tanshu.Accounts.BI/VoucherBI.cs

203 lines
7.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.SqlDAO;
namespace Tanshu.Accounts.BI
{
public class VoucherBI
{
public VoucherBO Insert(VoucherBO voucher)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
{
using (var idao = new SqlDAO.InventoryDAO(connection))
{
using (var advdao = new SqlDAO.AdvanceDAO(connection))
{
connection.BeginTransaction();
voucher.Date = null;
vdao.Insert(voucher);
foreach (var i in voucher.Inventories)
{
i.VoucherID = voucher.VoucherID;
idao.Insert(i);
}
if (voucher.AdvanceID.HasValue)
advdao.Adjust(voucher.AdvanceID.Value, CurrentUser.user.UserID);
connection.CommitTransaction();
return GetVoucher(voucher.VoucherID);
}
}
}
}
}
public VoucherBO Update(VoucherBO voucher)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
{
using (var idao = new SqlDAO.InventoryDAO(connection))
{
using (var advdao = new SqlDAO.AdvanceDAO(connection))
{
connection.BeginTransaction();
vdao.Update(voucher);
idao.Delete(voucher.VoucherID);
foreach (InventoryBO i in voucher.Inventories)
{
i.VoucherID = voucher.VoucherID;
idao.Insert(i);
}
if (voucher.AdvanceID.HasValue)
advdao.Adjust(voucher.AdvanceID.Value, CurrentUser.user.UserID);
connection.CommitTransaction();
return GetVoucher(voucher.VoucherID);
}
}
}
}
}
public VoucherBO GetVoucher(Guid voucherID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
{
var voucher = new VoucherBO();
voucher = vdao.GetVoucher(voucherID);
return FillVoucher(voucher, connection);
}
}
}
public VoucherBO GetVoucher(string billID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
{
var voucher = new VoucherBO();
voucher = vdao.GetVoucher(billID);
return FillVoucher(voucher, connection);
}
}
}
private VoucherBO FillVoucher(VoucherBO voucher, SqlConnectionDAO connection)
{
using (var idao = new SqlDAO.InventoryDAO(connection))
{
using (var adao = new SqlDAO.AdvanceDAO(connection))
{
using (var wdao = new SqlDAO.WaiterDAO(connection))
{
using (var udao = new SqlDAO.UserDAO(connection))
{
using (var cdao = new SqlDAO.CustomerDAO(connection))
{
voucher.Inventories = idao.GetInventories(voucher.VoucherID);
if (voucher.AdvanceID.HasValue)
voucher.Advance = adao.Get(voucher.AdvanceID.Value);
voucher.Waiter = wdao.GetWaiter(voucher.WaiterID);
voucher.User = udao.GetUser(voucher.UserID);
voucher.Customer = cdao.GetCustomer(voucher.CustomerID);
return voucher;
}
}
}
}
}
}
public List<PendingBillsBO> GetPendingBills(PendingType list, int floor)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.VoucherDAO(connection))
{
return dao.GetPendingBills(list, floor);
}
}
}
public Guid? GetPendingVoucherID(string tableID, int floor)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.VoucherDAO(connection))
{
return dao.GetPendingVoucherID(tableID, floor);
}
}
}
public List<InventoryBO> SaleInventory(Dictionary<BillItemKey, SalesBillItemBO>.ValueCollection list, Guid? voucherID)
{
var localList = new Dictionary<Guid, InventoryBO>();
foreach (var item in list)
{
var temp = new InventoryBO();
if (localList.ContainsKey(item.productID))
{
temp = localList[item.productID];
temp.Quantity += item.Quantity;
}
else
{
if (voucherID.HasValue)
temp.VoucherID = voucherID.Value;
temp.InventoryID = Guid.NewGuid();
temp.Discount = item.Discount;
temp.ProductID = item.productID;
temp.Quantity = item.Quantity;
temp.Rate = item.Price;
temp.Vat = item.Vat;
temp.ServiceTax = item.ServiceTax;
localList.Add(item.productID, temp);
}
}
var outList = new List<InventoryBO>();
foreach (var item in localList)
outList.Add(item.Value);
return outList;
}
public void SetAlarm(Guid voucherID, DateTime? alarmTime)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.VoucherDAO(connection))
{
dao.SetAlarm(voucherID, alarmTime);
}
}
}
public void VoidBill(Guid voucherID, string reason, Guid userID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.VoucherDAO(connection))
{
dao.VoidBill(voucherID, reason, userID);
}
}
}
public void DeclareBillsPaid(Guid userID, List<Guid> billList, PaidStatus paidStatus)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.VoucherDAO(connection))
{
dao.DeclareBillsPaid(userID, billList, paidStatus);
}
}
}
}
}