<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code &#187; timeclock</title>
	<atom:link href="http://www.rdustinwebstudio.com/code/tag/timeclock/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rdustinwebstudio.com/code</link>
	<description>Randy Dustin. Web Developer.</description>
	<lastBuildDate>Tue, 10 Jan 2012 14:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Timeclock: using FPDF to generate timesheets</title>
		<link>http://www.rdustinwebstudio.com/code/2009/04/09/timeclock-using-fpdf-to-generate-timesheets/</link>
		<comments>http://www.rdustinwebstudio.com/code/2009/04/09/timeclock-using-fpdf-to-generate-timesheets/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 13:46:05 +0000</pubDate>
		<dc:creator>Randy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[timeclock]]></category>

		<guid isPermaLink="false">http://www.rdustinwebstudio.com/code/?p=62</guid>
		<description><![CDATA[Background Read background information on the design of the timeclock system! Single vs. Multiple timesheets Since each student&#8217;s timesheet is formated the same way, whether it is generated as a single timesheet or as part of multiple timesheets, I developed a class to create the timesheets. In the class is a function called outputPDF which [...]]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>Read background information on the <a href="http://www.rdustinwebstudio.com/code/?p=8/">design of the timeclock system</a>!</p>
<h3>Single vs. Multiple timesheets</h3>
<p>Since each student&#8217;s timesheet is formated the same way, whether it is generated as a single timesheet or as part of multiple timesheets, I developed a class to create the timesheets.</p>
<div id="attachment_74" class="wp-caption alignnone" style="width: 310px"><a href="http://www.rdustinwebstudio.com/code/wp-content/uploads/2009/04/sample-timesheet.jpg"><img class="size-medium wp-image-74" title="sample-timesheet" src="http://www.rdustinwebstudio.com/code/wp-content/uploads/2009/04/sample-timesheet-300x240.jpg" alt="Figure 1: A sample timesheet" width="300" height="240" /></a><p class="wp-caption-text">Figure 1: A sample timesheet</p></div>
<p>In the class is a function called outputPDF which accepts one argument: an array of the timesheet values.  Inside the function we begin creating the page.</p>
<pre class="brush:php">function outputFPdf($app_data)
{
	$app_data;
	ob_start();
	$output = null;
	$output .= $this-&gt;fpdf-&gt;SetFont('Arial','B',15);
	$output .= $this-&gt;fpdf-&gt;Cell(80);
	$output .= $this-&gt;fpdf-&gt;Cell(30,10,'Complete Payroll Report',0,0,'C');
	$output .= $this-&gt;fpdf-&gt;Ln(8);
			$output .= $this-&gt;fpdf-&gt;SetFont('Arial','',10);
	$output .= $this-&gt;fpdf-&gt;Cell('',10,"Name: ".$app_data['name'],0,0,'C');
	$output .= $this-&gt;fpdf-&gt;Ln(6);
        &lt;---- edited for brevity ----&gt;
	ob_clean();
	return $output;
}</pre>
<p>Now that we&#8217;ve got the timesheet ready let&#8217;s create a function that determines the timesheet type.</p>
<pre class="brush:php">function createPdf($app_data, $type, $begin, $end, $section=null)
	{</pre>
<p>There are a few things we want to accomplish with this function.</p>
<ul>
<li>include and instantiate the fpdf library
<pre class="brush:php">include 'includes/fpdf.php';
$this-&gt;fpdf = new fpdfHelper();</pre>
</li>
<li>Call the FPDF page numbering function and create the first page:
<pre class="brush:php">$this-&gt;fpdf-&gt;AliasNbPages();
$this-&gt;fpdf-&gt;AddPage();</pre>
</li>
<li>Set the page title:
<pre class="brush:php">$this-&gt;fpdf-&gt;setTitle('Complete Payroll Report');</pre>
</li>
<li>check to see if the type is single and if so, generate the timesheet:
<pre class="brush:php">if($type == 'single')
{
	//set the begin period and end period dates
	$app_data['begin_period'] = $begin;
	$app_data['end_period'] = $end;
	//create the timesheet
	$data = $this-&gt;outputPdf($app_data);
	//get the current date so we can put it in the file name of the timesheet
	$date = date("m_d_Y");
	//create the file name with the employee's name and the date
	$name = $app_data['name']."_".$date.".pdf";
	//send it to the browser
	echo $this-&gt;fpdf-&gt;fpdfOutput($name, $destination = 'd');
}</pre>
</li>
<li>if the type isn&#8217;t single check to see if it is multiple and if so, generate the timesheets:
<pre class="brush:php">elseif($type == 'multiple')
{
	//get the current date to use in the file name
	$date = date("m_d_Y");
	//do stuff to get all apps in pdf
	$data = null; //create variable to hold the timesheets as we generate them
	//loop through the data and create a timesheet for each employee
	foreach ($app_data as $app)
	{
		//set up begin and end date variables for the pay period
		$app['begin_period'] = $begin;
		$app['end_period'] = $end;
		//generate timesheet for the current employee and store it in the data variable
		$data .= $this-&gt;outputPdf($app);
		//create a new page
		$data .= $this-&gt;fpdf-&gt;AddPage();
	}
	//create the file name and include the name of the department (section) in it
	$name = "payroll_report_".$section."_".$date.".pdf";
	//send it to the browser
	echo $this-&gt;fpdf-&gt;fpdfOutput($name, $destination = 'd');
}
}</pre>
</li>
</ul>
<p>So all together it looks like this:</p>
<pre class="brush:php">function createPdf($app_data, $type, $begin, $end, $section=null)
{
	include 'includes/fpdf.php';
	$this-&gt;fpdf = new fpdfHelper();

	$this-&gt;fpdf-&gt;AliasNbPages();
	$this-&gt;fpdf-&gt;AddPage();

	$this-&gt;fpdf-&gt;setTitle('Complete Payroll Report');

	if($type == 'single')
	{
		//set the begin period and end period dates
		$app_data['begin_period'] = $begin;
		$app_data['end_period'] = $end;
		//create the timesheet
		$data = $this-&gt;outputPdf($app_data);
		//get the current date so we can put it in the file name of the timesheet
		$date = date("m_d_Y");
		//create the file name with the employee's name and the date
		$name = $app_data['name']."_".$date.".pdf";
		//send it to the browser
		echo $this-&gt;fpdf-&gt;fpdfOutput($name, $destination = 'd');
	}
	elseif($type == 'multiple')
	{
		//get the current date to use in the file name
		$date = date("m_d_Y");
		//do stuff to get all apps in pdf
		$data = null; //create variable to hold the timesheets as we generate them
		//loop through the data and create a timesheet for each employee
		foreach ($app_data as $app)
		{
			//set up begin and end date variables for the pay period
			$app['begin_period'] = $begin;
			$app['end_period'] = $end;
			//generate timesheet for the current employee and store it in the data variable
			$data .= $this-&gt;outputPdf($app);
			//create a new page
			$data .= $this-&gt;fpdf-&gt;AddPage();
		}
		//create the file name and include the name of the department (section) in it
		$name = "payroll_report_".$section."_".$date.".pdf";
		//send it to the browser
		echo $this-&gt;fpdf-&gt;fpdfOutput($name, $destination = 'd');
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rdustinwebstudio.com/code/2009/04/09/timeclock-using-fpdf-to-generate-timesheets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Timeclock: simplifying timesheets</title>
		<link>http://www.rdustinwebstudio.com/code/2009/02/28/timeclock-simplifying-timesheets/</link>
		<comments>http://www.rdustinwebstudio.com/code/2009/02/28/timeclock-simplifying-timesheets/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 20:41:54 +0000</pubDate>
		<dc:creator>Randy</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[timeclock]]></category>

		<guid isPermaLink="false">http://www.rdustinwebstudio.com/code/?p=8</guid>
		<description><![CDATA[Background One of the cool things about the timeclock is the ability to generate pdf timesheets on demand. The Hartman Union Building (HUB) administrative assistant is tasked with producing timesheets for approximately 100 student employees every two weeks. Problem The old time clock system generated arbitrary numbers for each student employee. At the end of [...]]]></description>
			<content:encoded><![CDATA[<h3>Background</h3>
<p>One of the cool things about the timeclock is the ability to generate pdf timesheets on demand. The Hartman Union Building (HUB) administrative assistant is tasked with producing timesheets for approximately 100 student employees every two weeks.</p>
<h4>Problem</h4>
<p>The old time clock system generated arbitrary numbers for each student employee.  At the end of each two week pay period the administrative assistant had to manually enter each employee&#8217;s time clock number, generate and print a timesheet report.  As you can imagine, this was a tedious and time consuming task.<strong></strong></p>
<h4>Problem Solved!</h4>
<p><strong> </strong>Before I began creating the timeclock I talked to the administrative assistant to identify what she liked and disliked about the current system.  The problem outlined above was her greatest dislike.  I created the new timeclock system to revolve around the unique student ID number issued to students upon their acceptance to the university.  This allows the administrative assitant to select an employee by their name and generate a timesheet for that individual. Even better, I went one step further to reduce her workload: now she can generate a single pdf file with all employees&#8217; timesheets ready to print. This takes only a few minutes instead of the entire afternoon!</p>
<p>Read more about how I <a href="http://www.rdustinwebstudio.com/code/?p=62/">generate the timesheets</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rdustinwebstudio.com/code/2009/02/28/timeclock-simplifying-timesheets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

