narsil/Tanshu.Accounts.BI/SaleVoucherBI.cs
2011-12-05 14:53:02 +05:30

214 lines
8.5 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)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetDefaultSaleBillItem(productID);
}
}
}
public decimal GetProductDiscountLimit(Guid productID)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetProductDiscountLimit(productID);
}
}
}
public bool IsBillPrinted(Guid voucherID)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.IsBillPrinted(voucherID);
}
}
}
public decimal Amount(Guid voucherID)
{
//throw new NotImplementedException();
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.Amount(voucherID);
}
}
}
public bool Insert(SaleVoucherBO saleVoucher, List<InventoryBO> inventory)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var 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)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var 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)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var 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, int floor)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetPendingBills(list, floor);
}
}
}
public Guid? GetPendingVoucherID(string tableID, int floor)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.GetPendingVoucherID(tableID, floor);
}
}
}
public List<InventoryBO> SaleInventory(Dictionary<BillItemKey, SalesBillItemBO>.ValueCollection list, Guid? voucherID)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
return dao.SaleInventory(list, voucherID);
}
}
}
public void SetAlarm(Guid voucherID, DateTime? alarmTime)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherDAO dao = factory.GetSaleVoucherDAO(connection))
{
dao.SetAlarm(voucherID, alarmTime);
}
}
}
public void VoidBill(Guid voucherID, string reason)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherDAO dao = factory.GetSaleVoucherDAO(connection))
{
dao.VoidBill(voucherID, reason);
}
}
}
public void DeclareBillsPaid(Guid userID, List<Guid> billList, PaidStatus paidStatus)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
{
dao.DeclareBillsPaid(userID, billList, paidStatus);
}
}
}
}
}