Example #1
0
 function testCreatePair()
 {
     $staff_1 = new Staff();
     $staff_1->set(array('first_name' => 'First', 'last_name' => 'User'));
     $staff_1->save();
     $staff_2 = new Staff();
     $staff_2->set(array('first_name' => 'Second', 'last_name' => 'User'));
     $staff_2->save();
     $h = new Hour();
     $h->set(array('hours' => 6, 'staff_id' => $staff_1->id, 'pair_id' => $staff_2->id));
     $h->updateOrCreateWithPair();
     $this->assertTrue($h->id, 'should have an id');
     $this->assertTrue($h->get('pair_hour_id'), 'should have a pair hour id');
     $h2 = $h->getPairHour();
     $this->assertIsA($h2, 'Hour');
     $this->assertTrue($h2->id, 'should have an hour id');
     $this->assertEqual($h2->get('hours'), 6);
     $h->set(array('hours' => 7));
     $h->updateOrCreateWithPair();
     $h3 = $h->getPairHour();
     $this->assertEqual($h2->id, $h3->id);
     $this->assertEqual($h3->get('hours'), 7);
     $this->assertEqual($h3->getPairName(), $staff_1->getName());
     $this->assertEqual($h->getPairName(), $staff_2->getName());
 }
 function destroy($params)
 {
     if (!$params['id']) {
         bail('Required $params["id"] not present.');
     }
     $h = new Hour($params['id']);
     $support_contract_id = $h->get('support_contract_id');
     $h->destroy();
     isset($params['redirect']) ? $redirect = $params['redirect'] : ($redirect = array('controller' => 'SupportContract', 'action' => 'show', 'id' => $support_contract_id));
     $this->redirectTo($redirect);
 }
 public static function store()
 {
     $params = $_POST;
     $hospital = new Hospital(array('name' => $params['name'], 'open_time' => $params['open_time'], 'close_time' => $params['close_time']));
     $errors = $hospital->errors();
     if (count($errors) > 0) {
         flash()->error(':(', 'Something was a little off...');
         Redirect::to('/hospitals/create', array('errors' => $errors, 'attributes' => $params));
     }
     $hospital->save();
     for ($i = 1; $i <= 24; $i++) {
         $hour = new Hour(array('at' => $i, 'hospital_id' => $hospital->id, 'importance_id' => $params['importance_id']));
         $hour->save();
     }
     Redirect::to('/hospitals#' . $hospital->id);
 }
 public function create($course_id)
 {
     $course = Course::with('placements')->find($course_id);
     $employees = Employee::where('teach_salary', '>', 0.0)->get();
     $hours = Hour::all();
     $menu = 'academic';
     return View::make('presences.create', compact('course', 'subjects', 'employees', 'hours', 'menu'));
 }
Example #5
0
 public function edit($id)
 {
     $teach = Teach::find($id);
     $employees = Employee::where('teach_salary', '>', 0.0)->get();
     $subjects = Subject::all();
     $hours = Hour::all();
     $menu = 'employee';
     return View::make('teaches.edit', compact('teach', 'employees', 'subjects', 'hours', 'menu'));
 }
Example #6
0
 public function destroy($id)
 {
     $hour = Hour::with('schedules')->find($id);
     if ($hour->schedules->count() > 0) {
         Session::flash('message', 'Tidak dapat menghapus jam belajar! Jam belajar ini digunakan dalam jadwal belajar');
     } else {
         Hour::destroy($id);
         Session::flash('message', 'Sukses menghapus jam belajar!');
     }
 }
Example #7
0
 function testDestroyAssociatedRecords()
 {
     $c = new Company();
     $c->set(array('name' => 'destroy_test'));
     $c->save();
     $p = new Project();
     $p->set(array('company_id' => $c->id, 'name' => 'destroy_project_test'));
     $p->save();
     $e = new Estimate();
     $e->set(array('project_id' => $p->id, 'name' => 'destroy_estimate_test'));
     $e->save();
     $h = new Hour();
     $h->set(array('estimate_id' => $e->id, 'name' => 'destroy_hour_test'));
     $h->save();
     $ch = new Charge();
     $ch->set(array('company_id' => $c->id, 'name' => 'destroy_charge_test'));
     $ch->save();
     $con = new SupportContract();
     $con->set(array('company_id' => $c->id, 'name' => 'destroy_contract_test'));
     $con->save();
     $sup_hr = new Hour();
     $sup_hr->set(array('support_contract_id' => $con->id, 'description' => 'destroy_support_hour_test'));
     $sup_hr->save();
     $pay = new Payment();
     $pay->set(array('company_id' => $c->id, 'name' => 'destroy_payment_test'));
     $pay->save();
     $deleted_items = array('company' => $c->id, 'project' => $p->id, 'estimate' => $e->id, 'hour' => $h->id, 'support_hour' => $sup_hr->id, 'charge' => $ch->id, 'support_contract' => $con->id, 'payment' => $pay->id);
     $c->destroyAssociatedRecords();
     $c->delete();
     $dbcon = AMP::getDb();
     foreach ($deleted_items as $table => $id) {
         if ($table == 'support_hour') {
             $table = 'hour';
         }
         $sql = 'SELECT * FROM ' . $table . ' WHERE id = ' . $id;
         if ($records = $dbcon->Execute($sql)) {
             $this->assertEqual($records->RecordCount(), 0, "{$table} not deleted correctly: %s");
         } else {
             trigger_error($dbcon->ErrorMsg());
         }
     }
 }
