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 : ISaleVoucherBI
|
|
|
|
|
{
|
|
|
|
|
public SalesBillItemBO GetDefaultSaleBillItem(Guid productID)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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();
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2011-12-05 09:23:02 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var vdao = new SqlDAO.VoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var vdao = new SqlDAO.VoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-06 20:07:58 +00:00
|
|
|
|
public bool GetSaleVoucher(string billID, ref SaleVoucherBO voucherSale, ref List<InventoryDisplayBO> iList)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2012-04-06 20:07:58 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var svdao = new SqlDAO.SaleVoucherDAO(connection))
|
2012-04-06 20:07:58 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var idao = new SqlDAO.InventoryDAO(connection))
|
2012-04-06 20:07:58 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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)
|
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var dao = new SqlDAO.SaleVoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
|
|
|
|
dao.SetAlarm(voucherID, alarmTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-16 06:01:58 +00:00
|
|
|
|
public void VoidBill(Guid voucherID, string reason, Guid userID)
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
using (var dao = new SqlDAO.SaleVoucherDAO(connection))
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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
|
|
|
|
{
|
2013-11-16 06:01:58 +00:00
|
|
|
|
|
|
|
|
|
using (var connection = new SqlDAO.SqlConnectionDAO())
|
2010-03-02 17:56:21 +00:00
|
|
|
|
{
|
2013-11-16 06:01:58 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|