narsil/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs

99 lines
3.4 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
2010-03-02 17:56:21 +00:00
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.PointOfSale
{
public partial class frmSaleAnalysisForm : Form
{
IList<SalesAnalysis> _list;
bool _loading;
2010-03-02 17:56:21 +00:00
public frmSaleAnalysisForm()
{
_loading = true;
2010-03-02 17:56:21 +00:00
InitializeComponent();
}
private void SaleAnalysisForm_Load(object sender, EventArgs e)
{
dtpStart.Format = DateTimePickerFormat.Custom;
dtpStart.CustomFormat = "dd-MMM-yyyy";
dtpStart.Value = DateTime.Now.Date;
dtpFinish.Format = DateTimePickerFormat.Custom;
dtpFinish.CustomFormat = "dd-MMM-yyyy";
dtpFinish.Value = DateTime.Now.Date;
_loading = false;
ShowStatement();
}
2010-03-02 17:56:21 +00:00
private void dtpStart_ValueChanged(object sender, EventArgs e)
{
ShowStatement();
}
private void ShowStatement()
{
if (_loading)
return;
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 &&
!Session.IsAllowed("Accounts Audit"))
return;
var start = dtpStart.Value.Date.AddHours(6);
var finish = dtpFinish.Value.Date.AddDays(1).AddHours(5);
_list = new List<SalesAnalysis>();
if (finish > start)
{
var bi = new SalesAnalysisBI();
var list = new List<SalesAnalysis>();
list.AddRange(bi.GetSale(start, finish));
list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
list.AddRange(bi.GetSettlements(start, finish));
list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
var sc = bi.GetServiceCharge(start, finish);
if (sc != null)
list.Add(sc);
foreach (var item in bi.GetServiceTax(start, finish))
{
if (item.TaxAmount != 0)
{
list.Add(new SalesAnalysis() { GroupType = item.Name, Amount = item.TaxAmount });
}
}
foreach (var item in bi.GetVat(start, finish))
{
if (item.TaxAmount != 0)
{
list.Add(new SalesAnalysis() { GroupType = item.Name, Amount = item.TaxAmount });
}
}
_list = list;
}
dgvSale.AutoGenerateColumns = true;
dgvSale.DataSource = _list;
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dgvSale.Columns[1].DefaultCellStyle.Format = "#,##0.00;(#,##0.00);0";
dgvSale.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
2010-03-02 17:56:21 +00:00
}
private void dtpFinish_ValueChanged(object sender, EventArgs e)
{
ShowStatement();
}
private void btnPrint_Click(object sender, EventArgs e)
{
if (_list != null)
2010-03-02 17:56:21 +00:00
{
var startDate = dtpStart.Value.Date.AddHours(6);
var finishDate = dtpFinish.Value.Date.AddDays(1).AddHours(5);
Accounts.Print.Thermal.PrintSale(Session.User.Name, _list, startDate, finishDate);
2010-03-02 17:56:21 +00:00
}
}
}
}