Example #8
0
 function overview($params)
 {
     $ret_array = array();
     if (isset($params['range']) && $params['range'] != '') {
         $range = $params['range'];
     } else {
         $range = 1;
     }
     if (isset($params['navigation']) && $params['navigation'] != '') {
         $navigation = $params['navigation'];
     } else {
         $navigation = -1;
     }
     $start_date = date('Y-m-d', strtotime($range * $navigation . ' month'));
     if (isset($params['end_date']) && $params['end_date'] != '') {
         $end_date = $params['end_date'];
     } else {
         $end_date = date('Y-m-d', strtotime($start_date . ' +' . $range . ' months'));
     }
     switch ($range) {
         case 1:
             $send_end_date = $end_date;
             break;
         case 3:
         case 6:
             $start_date = date('Y-m-d', strtotime('-1 sunday', strtotime($start_date)));
             $end_date = date('Y-m-d', strtotime('+0 saturday', strtotime($end_date)));
             $send_end_date = date('Y-m-d', strtotime('-1 sunday', strtotime($end_date)));
             break;
         case 12:
             $start_date = date('Y-m-01', strtotime($start_date));
             $end_date = date('Y-m-t', strtotime($end_date));
             $send_end_date = date('Y-m-01', strtotime($end_date));
             break;
     }
     $hours = Hour::getMany(array('staff_id' => $params['id'], 'hour_search' => array('start_date' => $start_date, 'end_date' => $end_date)));
     $hours_array = array();
     foreach ($hours as $hour) {
         switch ($range) {
             case 3:
             case 6:
                 $hour->itemdata['date'] = date('Y-m-d', strtotime('-1 sunday', strtotime($hour->itemdata['date'])));
                 break;
             case 12:
                 $hour->itemdata['date'] = date('Y-m-01', strtotime($hour->itemdata['date']));
                 break;
         }
         array_push($hours_array, array('date' => $hour->itemdata['date'], 'hours' => $hour->itemdata['hours'] - $hour->itemdata['discount'], 'discount' => $hour->itemdata['discount']));
     }
     $this->data->hours = $hours_array;
     $this->data->start_date = $start_date;
     $this->data->end_date = $send_end_date;
 }
Example #9
0
    function testCreateFormForOneObject()
    {
        $hour = new Hour();
        $hour->set(array('description' => 'SimpleTest Hour Description 2', 'support_contract_id' => 1, 'date' => '2010-02-20', 'hours' => '2.5', 'discount' => '1'));
        $hour->save();
        $hour_id = $hour->get('id');
        $form = new Form(array('controller' => 'Hour', 'action' => 'update', 'method' => 'post'));
        $f = $form->getFieldSetFor($hour);
        $html = $f->description;
        $html .= $f->hours;
        $html .= $f->discount;
        $form->content = $html;
        $form_html = $form->html;
        $correct_html = '<form method="post" action="index.php" class = "standard-form" >
<input type="hidden" name="controller" value="Hour"/>
<input type="hidden" name="action" value="update"/>
<input type="text" value="SimpleTest Hour Description 2" id = "ActiveRecord[Hour][' . $hour_id . '][description]" class = "description-field Hour-field text-field" name = "ActiveRecord[Hour][' . $hour_id . '][description]" /><input type="text" value="2.5" id = "ActiveRecord[Hour][' . $hour_id . '][hours]" class = "hours-field Hour-field float-field" name = "ActiveRecord[Hour][' . $hour_id . '][hours]" /><input type="text" value="1" id = "ActiveRecord[Hour][' . $hour_id . '][discount]" class = "discount-field Hour-field float-field" name = "ActiveRecord[Hour][' . $hour_id . '][discount]" /><div class="submit-container"><input type="submit" class="submit_btn" value="submit"/></div>
</form>
';
        $this->assertEqual($correct_html, $form_html);
        $hour->delete();
    }
