$employeeOnShiftArray = EmployeeOnShift::find()
->where([
'status' => EmployeeOnShift::STATUS_ACCEPT,
- 'status_source' => EmployeeOnShift::STATUS_SOURCE_NOT_CREATED_IN_1C
+ 'status_source' => EmployeeOnShift::STATUS_SOURCE_NOT_CREATED_IN_1C,
+ 'active' => EmployeeOnShift::ACTIVE_ON,
])
->all();
$result = [];
$model = new EmployeeOnShift($row);
$model->guid = DataHelper::createGuidMy("06");
$model->created_at = date(DATE_ATOM);
+ $model->active = EmployeeOnShift::ACTIVE_ON;
if (!$model->save()) {
throw new InvalidArgumentException(array_values($model->firstErrors)[0] ?? "");
}
public function control(WorkerControl $row) {
- $model = EmployeeOnShift::findOne(['guid' => $row->guid]);
+ $model = EmployeeOnShift::findOne(['guid' => $row->guid, 'active' => EmployeeOnShift::ACTIVE_ON]);
if (!$model) {
throw new InvalidArgumentException('guid не найден');
public function actionCreate()
{
// Удаляем старые заявки
- EmployeeOnShift::deleteAll([
+ EmployeeOnShift::updateAll(['active' => EmployeeOnShift::ACTIVE_OFF], [
'and',
['status' => [EmployeeOnShift::STATUS_INITIAL, EmployeeOnShift::STATUS_REJECT]],
['<=', 'created_at', date('Y-m-d H:i:s', strtotime('-30 minutes', time()))]
// [['guid'], 'unique'],
['created_by', 'exist', 'targetClass' => Admin::class, 'targetAttribute' => 'id', 'filter' => ['group_id' => [1, 7, 8, 10, 30, 35, 40, 50, 51, 71]]],
['store_id', 'exist', 'targetClass' => Products1c::class, 'targetAttribute' => 'id', 'filter' => ['tip' => 'city_store']],
- ['phone', 'unique', 'targetClass' => EmployeeOnShift::class, 'targetAttribute' => ['phone', 'store_id'], 'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL]],
+ ['phone', 'unique', 'targetClass' => EmployeeOnShift::class, 'targetAttribute' => ['phone', 'store_id'], 'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL, 'active' => EmployeeOnShift::ACTIVE_ON]],
['phone', PhoneValidator::class],
['datetime_start', 'checkDateTimeStart']
];
['guid', 'string', 'length' => 36],
['guid', 'exist', 'targetClass' => EmployeeOnShift::class,
'targetAttribute' => 'guid',
- 'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL],
+ 'filter' => ['status' => EmployeeOnShift::STATUS_INITIAL, 'active' => EmployeeOnShift::ACTIVE_ON],
'message' => 'Нет новой заявки с таким guid',
],
];
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240827_061358_alter_table_employee_on_shift_add_column_active
+ */
+class m240827_061358_alter_table_employee_on_shift_add_column_active extends Migration
+{
+ const TABLE_NAME = 'erp24.employee_on_shift';
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->addColumn(self::TABLE_NAME, 'active', $this->tinyInteger()->notNull()->defaultValue(1)
+ ->after('status_source')->comment('0 - не активная заявка 1 - активная заявка, может использоваться в операциях'));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeDown()
+ {
+ $this->dropColumn(self::TABLE_NAME, 'active');
+ }
+}
* @property int $salary_shift Ставка в рублях за смену
* @property int $status 0 - в ожидании, 1 - подтверждено, 2 - отказано
* @property int $status_source -1 - получена ошибка в системе, 0 - не создано, 1 - создано в 1С
+ * @property int $active 0 - не активная заявка 1 - активная заявка, может использоваться в операциях
*/
class EmployeeOnShift extends \yii\db\ActiveRecord
{
+ const ACTIVE_ON = 1;
+ const ACTIVE_OFF = 0;
+
const STATUS_INITIAL = 0;
const STATUS_ACCEPT = 1;
const STATUS_REJECT = 2;
return [
[['guid', 'phone', 'created_at', 'shift_date', 'shift_type', 'datetime_start', 'datetime_end', 'created_by', 'store_id', 'price'], 'required'],
[['created_at', 'shift_date', 'datetime_start', 'datetime_end'], 'safe'],
- [['shift_type', 'created_by', 'price', 'status', 'status_source'], 'integer'],
+ [['shift_type', 'created_by', 'price', 'status', 'status_source', 'active'], 'integer'],
[['salary_shift'], 'in', 'range' => Timetable::getSalariesDay(), 'skipOnEmpty' => false],
[['guid', 'store_id'], 'string', 'max' => 36],
[['phone'], 'string', 'max' => 16],
'salary_shift' => 'Salary Shift',
'status' => 'Status',
'status_source' => 'status_source',
+ 'active' => 'active',
];
}
->all();
$adminsIds = implode(',',ArrayHelper::getColumn($admins, 'id'));
- $phones = ArrayHelper::getColumn(EmployeeOnShift::find()->all(), 'phone');
+ $phones = ArrayHelper::getColumn(EmployeeOnShift::find()->where(['active' => EmployeeOnShift::ACTIVE_ON])->all(), 'phone');
foreach ($admins as $admin) {
/** @var Admin $admin */
$model->created_at = date("Y-m-d H:i:s");
$model->status = EmployeeOnShift::STATUS_ACCEPT;
$model->status_source = EmployeeOnShift::STATUS_SOURCE_NOT_CREATED_IN_1C;
+ $model->active = EmployeeOnShift::ACTIVE_ON;
$model->save();
if ($model->getErrors()) {
$error .= json_encode($model->getErrors(), JSON_UNESCAPED_UNICODE);