reports fix

This commit is contained in:
2024-02-01 00:57:42 +03:00
parent 1279d5ac17
commit 1bcc7834c2
8 changed files with 355 additions and 233 deletions

View File

@ -3,6 +3,7 @@
namespace frontend\modules\api\models;
use common\classes\Debug;
use common\models\Reports;
use yii\base\Model;
@ -10,6 +11,7 @@ use yii\base\Model;
class ReportSearchForm extends Model
{
public $user_card_id;
public $user_id;
public $limit;
public $offset;
/** @var string */
@ -22,6 +24,7 @@ class ReportSearchForm extends Model
$this->limit = 10;
$this->offset = 0;
$this->user_card_id = null;
$this->user_id = null;
$this->toDate = date('Y-m-d');
$this->fromDate = date('Y-m-d');
@ -36,7 +39,7 @@ class ReportSearchForm extends Model
[['byDate'], 'safe'],
[['fromDate', 'toDate', 'date'], 'string'],
// [['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'],
[[ 'user_card_id'], 'integer', 'min' => 0],
[[ 'user_card_id', 'user_id'], 'integer', 'min' => 0],
];
}
@ -48,8 +51,8 @@ class ReportSearchForm extends Model
$queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]);
}
if (isset($this->user_card_id)) {
$queryBuilder->andWhere(['reports.user_card_id' => $this->user_card_id]);
if (isset($this->user_id)) {
$queryBuilder->andWhere(['reports.user_id' => $this->user_id]);
}
$queryBuilder->limit($this->limit)
@ -61,7 +64,7 @@ class ReportSearchForm extends Model
public function findByDate()
{
return Reports::find()->with('task')
->where(['reports.user_card_id' => $this->user_card_id])
->where(['reports.user_id' => $this->user_id])
->andWhere(['reports.created_at' => $this->date])
->asArray()->all();
}
@ -69,7 +72,7 @@ class ReportSearchForm extends Model
public function reportsByDate()
{
return Reports::find()->with('task')
->where(['reports.user_card_id' => $this->user_card_id])
->where(['reports.user_id' => $this->user_id])
->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate])
->asArray()->all();
}

View File

@ -35,6 +35,12 @@ namespace frontend\modules\api\models;
* description="ID карты(профиля) пользователя"
* ),
* @OA\Property(
* property="user_id",
* type="integer",
* example=23,
* description="ID пользователя"
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* example=1,
@ -75,6 +81,10 @@ namespace frontend\modules\api\models;
* type="integer",
* ),
* @OA\Property(
* property="user_id",
* type="integer",
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* ),
@ -111,6 +121,10 @@ namespace frontend\modules\api\models;
* type="integer",
* ),
* @OA\Property(
* property="user_id",
* type="integer",
* ),
* @OA\Property(
* property="project_id",
* type="integer",
* ),