Example #10
0
 function getHours($criteria = array())
 {
     $criteria = array_merge(array('support_contract_id' => $this->id), $criteria);
     $this->hours = Hour::getMany($criteria);
     return $this->hours;
 }
Example #11
0
 function destroy($params)
 {
     if (empty($params['id'])) {
         bail('Required parameter "id" is missing.');
     }
     $hour = new Hour($params['id']);
     $project_id = $hour->getProject()->id;
     $hour->destroy();
     $this->redirectTo(array('controller' => 'Project', 'action' => 'show', 'id' => $project_id));
 }
Example #12
0
 function testCalculateBalanceWithDateRange()
 {
     #Company
     $cp = new Company();
     $cp->set(array('name' => 'Test Company', 'status' => 'active'));
     $cp->save();
     $pb = new CompanyPreviousBalance();
     $pb->set(array('company_id' => $cp->id, 'amount' => 600.25, 'date' => '2010-01-30'));
     $pb->save();
     $this->assertWithinMargin($pb->getAmount(), '600.25', '.01');
     ######### Support
     $sc = new SupportContract();
     $sc->set(array('company_id' => $cp->id, 'domain_name' => 'Test', 'start_date' => '2010-01-01', 'end_date' => '2010-04-30', 'hourly_rate' => '120', 'support_hours' => '.5', 'monthly_rate' => '50'));
     $sc->save();
     # add support hours
     # before previous balance
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-01-20', 'hours' => '2.5'));
     $h->save();
     # in range
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-02-20', 'hours' => '2.5'));
     $h->save();
     # in range
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-03-20', 'hours' => '2.5'));
     $h->save();
     # out of range
     $h = new Hour();
     $h->set(array('description' => 'Test', 'support_contract_id' => $sc->id, 'date' => '2010-05-20', 'hours' => '2'));
     $h->save();
     ### Support Totals = in range is 2 months x 50 = 100, 4 @ 120 = 480 = 580
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $total = $cp->calculateSupportTotal($date_range);
     $this->assertEqual($total, 580);
     ###### Project
     $pj = new Project();
     $pj->set(array('name' => 'Test Project', 'company_id' => $cp->id, 'hourly_rate' => '120'));
     $pj->save();
     # Add an Estimate item #1
     $es1 = new Estimate();
     $es1->set(array('project_id' => $pj->id, 'name' => 'Test Estimate 1', 'high_hours' => '10', 'low_hours' => '5'));
     $es1->save();
     # Add an Estimate item #2
     $es2 = new Estimate();
     $es2->set(array('project_id' => $pj->id, 'name' => 'Test Estimate 2', 'high_hours' => '10', 'low_hours' => '5'));
     $es2->save();
     # Add some before previous balance hours for #1 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es1->id, 'description' => 'Test Hours for Estimate 1', 'date' => '2010-01-15', 'hours' => '5'));
     $hr->save();
     # Add some in range hours for #1 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es1->id, 'description' => 'Test Hours for Estimate 1', 'date' => '2010-02-15', 'hours' => '5'));
     $hr->save();
     # Add some in range hours for #2 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es2->id, 'description' => 'Test Hours for Estimate 2', 'date' => '2010-02-15', 'hours' => '5'));
     $hr->save();
     # Add some out of range hours for #2 - 5 hours at 120 = 600
     $hr = new Hour();
     $hr->set(array('estimate_id' => $es2->id, 'description' => 'Test Hours for Estimate 2', 'date' => '2010-05-15', 'hours' => '5'));
     $hr->save();
     ## Project Totals = In range 1200, out of range 1800
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $total = $cp->calculateProjectsTotal($date_range);
     $this->assertEqual($total, 1200);
     #Charge
     # before previous balance
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-01-10', 'amount' => '20.50'));
     $cr->save();
     # in date range
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-03-14', 'amount' => '50.25'));
     $cr->save();
     # in date range
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-03-20', 'amount' => '50'));
     $cr->save();
     # out of date range
     $cr = new Charge();
     $cr->set(array('name' => 'Test', 'company_id' => $cp->id, 'date' => '2010-05-15', 'amount' => '50'));
     $cr->save();
     # Total Charges = in range 100.25, out of range 150.25
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $charge_total = $cp->calculateChargesTotal($date_range);
     $this->assertEqual($charge_total, 100.25);
     ## Test Total Costs
     # Charges 100.25 + project 1200 + support 580
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $total = $cp->calculateCosts($date_range);
     $this->assertEqual($total, 1880.25);
     ## Payments
     # add payment before previous balance date
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-01-22', 'amount' => '20.50'));
     $py->save();
     # add payment in range
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-02-10', 'amount' => '20.00'));
     $py->save();
     # add payment in range
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-03-01', 'amount' => '120.00'));
     $py->save();
     # add payment out of range
     $py = new Payment();
     $py->set(array('company_id' => $cp->id, 'date' => '2010-04-01', 'amount' => '20.25'));
     $py->save();
     # Total Payments are 20 + 120 = 140 in range and after previous balance
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $payment_total = $cp->calculatePaymentsTotal($date_range);
     $this->assertEqual($payment_total, 140);
     #### fails because the previous balance isn't getting included FIX ME!!
     # Total Balance Costs 1880.25 - Payments 140 + Previous balance 600.25 = 2340.5
     $date_range = array('start_date' => '2010-01-01', 'end_date' => '2010-03-31');
     $balance = $cp->calculateBalance($date_range);
     $this->assertWithinMargin($balance, 2340.5, 0.001);
     ## clean up
     $cp->destroyAssociatedRecords();
     $cp->delete();
 }
