narsil/Tanshu.Accounts.BI/SaleVoucherBI.cs
2010-03-02 23:26:21 +05:30

225 lines
9.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.DAOFactory;
using Tanshu.Data.DAO;
namespace Tanshu.Accounts.BI
{
public class SaleVoucherBI : ISaleVoucherBI
{
public SalesBillItemBO GetDefaultSaleBillItem(Guid productID)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetDefaultSaleBillItem(productID);
}
}
}
public decimal GetProductDiscountLimit(Guid productID)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetProductDiscountLimit(productID);
}
}
}
public bool IsBillPrinted(Guid voucherID)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.IsBillPrinted(voucherID);
}
}
}
public bool Insert(SaleVoucherBO saleVoucher, List<InventoryBO> inventory)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (IVoucherDAO vdao = factory.GetVoucherDAO(connection))
{
using (ISaleVoucherDAO svdao = factory.GetSaleVoucherDAO(connection))
{
using (IInventoryDAO idao = factory.GetInventoryDAO(connection))
{
connection.BeginTransaction();
#region Voucher
VoucherBO myVoucher = (VoucherBO)saleVoucher;
myVoucher.Date = null;
vdao.Insert(myVoucher);
#endregion
#region Transaction Sale
svdao.Insert(saleVoucher);
#endregion
#region Inventory
foreach (InventoryBO i in inventory)
{
i.VoucherID = saleVoucher.VoucherID;
InventoryBO myInventory = i;
idao.Insert(myInventory);
}
#endregion
connection.CommitTransaction();
return true;
}
}
}
}
}
public bool Update(SaleVoucherBO saleVoucher, List<InventoryBO> inventory)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (IVoucherDAO vdao = factory.GetVoucherDAO(connection))
{
using (ISaleVoucherDAO svdao = factory.GetSaleVoucherDAO(connection))
{
using (IInventoryDAO idao = factory.GetInventoryDAO(connection))
{
connection.BeginTransaction();
#region Voucher
VoucherBO myVoucher = (VoucherBO)saleVoucher;
vdao.Update(myVoucher);
#endregion
#region Transaction Sale
svdao.Update(saleVoucher);
#endregion
#region Inventory
idao.Delete(saleVoucher.VoucherID);
foreach (InventoryBO i in inventory)
{
i.VoucherID = saleVoucher.VoucherID;
InventoryBO myInventory = i;
idao.Insert(myInventory);
}
#endregion
connection.CommitTransaction();
return true;
}
}
}
}
}
public bool GetSaleVoucher(Guid voucherID, ref SaleVoucherBO voucherSale, ref List<InventoryDisplayBO> iList)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherDAO svdao = factory.GetSaleVoucherDAO(connection))
{
using (IInventoryDAO idao = factory.GetInventoryDAO(connection))
{
voucherSale = svdao.GetVoucherSale(voucherID);
iList = idao.GetInventories(voucherID);
return true;
}
}
}
}
public List<PendingBillsBO> GetPendingBills(PendingType list)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetPendingBills(list);
}
}
}
public Guid? GetPendingVoucherID(string tableID)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetPendingVoucherID(tableID);
}
}
}
public List<InventoryBO> SaleInventory(Dictionary<BillItemKey, SalesBillItemBO>.ValueCollection list, Guid? voucherID)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.SaleInventory(list, voucherID);
}
}
}
public void GetComplexBillInformation(Guid voucherID, Guid complexProductID, ref decimal rate, ref decimal quantity, ref string name)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
dao.GetComplexBillInformation(voucherID, complexProductID, ref rate, ref quantity, ref name);
}
}
}
public void SetAlarm(Guid voucherID, DateTime? alarmTime)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherDAO dao = factory.GetSaleVoucherDAO(connection))
{
dao.SetAlarm(voucherID, alarmTime);
}
}
}
public void VoidBill(Guid voucherID, string reason)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherDAO dao = factory.GetSaleVoucherDAO(connection))
{
dao.VoidBill(voucherID, reason);
}
}
}
public void DeclareBillsPaid(Guid userID, List<Guid> billList, bool creditCard)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
dao.DeclareBillsPaid(userID, billList, creditCard);
}
}
}
public void ToggleImportant(Guid voucherID)
{
GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (IConnectionDAO connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
dao.ToggleImportant(voucherID);
}
}
}
}
}