narsil/Tanshu.Accounts.BI/SaleVoucherBI.cs

227 lines
8.2 KiB
C#

using System;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.BI
{
public class SaleVoucherBI : ISaleVoucherBI
{
public SalesBillItemBO GetDefaultSaleBillItem(Guid productID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.GetDefaultSaleBillItem(productID);
}
}
}
public decimal GetProductDiscountLimit(Guid productID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.GetProductDiscountLimit(productID);
}
}
}
public bool IsBillPrinted(Guid voucherID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.IsBillPrinted(voucherID);
}
}
}
public decimal Amount(Guid voucherID)
{
//throw new NotImplementedException();
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.Amount(voucherID);
}
}
}
public bool Insert(SaleVoucherBO saleVoucher, List<InventoryBO> inventory)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
{
using (var idao = new SqlDAO.InventoryDAO(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)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
{
using (var idao = new SqlDAO.InventoryDAO(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)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
{
using (var idao = new SqlDAO.InventoryDAO(connection))
{
voucherSale = svdao.GetVoucherSale(voucherID);
iList = idao.GetInventories(voucherID);
return true;
}
}
}
}
public bool GetSaleVoucher(string billID, ref SaleVoucherBO voucherSale, ref List<InventoryDisplayBO> iList)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
{
using (var idao = new SqlDAO.InventoryDAO(connection))
{
voucherSale = svdao.GetVoucherSale(billID);
iList = idao.GetInventories(voucherSale.VoucherID);
return true;
}
}
}
}
public List<PendingBillsBO> GetPendingBills(PendingType list, int floor)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.GetPendingBills(list, floor);
}
}
}
public Guid? GetPendingVoucherID(string tableID, int floor)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.GetPendingVoucherID(tableID, floor);
}
}
}
public List<InventoryBO> SaleInventory(Dictionary<BillItemKey, SalesBillItemBO>.ValueCollection list, Guid? voucherID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
{
return dao.SaleInventory(list, voucherID);
}
}
}
public void SetAlarm(Guid voucherID, DateTime? alarmTime)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.SaleVoucherDAO(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.SaleVoucherDAO(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.SaleVoucherMixDAO(connection))
{
dao.DeclareBillsPaid(userID, billList, paidStatus);
}
}
}
}
}