// Payroll2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Payroll2.h"
#include "Payroll2Dlg.h"
#include ".\payroll2dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CPayroll2Dlg dialog
CPayroll2Dlg::CPayroll2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CPayroll2Dlg::IDD, pParent)
, m_EmployeeName(_T(""))
, m_HourlySalary(_T("10.00"))
, m_Monday1(_T("0.00"))
, m_Tuesday1(_T("0.00"))
, m_Wednesday1(_T("0.00"))
, m_Thursday1(_T("0.00"))
, m_Friday1(_T("0.00"))
, m_Saturday1(_T("0.00"))
, m_Sunday1(_T("0.00"))
, m_Monday2(_T("0.00"))
, m_Tuesday2(_T("0.00"))
, m_Wednesday2(_T("0.00"))
, m_Thursday2(_T("0.00"))
, m_Friday2(_T("0.00"))
, m_Saturday2(_T("0.00"))
, m_Sunday2(_T("0.00"))
, m_RegHours(_T("0.00"))
, m_RegAmount(_T("0.00"))
, m_NetPay(_T("0.00"))
, m_OvtHours(_T("0.00"))
, m_OvtAmount(_T("0.00"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPayroll2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EMPLNAME, m_EmployeeName);
DDX_Text(pDX, IDC_HOURLYSALARY, m_HourlySalary);
DDX_Control(pDX, IDC_STARTDATE, m_StartDate);
DDX_Control(pDX, IDC_ENDDATE, m_EndDate);
DDX_Text(pDX, IDC_MONDAY1, m_Monday1);
DDX_Text(pDX, IDC_TUESDAY1, m_Tuesday1);
DDX_Text(pDX, IDC_WEDNESDAY1, m_Wednesday1);
DDX_Text(pDX, IDC_THURSDAY1, m_Thursday1);
DDX_Text(pDX, IDC_FRIDAY1, m_Friday1);
DDX_Text(pDX, IDC_SATURDAY1, m_Saturday1);
DDX_Text(pDX, IDC_SUNDAY1, m_Sunday1);
DDX_Text(pDX, IDC_MONDAY2, m_Monday2);
DDX_Text(pDX, IDC_TUESDAY2, m_Tuesday2);
DDX_Text(pDX, IDC_WEDNESDAY2, m_Wednesday2);
DDX_Text(pDX, IDC_THURSDAY2, m_Thursday2);
DDX_Text(pDX, IDC_FRIDAY2, m_Friday2);
DDX_Text(pDX, IDC_SATURDAY2, m_Saturday2);
DDX_Text(pDX, IDC_SUNDAY2, m_Sunday2);
DDX_Text(pDX, IDC_REGHOURS, m_RegHours);
DDX_Text(pDX, IDC_REGAMOUNT, m_RegAmount);
DDX_Text(pDX, IDC_NETPAY, m_NetPay);
DDX_Text(pDX, IDC_OVTHOURS, m_OvtHours);
DDX_Text(pDX, IDC_OVTAMOUNT, m_OvtAmount);
DDX_Control(pDX, IDC_HOURLYSALARY, m_WndHourlySalay);
DDX_Control(pDX, IDC_MONDAY1, m_WndMonday1);
DDX_Control(pDX, IDC_TUESDAY1, m_WndTuesday1);
DDX_Control(pDX, IDC_WEDNESDAY1, m_WndWednesday1);
DDX_Control(pDX, IDC_THURSDAY1, m_WndThursday1);
DDX_Control(pDX, IDC_FRIDAY1, m_WndFriday1);
DDX_Control(pDX, IDC_SATURDAY1, m_WndSaturday1);
DDX_Control(pDX, IDC_SUNDAY1, m_WndSunday1);
DDX_Control(pDX, IDC_MONDAY2, m_WndMonday2);
DDX_Control(pDX, IDC_TUESDAY2, m_WndTuesday2);
DDX_Control(pDX, IDC_WEDNESDAY2, m_WndWednesday2);
DDX_Control(pDX, IDC_THURSDAY2, m_WndThursday2);
DDX_Control(pDX, IDC_FRIDAY2, m_WndFriday2);
DDX_Control(pDX, IDC_SATURDAY2, m_WndSaturday2);
DDX_Control(pDX, IDC_SUNDAY2, m_WndSunday2);
}
BEGIN_MESSAGE_MAP(CPayroll2Dlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_NOTIFY(DTN_CLOSEUP, IDC_STARTDATE, OnDtnCloseupStartdate)
ON_NOTIFY(DTN_CLOSEUP, IDC_ENDDATE, OnDtnCloseupEnddate)
ON_BN_CLICKED(IDC_PROCESS_BTN, OnBnClickedProcessBtn)
END_MESSAGE_MAP()
// CPayroll2Dlg message handlers
BOOL CPayroll2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
CTime today = CTime::GetCurrentTime();
CTimeSpan tmeSpan(14, 0, 0, 0);
CTime twoWeeksAgo = today - tmeSpan;
this->m_StartDate.SetTime(&twoWeeksAgo);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CPayroll2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CPayroll2Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CPayroll2Dlg::OnDtnCloseupStartdate(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
// Get the starting date
CTime dteStart;
this->m_StartDate.GetTime(dteStart);
// Find out if the user selected a day that is not Monday
if( dteStart.GetDayOfWeek() != 2 )
{
AfxMessageBox("The date you selected in invalid\n"
"The time period should start on a Monday");
this->m_StartDate.SetFocus();
}
}
void CPayroll2Dlg::OnDtnCloseupEnddate(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
CTime dteStart, dteEnd;
// Get the starting date
this->m_StartDate.GetTime(dteStart);
// Get the ending date
this->m_EndDate.GetTime(dteEnd);
// Make sure the first day of the period is Monday
if( dteStart.GetDayOfWeek() != 2 )
{
AfxMessageBox("The starting date you selected in invalid\n"
"The time period should start on a Monday");
this->m_StartDate.SetFocus();
}
// Find the number of days that separates the start and end
CTimeSpan timeDifference = dteEnd - dteStart;
LONGLONG fourteenDaysLater = timeDifference.GetDays();
if( (dteEnd.GetDayOfWeek() != 1) || (fourteenDaysLater != 13) )
{
AfxMessageBox("The ending date you selected in invalid\n"
"The time period should span 2 weeks and end on a Sunday");
this->m_EndDate.SetFocus();
}
}
void CPayroll2Dlg::OnBnClickedProcessBtn()
{
// TODO: Add your control notification handler code here
UpdateData();
double monday1 = 0.00, tuesday1 = 0.00, wednesday1 = 0.00,
thursday1 = 0.00, friday1 = 0.00, saturday1 = 0.00,
sunday1 = 0.00, monday2 = 0.00, tuesday2 = 0.00,
wednesday2 = 0.00, thursday2 = 0.00, friday2 = 0.00,
saturday2 = 0.00, sunday2 = 0.00;
double totalHoursWeek1, totalHoursWeek2;
double regHours1 = 0.00, regHours2 = 0.00, ovtHours1 = 0.00, ovtHours2 = 0.00;
double regAmount1 = 0.00, regAmount2 = 0.00, ovtAmount1 = 0.00, ovtAmount2 = 0.00;
double regularHours, overtimeHours;
double regularAmount, overtimeAmount, totalEarnings;
double hourlySalary = 0.00;
// Retrieve the hourly salary
hourlySalary = atof(this->m_HourlySalary);
monday1 = atof(this->m_Monday1);
tuesday1 = atof(this->m_Tuesday1);
wednesday1 = atof(this->m_Wednesday1);
thursday1 = atof(this->m_Thursday1);
friday1 = atof(this->m_Friday1);
saturday1 = atof(this->m_Saturday1);
sunday1 = atof(this->m_Sunday1);
monday2 = atof(this->m_Monday2);
tuesday2 = atof(this->m_Tuesday2);
wednesday2 = atof(this->m_Wednesday2);
thursday2 = atof(this->m_Thursday2);
friday2 = atof(this->m_Friday2);
saturday2 = atof(this->m_Saturday2);
sunday2 = atof(this->m_Sunday2);
// Calculate the total number of hours for each week
totalHoursWeek1 = monday1 + tuesday1 + wednesday1 + thursday1 +
friday1 + saturday1 + sunday1;
totalHoursWeek2 = monday2 + tuesday2 + wednesday2 + thursday2 +
friday2 + saturday2 + sunday2;
// The overtime is paid time and half
double ovtSalary = hourlySalary * 1.5;
// If the employee worked under 40 hours, there is no overtime
if( totalHoursWeek1 < 40 )
{
regHours1 = totalHoursWeek1;
regAmount1 = hourlySalary * regHours1;
ovtHours1 = 0.00;
ovtAmount1 = 0.00;
} // If the employee worked over 40 hours, calculate the overtime
else if( totalHoursWeek1 >= 40 )
{
regHours1 = 40;
regAmount1 = hourlySalary * 40;
ovtHours1 = totalHoursWeek1 - 40;
ovtAmount1 = ovtHours1 * ovtSalary;
}
if( totalHoursWeek2 < 40 )
{
regHours2 = totalHoursWeek2;
regAmount2 = hourlySalary * regHours2;
ovtHours2 = 0.00;
ovtAmount2 = 0.00;
}
else if( totalHoursWeek2 >= 40 )
{
regHours2 = 40;
regAmount2 = hourlySalary * 40;
ovtHours2 = totalHoursWeek2 - 40;
ovtAmount2 = ovtHours2 * ovtSalary;
}
regularHours = regHours1 + regHours2;
overtimeHours = ovtHours1 + ovtHours2;
regularAmount = regAmount1 + regAmount2;
overtimeAmount = ovtAmount1 + ovtAmount2;
totalEarnings = regularAmount + overtimeAmount;
this->m_RegHours.Format("%.2f", regularHours);
this->m_OvtHours.Format("%.2f", overtimeHours);
this->m_RegAmount.Format("%.2f", regularAmount);
this->m_OvtAmount.Format("%.2f", overtimeAmount);
this->m_NetPay.Format("%.2f", totalEarnings);
UpdateData(FALSE);
}
|