narsil/Tanshu.Accounts.BI/SaleVoucherBI.cs

227 lines
8.1 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.BI
{
public class SaleVoucherBI
2010-03-02 17:56:21 +00:00
{
public SalesBillItemBO GetDefaultSaleBillItem(Guid productID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
return dao.GetDefaultSaleBillItem(productID);
}
}
}
public decimal GetProductDiscountLimit(Guid productID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
return dao.GetProductDiscountLimit(productID);
}
}
}
public bool IsBillPrinted(Guid voucherID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
return dao.IsBillPrinted(voucherID);
}
}
}
2011-12-05 09:23:02 +00:00
public decimal Amount(Guid voucherID)
{
//throw new NotImplementedException();
using (var connection = new SqlDAO.SqlConnectionDAO())
2011-12-05 09:23:02 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2011-12-05 09:23:02 +00:00
{
return dao.Amount(voucherID);
}
}
}
2010-03-02 17:56:21 +00:00
public bool Insert(SaleVoucherBO saleVoucher, List<InventoryBO> inventory)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
using (var idao = new SqlDAO.InventoryDAO(connection))
2010-03-02 17:56:21 +00:00
{
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())
2010-03-02 17:56:21 +00:00
{
using (var vdao = new SqlDAO.VoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
using (var idao = new SqlDAO.InventoryDAO(connection))
2010-03-02 17:56:21 +00:00
{
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())
2010-03-02 17:56:21 +00:00
{
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
using (var idao = new SqlDAO.InventoryDAO(connection))
2010-03-02 17:56:21 +00:00
{
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;
}
}
}
}
2010-03-02 17:56:21 +00:00
2011-12-05 09:23:02 +00:00
public List<PendingBillsBO> GetPendingBills(PendingType list, int floor)
2010-03-02 17:56:21 +00:00
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
2011-12-05 09:23:02 +00:00
return dao.GetPendingBills(list, floor);
2010-03-02 17:56:21 +00:00
}
}
}
2011-12-05 09:23:02 +00:00
public Guid? GetPendingVoucherID(string tableID, int floor)
2010-03-02 17:56:21 +00:00
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
2011-12-05 09:23:02 +00:00
return dao.GetPendingVoucherID(tableID, floor);
2010-03-02 17:56:21 +00:00
}
}
}
public List<InventoryBO> SaleInventory(Dictionary<BillItemKey, SalesBillItemBO>.ValueCollection list, Guid? voucherID)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
return dao.SaleInventory(list, voucherID);
}
}
}
public void SetAlarm(Guid voucherID, DateTime? alarmTime)
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
dao.SetAlarm(voucherID, alarmTime);
}
}
}
public void VoidBill(Guid voucherID, string reason, Guid userID)
2010-03-02 17:56:21 +00:00
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherDAO(connection))
2010-03-02 17:56:21 +00:00
{
dao.VoidBill(voucherID, reason, userID);
2010-03-02 17:56:21 +00:00
}
}
}
2011-12-05 09:23:02 +00:00
public void DeclareBillsPaid(Guid userID, List<Guid> billList, PaidStatus paidStatus)
2010-03-02 17:56:21 +00:00
{
using (var connection = new SqlDAO.SqlConnectionDAO())
2010-03-02 17:56:21 +00:00
{
using (var dao = new SqlDAO.SaleVoucherMixDAO(connection))
2010-03-02 17:56:21 +00:00
{
2011-12-05 09:23:02 +00:00
dao.DeclareBillsPaid(userID, billList, paidStatus);
2010-03-02 17:56:21 +00:00
}
}
}
}
}