| Current Path : /var/www/html/project/models/ |
| Current File : /var/www/html/project/models/Projects.php |
<?php
namespace app\models;
use Yii;
use app\models\Tasks;
/**
* This is the model class for table "projects".
*
* @property int $id
* @property string $name
* @property string $start_dt
* @property string $end_dt
* @property int $staff_me
* @property int $staff_gd
* @property int $staff_wd
* @property int $staff_cw
* @property string $progress
* @property int $status
* @property string $created_dt
* @property int $created_by
* @property string $updated_dt
* @property int $updated_by
*/
class Projects extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'projects';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['start_dt', 'end_dt', 'name', 'cat'], 'required'],
[['start_dt', 'end_dt', 'created_dt', 'updated_dt', 'staff_me', 'staff_gd', 'staff_wd', 'staff_cw', 'template_id'], 'safe'],
[['staff_me', 'staff_gd', 'staff_wd', 'staff_cw', 'status', 'created_by', 'updated_by'], 'integer'],
[['name', 'progress'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'name' => 'Project Name',
'start_dt' => 'Project Start Date',
'end_dt' => 'Project End Date',
'staff_me' => 'Marketing Executive',
'staff_gd' => 'Graphic Designer',
'staff_wd' => 'Web Designer',
'staff_cw' => 'Content Writer',
'progress' => 'Progress',
'status' => 'Status',
'created_dt' => 'Created Dt',
'created_by' => 'Created By',
'updated_dt' => 'Updated Dt',
'updated_by' => 'Updated By',
'template_id' => 'Workflow Template',
'cat' => 'Category',
];
}
public function getname($id) {
$output = '';
if (($model = static::findOne($id)) !== null) {
$output = $model->name;
}
return $output;
}
public function getduedays($end_dt) {
$output = '';
//$now = date('Y-m-d');
//$your_date = strtotime($end_dt);
$datediff = strtotime($end_dt) - strtotime(date('Y-m-d'));
$duedays = round($datediff / (60 * 60 * 24));
if ($duedays > 0)
$output = '<span class="kt-font-bold kt-font-success">' . $duedays . ' days left</span>';
if ($duedays == 0)
$output = '<span class="kt-font-bold kt-font-warning">Due today</span>';
if ($duedays < 0)
$output = '<span class="kt-font-bold kt-font-danger">' . abs($duedays) . ' days overdue</span>';
return $output;
}
public function displayprogress($progress, $end_dt, $project_id) {
$output = '';
$totaltask = Tasks::find()
->where(['project_id' => $project_id])
->andwhere(['deleted_status' => '0'])
->andwhere(['OR', ['=', 'task_type', 'step'], ['=', 'task_type', 'product']])
->count();
if ($totaltask > 0) {
if ($progress == 'Pending')
$output = '<span class="btn btn-label-dark btn-sm btn-bold btn-block text-nowrap">Not Started</span>';
if ($progress == 'On-going') {
if ($end_dt < date('Y-m-d'))
$output = '<span class="btn btn-label-danger btn-sm btn-bold btn-block">Overdue</span>';
else
$output = '<span class="btn btn-label-warning btn-sm btn-bold btn-block">On-Going</span>';
}
if ($progress == 'Complete')
$output = '<span class="btn btn-label-success btn-sm btn-bold btn-block">Complete</span>';
}
return $output;
}
public function getsummary1() {
$query = Projects::find();
$query->andWhere(['=', 'status', '1']);
return $query->count();
}
public function getsummary2() {
$query = Projects::find();
$query->andWhere(['=', 'status', '1']);
$query->andWhere(['=', 'progress', 'On-going']);
return $query->count();
}
public function getsummary3() {
$query = Projects::find();
$query->andWhere(['=', 'status', '1']);
$query->andWhere(['=', 'progress', 'Complete']);
return $query->count();
}
public function getsummary4() {
$query = Projects::find();
$query->andWhere(['=', 'status', '1']);
$query->andWhere(['=', 'progress', 'On-going']);
$query->andWhere(['AND', ['=', 'progress', 'On-going'], ['<', 'end_dt', date('Y-m-d')]]);
return $query->count();
}
}