function index($params)
 {
     $this->data->new_contract = new SupportContract();
     $this->data->contracts = getMany('SupportContract', array("sort" => "status, company_id"));
     $this->data->new_hour = new Hour();
     $this->data->new_hour->set(array('staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
 }
 function index($params)
 {
     $d = $this->data;
     $d->support_hours = getMany('SupportHour', array('sort' => 'date DESC'));
     $d->new_support_hour = new SupportHour();
     $d->new_support_hour->set(array('staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
 }
function destroyRecords($model, $criteria)
{
    $records = getMany($model, $criteria);
    $i = 0;
    if ($records) {
        foreach ($records as $record) {
            $record->destroyAssociatedRecords();
            $record->delete();
            $i++;
        }
        echo "Deleted {$i} test {$model}: " . array_dump($criteria) . "<br>";
    } else {
        echo "No test {$model} found: " . array_dump($criteria) . "<br>";
    }
}
 function show($params)
 {
     if (!$params['id']) {
         bail('Required parameter "id" is not present.');
     }
     $d = $this->data;
     $d->estimate = new Estimate($params['id']);
     $d->project = new Project($d->estimate->get('project_id'));
     $d->new_hour = new Hour();
     $d->new_hour->set(array('estimate_id' => $params['id'], 'staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
     $d->new_estimate = new Estimate();
     $d->new_estimate->set(array('project_id' => $d->project->id));
     $d->estimates = $d->project->getEstimates();
     $d->hours = getMany('Hour', array('estimate_id' => $params['id'], 'sort' => 'date DESC'));
 }
Beispiel #5
0
 function index($params)
 {
     $d = $this->data;
     if ($this->search_params('hour_search')) {
         $a_year_ago = date('Y-m-d', time() - 60 * 60 * 24 * 365);
         $default_query = array('hour_search' => array('start_date' => $a_year_ago), 'sort' => 'date DESC');
         $hour_query = array_merge($default_query, $this->search_params('hour_search'));
         $d->hours = getMany('Hour', $hour_query);
     } else {
         $d->hours = array();
     }
     $d->new_hour = new Hour();
     $d->new_hour->set(array('staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
     $d->new_support_hour = new Hour();
     $d->new_support_hour->set(array('staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
 }
Beispiel #6
0
 function show($params = array())
 {
     if (!isset($params['id']) || !$params['id']) {
         $staff_members = getAll('Staff');
         if (!isset($params['start_date']) || !isset($params['end_date'])) {
             $hours_criteria = array('current_week' => true);
             $this->data->dates = array('start_date' => date('Y-m-d', strtotime('last Sunday')), 'end_date' => date('Y-m-d', strtotime('next Sunday')));
         } else {
             $hours_criteria = array('hour_search' => array('start_date' => $params['start_date'], 'end_date' => $params['end_date']));
             $this->data->dates = array('start_date' => $params['start_date'], 'end_date' => $params['end_date']);
         }
         foreach ($staff_members as $staff) {
             if (!$staff->get('active')) {
                 continue;
             }
             if (!isset($this->data->billable_hours_this_week)) {
                 $this->data->staff = array();
                 $this->data->billable_hours_this_week = array();
             }
             if (!isset($this->data->total_hours_this_week)) {
                 $this->data->staff = array();
                 $this->data->total_hours_this_week = array();
             }
             $this->data->staff[$staff->get('id')] = $staff->getName();
             $this->data->billable_hours_this_week[$staff->get('id')] = $staff->getBillableHoursTotal($hours_criteria);
             $this->data->total_hours_this_week[$staff->get('id')] = $staff->getHoursTotal($hours_criteria);
         }
     } else {
         $this->data->active_projects = getMany('Project', array('active' => true));
         $staff = new Staff($params['id']);
         $this->data->staff = $staff;
         $this->data->staff_hours = $staff->getHours();
         $hours_criteria = array('current_month' => true);
         $this->data->hours_this_month = $staff->getHoursTotal($hours_criteria);
         $this->data->billable_hours_this_month = $staff->getBillableHoursTotal($hours_criteria);
         $hours_criteria = array('current_week' => true);
         $this->data->hours_this_week = $staff->getHoursTotal($hours_criteria);
         $this->data->billable_hours_this_week = $staff->getBillableHoursTotal($hours_criteria);
         $this->data->new_project = new Project();
         $this->data->new_project->set(array('staff_id' => Session::getUserId()));
         $this->data->new_support_hour = new Hour();
         $this->data->new_support_hour->set(array('staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
         $this->data->graph = array('staff' => $staff->id, 'call' => 'overview');
     }
 }
Beispiel #7
0
 function getHours($criteria = array())
 {
     $criteria = array_merge($criteria, array('staff_id' => $this->id, 'sort' => 'date desc'));
     $this->hours = getMany('Hour', $criteria);
     return $this->hours;
 }
Beispiel #8
0
 function getContacts()
 {
     if (empty($this->contacts)) {
         $this->contacts = getMany('Contact', array('company_id' => $this->id));
     }
     return $this->contacts;
 }
 function index($params)
 {
     $three_months_ago = Util::date_format('-3 months');
     $this->data->payments = getMany('Payment', array('date_range' => array('start_date' => $three_months_ago)));
     $this->data->invoices = getMany('Invoices', array('date_range' => array('start_date' => $three_months_ago)));
 }
Beispiel #10
0
 function classSelect($class, $tokens, $search_criteria = array())
 {
     if (!class_exists($class)) {
         bail("Class \"{$class}\" does not exist.");
     }
     if ($search_criteria) {
         $objects = getMany($class, $search_criteria);
     } else {
         $objects = getAll($class);
     }
     foreach ($objects as $o) {
         $data[$o->id] = $o->getName();
     }
     return $this->select($data, $tokens);
 }
Beispiel #11
0
 function index($params)
 {
     $this->data->new_charge = new Charge();
     $this->data->new_charge->set(array('date' => date('Y-m-d')));
     $this->data->charges = getMany('Charge', array("sort" => "date"));
 }
Beispiel #12
0
 static function getMany($search_criteria)
 {
     return getMany(get_called_class(), $search_criteria);
 }