71 lines
3.1 KiB
C#
71 lines
3.1 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(@"
|
|
SELECT @AdvanceID = NEWID(), @DateIn = getdate();
|
|
|
|
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.Add("@DateIn", System.Data.SqlDbType.DateTime);
|
|
cmd.Parameters["@DateIn"].Direction = System.Data.ParameterDirection.Output;
|
|
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 AdvanceBO Get(Guid advanceID)
|
|
{
|
|
using (var cmd = new SqlCommand("SELECT * FROM Advances WHERE AdvanceID = @AdvanceID"))
|
|
{
|
|
cmd.Parameters.AddWithValue("@AdvanceID", advanceID);
|
|
return BusinessObjectDAO<AdvanceBO>.GetBusinessObject(connection.ExecuteReader(cmd));
|
|
}
|
|
}
|
|
|
|
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";
|
|
var 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)
|
|
{
|
|
var 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);
|
|
}
|
|
}
|
|
}
|