Location: PHPKode > projects > TEMS -Time and Expense Management System > tems/times/SubmitPage.php
<?php

/* * *******************************************************************************
 * TES is a Time and Expense Management program developed by
 * Initechs, LLC. Copyright (C) 2009 - 2010 Initechs LLC.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation with the addition of the following permission added
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 * IN WHICH THE COPYRIGHT IS OWNED BY INITECHS, INITECHS DISCLAIMS THE WARRANTY
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 *
 * You can contact Initechs headquarters at 1841 Piedmont Road, Suite 301,
 * Marietta, GA, USA. or at email address hide@address.com
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display od the "Initechs" logo.
 * If the display of the logo is not reasonably feasible for technical reasons,
 * the Appropriate Legal Notices must display the words "Powered by Initechs".

 * ****************************************************************************** */

$basedir = dirname(__FILE__) . '/..';
require_once("$basedir/baseclass/PageController.php");

class ActionPage extends PageController {

    protected function ListPage($ControlDS, $heading='') {
        global $basedir;
        global $ini_array;
        $recs_per_page = $ini_array['display']['records_per_page'];

        $SearchDisplayDS = new DisplayControlStructure($ControlDS->folder, $ControlDS->searchLayout);
        $searchLayoutArray = $SearchDisplayDS->layoutArray;

        $DisplayControlDS = new DisplayControlStructure($ControlDS->folder, $ControlDS->displayLayout);
        $layoutArray = $DisplayControlDS->layoutArray;

        $where = $this->buildWhereClause($ControlDS, $searchLayoutArray);

        $DataSet = $this->LoadListPageData($ControlDS, $DisplayControlDS, $where);

        $start = $this->setRecordOffset();

        $Data = new dbObj();
        $TotalRecs = $Data->countRows($ControlDS->table, $where);

        $navigation = $this->buildNavigation($start, $TotalRecs);

        $str = '';

        $str .= $this->buildSearchForm($ControlDS, $searchLayoutArray, $heading);

        if ($str <> "No record found") {
            $TimeSummary = new TimeSummaryPage();
            $str .= $TimeSummary->showSummary();

            $str .= $this->showTable($ControlDS, $layoutArray, $DataSet, $navigation);
        }

        unset($_SESSION['error']);
        unset($_SESSION['message']);
        return $str;
    }

    protected function buildWhereClause($ControlDS, $displayLayout) {
        $where = '';

        $uid = trim($_GET['uid']);
        $DbObj = new dbObj();
        $query = "select  users_id, weekenddate
					from  times
					where uid = $uid";

        $dataset = $DbObj->getDatabyQuery($query);
        if ($dataset <> null) {
            $where = "users_id = '{$dataset[0]['users_id']}' and weekenddate = '{$dataset[0]['weekenddate']}'";
        }

        return $where;
    }

    protected function buildSearchForm($ControlDS, $searchLayoutArray, $heading='') {
        $ControlDS->displayLayout = $ControlDS->searchLayout;
        $str = $this->BrowsePage($ControlDS, $heading = '');

        return $str;
    }

}

class TimeSummaryPage extends PageSection {

    public function showSummary() {
        $DbObj = new dbObj();
        $where = "uid = '{$_GET['uid']}'";
        $EH = $DbObj->fetchRowbyWhereClause('times', $where);

        $str = '';

        $str .= "\n<table id = 'list'>";

        $str .= $this->makeColHeading($EH);
        $str .= $this->makeDetailBlock($EH);

        $str .= "\n</table>";

        return $str;
    }

    protected function getDetailRecs($EH) {
        $DbObj = new dbObj();
        $query = "select workdate,
                         datediff(workdate, date('{$EH['weekenddate']}')) + 7 as dayindex,
			 sum(nonbillablehours + billablehours) as totalhoursbydate,
			 sum(billablehours) as billhoursbydate,
			 sum(nonbillablehours) as nonbillhoursbydate
		    from times
		   Where times.users_id = '{$EH['users_id']}'
                     and times.weekenddate = '{$EH['weekenddate']}'
		group by times.workdate
                order by dayindex";

        $dataset = $DbObj->getDatabyQuery($query);
        return $dataset;
    }

    protected function makeColHeading($EH) {

        $dateFormat = getUserDateFormat();

        $str = '';
        $str .= "<tr> <th>".changeLiteral(Hours)."</th>";

        for ($i=6; $i>=0; $i--) {
            $date = tesAddDate($EH['weekenddate'], -$i);
            $date = cvtDateIso2Dsp($date, $dateFormat);
            $str .= "<th>" . changeLiteral(Date2Day($date)) . "<hr />$date</th>";
        }

	$str .= "<th>".changeLiteral('Total')."</th> \n</tr>";
        return $str;
    }

    protected function makeDetailBlock($EH) {

        $dataset = $this->getDetailRecs($EH);
        if (!isset($dataset[0]))
            return null;

        $str = '';
        $timeArray = array();
        $totalArray = array();

        $timeArray['billhours'][0] = changeLiteral('Billable Hours');
        $timeArray['nonbillhours'][0] = changeLiteral('Non-billable Hours');
        $timeArray['totalhours'][0] = changeLiteral('Total Hours');

        foreach ($dataset as $row) {
            $timeArray['billhours'][$row['dayindex']] = $row['billhoursbydate'];
            $timeArray['nonbillhours'][$row['dayindex']] = $row['nonbillhoursbydate'];
            $timeArray['totalhours'][$row['dayindex']] = $row['totalhoursbydate'];

            $timeArray['billhours'][8] += $row['billhoursbydate'];
            $timeArray['nonbillhours'][8] += $row['nonbillhoursbydate'];
            $timeArray['totalhours'][8] += $row['totalhoursbydate'];
        }

        $str .= $this->makeDetailLine($timeArray);

        return $str;

    }

    protected function makeDetailLine($timeArray) {

        foreach ($timeArray as $row) {

            $str .= "\n<tr>";
            $str .= "{$this->printField($row[0], 'vertical-align: top; text-align: left;', 'textField')}";

            for ($i=1; $i<=8; $i++) {
                $amount = isset ($row[$i]) ? sprintf("%01.2f", $row[$i]) : '';
                $amount = $amount == '0.00' ? '' : $amount;
                $str .= "{$this->printField($amount, 'vertical-align: top; text-align: center;', 'textField')}";
            }
            $str .= "\n</tr>";
        }
        return $str;
    }


}

?>
Return current item: TEMS -Time and Expense Management System