Example #13
0
echo $form->labelEx($model, 'ID_Room:', array('class' => 'control-label'));
?>
		<?php 
echo $form->dropdownList($model, 'ID_Room', Room::getRoomOptions(), array('class' => 'form-control'));
?>
		<?php 
echo $form->error($model, 'ID_Room', array('class' => 'text-danger'));
?>
	</div>

	<div class="form-group">
		<?php 
echo $form->labelEx($model, 'ID_Hour:', array('class' => 'control-label'));
?>
		<?php 
echo $form->dropdownList($model, 'ID_Hour', Hour::getHourOptions(), array('class' => 'form-control'));
?>
		<?php 
echo $form->error($model, 'ID_Hour', array('class' => 'text-danger'));
?>
	</div>

	<div class="form-group">
		<?php 
echo $form->labelEx($model, 'ID_Subject:', array('class' => 'control-label'));
?>
		<?php 
echo $form->dropdownList($model, 'ID_Subject', Subject::getSubjectOptions(), array('class' => 'form-control'));
?>
		<?php 
echo $form->error($model, 'ID_Subject', array('class' => 'text-danger'));
Example #14
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Hour the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Hour::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
  public function add_single(Hour $hour) {
    $hours = count($this->hours);
    if($hours && $hour->getHour() < $this->hours[$hours-1]->getHour()) {
      $this->past_midnight = True;
    }

    if($this->past_midnight) {
      $hour->pastMidnight();
    }

    $this->hours[] = $hour;
  }
Example #16
0
 public function actionGetSessionOptions()
 {
     $_SESSION['idSubject'] = $_POST['id'];
     $result = '';
     if ($_SESSION['idSubject'] != 0) {
         $sql_hour = "SELECT \n                        ssj.Hour\n                        FROM tbl_classmanager AS cm \n                        INNER JOIN tbl_class_subject AS csj ON csj.ID_CLass = cm.ID \n                        INNER JOIN tbl_subject AS sj ON sj.ID = csj.ID_Subject \n                        INNER JOIN tbl_semester_subject AS ssj ON ssj.ID_Subject = sj.ID \n                        INNER JOIN tbl_hour AS h ON h.ID = csj.ID_Hour \n                        WHERE ssj.ID_Subject = :idSubject AND csj.ID_Class = :idClass AND csj.ID_Facuty = :idFacuty";
         $sql_type = "SELECT \n                        h.Type\n                        FROM tbl_classmanager AS cm \n                        INNER JOIN tbl_class_subject AS csj ON csj.ID_CLass = cm.ID \n                        INNER JOIN tbl_subject AS sj ON sj.ID = csj.ID_Subject \n                        INNER JOIN tbl_semester_subject AS ssj ON ssj.ID_Subject = sj.ID \n                        INNER JOIN tbl_hour AS h ON h.ID = csj.ID_Hour \n                        WHERE ssj.ID_Subject = :idSubject AND csj.ID_Class = :idClass AND csj.ID_Facuty = :idFacuty";
         $total_hour = SemesterSubject::model()->findBySql($sql_hour, array('idSubject' => $_SESSION['idSubject'], 'idClass' => $_SESSION['idClass'], 'idFacuty' => Yii::app()->user->getState('idUser')));
         $hour_type = Hour::model()->findBySql($sql_type, array('idSubject' => $_SESSION['idSubject'], 'idClass' => $_SESSION['idClass'], 'idFacuty' => Yii::app()->user->getState('idUser')));
         $sessions = $this->getAttendanceSession(Yii::app()->user->getState('idUser'), $this->getIdClassSubject($_SESSION['idClass'], $_SESSION['idSubject'], Yii::app()->user->getState('idUser')));
         if (strtoupper($hour_type->Type) == 'E') {
             $session = $total_hour->Hour / 3;
         } else {
             $session = $total_hour->Hour / 2;
         }
         if ($session == 0) {
             $result .= '<option value="0">Không Session</option>';
         } else {
             $result .= '<option value="0">Chọn session</option>';
             for ($i = 0; $i < $session; $i++) {
                 $disabled = '';
                 foreach ($sessions as $sess) {
                     if ($sess->Session == $i + 1) {
                         $disabled = ' class="disabled" ';
                     }
                 }
                 $result .= '<option value="' . ($i + 1) . '" ' . $disabled . '> Session ' . ($i + 1) . '</option>';
             }
         }
         echo $result;
     } else {
         echo '<option value="0">Chưa chọn lớp học</option>';
     }
 }
