2010-03-02 17:56:21 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
return dao.GetDefaultSaleBillItem(productID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public decimal GetProductDiscountLimit(Guid productID)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
return dao.GetProductDiscountLimit(productID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public bool IsBillPrinted(Guid voucherID)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
return dao.IsBillPrinted(voucherID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-05 09:23:02 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-02 17:56:21 +00:00
|
|
|
|
public bool Insert(SaleVoucherBO saleVoucher, List<InventoryBO> inventory)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherDAO svdao = factory.GetSaleVoucherDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
using (IInventoryDAO idao = factory.GetInventoryDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
voucherSale = svdao.GetVoucherSale(voucherID);
|
|
|
|
|
iList = idao.GetInventories(voucherID);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-05 09:23:02 +00:00
|
|
|
|
public List<PendingBillsBO> GetPendingBills(PendingType list, int floor)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
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
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
return dao.SaleInventory(list, voucherID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void SetAlarm(Guid voucherID, DateTime? alarmTime)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherDAO dao = factory.GetSaleVoucherDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
dao.SetAlarm(voucherID, alarmTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void VoidBill(Guid voucherID, string reason)
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherDAO dao = factory.GetSaleVoucherDAO(connection))
|
|
|
|
|
{
|
|
|
|
|
dao.VoidBill(voucherID, reason);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
|
|
|
|
using (var connection = factory.Connection)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
using (ISaleVoucherMixDAO dao = factory.GetSaleVoucherMixDAO(connection))
|
|
|
|
|
{
|
2011-12-05 09:23:02 +00:00
|
|
|
|
dao.DeclareBillsPaid(userID, billList, paidStatus);
|
2010-03-02 17:56:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|