60 lines
2.7 KiB
C#
60 lines
2.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data.SqlClient;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Data.DAO;
|
|
using Tanshu.Accounts.DAOFactory;
|
|
|
|
namespace Tanshu.Accounts.SqlDAO
|
|
{
|
|
public class AdvanceDAO : BaseDAO, IAdvanceDAO
|
|
{
|
|
public AdvanceDAO(IConnectionDAO connection)
|
|
: base(connection)
|
|
{ }
|
|
|
|
public void Insert(AdvanceBO advance)
|
|
{
|
|
SqlCommand cmd = new SqlCommand(@"
|
|
SET @AdvanceID = NEWID();
|
|
INSERT INTO Advances (AdvanceID, Amount, Narration, CashierIn, DateIn, CashierOut, DateOut)
|
|
VALUES (@AdvanceID, @Amount, @Narration, @CashierIn, @DateIn, @CashierOut, @DateOut)
|
|
");
|
|
cmd.Parameters.Add("@AdvanceID", System.Data.SqlDbType.UniqueIdentifier);
|
|
cmd.Parameters["@AdvanceID"].Direction = System.Data.ParameterDirection.Output;
|
|
cmd.Parameters.AddWithValue("@Amount", advance.Amount);
|
|
cmd.Parameters.AddWithValue("@Narration", advance.Narration);
|
|
cmd.Parameters.AddWithValue("@CashierIn", advance.CashierIn);
|
|
cmd.Parameters.AddWithValue("@DateIn", advance.DateIn);
|
|
if (advance.CashierOut.HasValue)
|
|
cmd.Parameters.AddWithValue("@CashierOut", advance.CashierOut);
|
|
else
|
|
cmd.Parameters.AddWithValue("@CashierOut", DBNull.Value);
|
|
if (advance.DateOut.HasValue)
|
|
cmd.Parameters.AddWithValue("@DateOut", advance.DateOut);
|
|
else
|
|
cmd.Parameters.AddWithValue("@DateOut", DBNull.Value);
|
|
connection.ExecuteNonQuery(cmd);
|
|
advance.AdvanceID = (Guid)cmd.Parameters["@AdvanceID"].Value;
|
|
}
|
|
public List<AdvanceDisplayBO> GetAdvances(DateTime fromDate, DateTime toDate, bool all)
|
|
{
|
|
string query = "SELECT a.*, u.Name AS Cashier FROM Advances a INNER JOIN Users u ON a.CashierIn = u.UserID WHERE DateIn BETWEEN @StartDate AND @FinishDate";
|
|
if (!all)
|
|
query += " AND CashierOut IS NULL";
|
|
SqlCommand cmd = new SqlCommand(query);
|
|
cmd.Parameters.AddWithValue("@StartDate", fromDate);
|
|
cmd.Parameters.AddWithValue("@FinishDate", toDate);
|
|
return BusinessObjectDAO<AdvanceDisplayBO>.GetBusinessObjects(connection.ExecuteReader(cmd));
|
|
}
|
|
public void Adjust(Guid advanceID, Guid userID)
|
|
{
|
|
SqlCommand cmd = new SqlCommand("UPDATE Advances SET CashierOut = @CashierOut, DateOut = GETDATE() WHERE AdvanceID = @AdvanceID");
|
|
cmd.Parameters.AddWithValue("@AdvanceID", advanceID);
|
|
cmd.Parameters.AddWithValue("@CashierOut", userID);
|
|
connection.ExecuteNonQuery(cmd);
|
|
}
|
|
}
|
|
}
|