<?php

chdir(realpath(dirname(__FILE__)) . '/..');
require 'vendor/autoload.php';
require 'config.php';
// Database
require 'db_setup.php';
// Truncate 'hours' table
Hour::truncate();
// Reprocess 'raw_hours' data by hour
$dates = RawHour::groupBy('date')->orderBy('date')->lists('date');
foreach ($dates as $date) {
    // Generate current aggregated download and upload lists
    $users_downloaded = RawHour::where('date', '=', $date)->where('dst_user_name', '!=', '')->groupBy('dst_user_name')->select('users.id', 'dst_user_name as user_name', 'dst_addr as ipaddr', $db->connection()->raw('sum(bytes) as downloaded'))->leftJoin('users', 'dst_user_name', '=', 'users.name')->get()->toArray();
    $users_uploaded = RawHour::where('date', '=', $date)->where('src_user_name', '!=', '')->groupBy('src_user_name')->select('users.id', 'src_user_name as user_name', 'src_addr as ipaddr', $db->connection()->raw('sum(bytes) as uploaded'))->leftJoin('users', 'src_user_name', '=', 'users.name')->get()->toArray();
    // Parse user data
    foreach ($users_downloaded as $user_downloaded) {
        // Update users table
        if (!($user = User::where('name', '=', $user_downloaded['user_name'])->first())) {
            $user = new User();
            $user->name = $user_downloaded['user_name'];
        }
        $user->lastip = $user_downloaded['ipaddr'];
        $user->firstseen = isset($user->firstseen) && $user->firstseen != false ? $user->firstseen : $date;
        $user->lastseen = $date;
        $user->save();
        // Determine user usage data
        $downloaded = $user_downloaded['downloaded'];
        $uploaded = 0;
        foreach ($users_uploaded as $user_uploaded) {
            if ($user_uploaded['user_name'] == $user->name) {
Example #18
0
 private function getHours()
 {
     $hours_cc = new ConstraintChain();
     if (empty($this->_data['week_ending'])) {
         $this->_data['week_ending'] = date(DATE_FORMAT, strtotime('friday'));
     }
     $hours_cc->add(new Constraint('start_time', '<=', fix_date($this->_data['week_ending'])));
     $hours_cc->add(new Constraint('start_time', '>', date('Y-m-d', strtotime('last monday', strtotime(fix_date($this->_data['week_ending']))))));
     if (!isModuleAdmin()) {
         $hours_cc->add(new Constraint('owner', '=', EGS_USERNAME));
     } else {
         if (!empty($this->_data['username'])) {
             $hours_cc->add(new Constraint('owner', '=', $this->_data['username']));
         }
     }
     if (!empty($this->_data['project_id'])) {
         $hours_cc > add(new Constraint('project_id', '=', $this->_data['project_id']));
         //for a single project
     }
     $hours = Hour::getForTimesheet($hours_cc);
     return $hours;
 }
Example #19
0
 function getHours($search_criteria = array())
 {
     $criteria = array_merge(array('estimate_id' => $this->id), $search_criteria, array('sort' => 'date DESC'));
     $this->hours = Hour::getMany($criteria);
     return $this->hours;
 }
Example #20
0
 public static function getHourOptions()
 {
     return CHtml::listData(Hour::model()->findAll(), 'ID', 'Value');
 }