create project

This commit is contained in:
2024-04-24 18:02:58 +03:00
commit 17df2ce6a9
276 changed files with 15932 additions and 0 deletions

View File

@ -0,0 +1,73 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "addresses".
*
* @property int $id
* @property string $address
* @property int $company_id
* @property string|null $name
*
* @property Check[] $checks
* @property Company $company
*/
class Addresses extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'addresses';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['address', 'company_id'], 'required'],
[['company_id'], 'integer'],
[['address', 'name'], 'string', 'max' => 255],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'address' => 'Адрес',
'company_id' => 'Компания',
'name' => 'Название',
];
}
/**
* Gets query for [[Checks]].
*
* @return \yii\db\ActiveQuery
*/
public function getChecks()
{
return $this->hasMany(Check::class, ['addresses_id' => 'id']);
}
/**
* Gets query for [[Company]].
*
* @return \yii\db\ActiveQuery
*/
public function getCompany()
{
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
}

111
common/models/Check.php Normal file
View File

@ -0,0 +1,111 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "check".
*
* @property int $id
* @property string $number
* @property int $company_id
* @property string $additional
* @property string $title
* @property int $addresses_id
* @property int|null $status
*
* @property Addresses $addresses
* @property Company $company
*/
class Check extends \yii\db\ActiveRecord
{
const STATUS_NEW = 1;
const STATUS_PRINTED = 2;
const STATUS_PAID = 3;
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::STATUS_NEW => 'Новый',
self::STATUS_PRINTED => 'Напечатан',
self::STATUS_PAID => 'Оплачен',
];
}
/**
* @return string[]
*/
public static function getStatusColor(): array
{
return [
self::STATUS_NEW => '#FFA500',
self::STATUS_PRINTED => '#008080',
self::STATUS_PAID => '#32CD32',
];
}
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'check';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['number', 'company_id', 'addresses_id'], 'required'],
[['company_id', 'addresses_id', 'status'], 'integer'],
[['number', 'title'], 'string', 'max' => 255],
[['additional'], 'string'],
[['addresses_id'], 'exist', 'skipOnError' => true, 'targetClass' => Addresses::class, 'targetAttribute' => ['addresses_id' => 'id']],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'number' => 'Номер',
'company_id' => 'Компания',
'additional' => 'Дополнительная информация',
'title' => 'Заголовок',
'addresses_id' => 'Отделение',
'status' => 'Статус',
];
}
/**
* Gets query for [[Addresses]].
*
* @return \yii\db\ActiveQuery
*/
public function getAddresses(): \yii\db\ActiveQuery
{
return $this->hasOne(Addresses::class, ['id' => 'addresses_id']);
}
/**
* Gets query for [[Company]].
*
* @return \yii\db\ActiveQuery
*/
public function getCompany(): \yii\db\ActiveQuery
{
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "check_product".
*
* @property int $check_id
* @property int $product_id
* @property int|null $quantity
*
* @property Check $check
* @property Product $product
*/
class CheckProduct extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'check_product';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['check_id', 'product_id'], 'required'],
[['check_id', 'product_id', 'quantity'], 'integer'],
[['check_id', 'product_id'], 'unique', 'targetAttribute' => ['check_id', 'product_id']],
[['check_id'], 'exist', 'skipOnError' => true, 'targetClass' => Check::class, 'targetAttribute' => ['check_id' => 'id']],
[['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::class, 'targetAttribute' => ['product_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'check_id' => 'Check ID',
'product_id' => 'Product ID',
'quantity' => 'Quantity',
];
}
/**
* Gets query for [[Check]].
*
* @return \yii\db\ActiveQuery
*/
public function getCheck()
{
return $this->hasOne(Check::class, ['id' => 'check_id']);
}
/**
* Gets query for [[Product]].
*
* @return \yii\db\ActiveQuery
*/
public function getProduct()
{
return $this->hasOne(Product::class, ['id' => 'product_id']);
}
}

125
common/models/Company.php Normal file
View File

@ -0,0 +1,125 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
/**
* This is the model class for table "company".
*
* @property int $id
* @property string $inn
* @property int $user_id
* @property string $name
* @property string|null $address
* @property int|null $created_at
* @property int|null $updated_at
* @property int|null $status
*
* @property Addresses[] $addresses
* @property Check[] $checks
* @property Product[] $products
*/
class Company extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_INACTIVE = 0;
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::STATUS_ACTIVE => 'Активна',
self::STATUS_INACTIVE => 'Не активна',
];
}
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'company';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['inn', 'name', 'user_id'], 'required'],
[['created_at', 'updated_at'], 'safe'],
[['status', 'user_id'], 'integer'],
[['name', 'address', 'inn'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'inn' => 'ИНН',
'name' => 'Название',
'address' => 'Адрес',
'created_at' => 'Дата создания',
'updated_at' => 'Дата редактирования',
'status' => 'Статус',
'user_id' => 'Пользователь',
];
}
/**
* Gets query for [[Addresses]].
*
* @return \yii\db\ActiveQuery
*/
public function getAddresses()
{
return $this->hasMany(Addresses::class, ['company_id' => 'id']);
}
/**
* Gets query for [[Checks]].
*
* @return \yii\db\ActiveQuery
*/
public function getChecks()
{
return $this->hasMany(Check::class, ['company_id' => 'id']);
}
/**
* Gets query for [[Products]].
*
* @return \yii\db\ActiveQuery
*/
public function getProducts()
{
return $this->hasMany(Product::class, ['company_id' => 'id']);
}
public static function getMyCompany()
{
$companies = self::find()->where(['user_id' => Yii::$app->user->id])->all();
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace common\models;
use common\classes\Debug;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_user;
/**
* {@inheritdoc}
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return bool whether the user is logged in successfully
*/
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
}
return false;
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
}

97
common/models/Product.php Normal file
View File

@ -0,0 +1,97 @@
<?php
namespace common\models;
use Yii;
use function Symfony\Component\String\s;
/**
* This is the model class for table "product".
*
* @property int $id
* @property string $title
* @property string $article
* @property int $company_id
* @property int|null $type
* @property int|null $price
* @property int|null $status
*
* @property Company $company
*/
class Product extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_INACTIVE = 0;
const TYPE_PIECE = 1;
const TYPE_WEIGHT = 2;
/**
* @return string[]
*/
public static function getType(): array
{
return [
self::TYPE_PIECE => 'шт.',
self::TYPE_WEIGHT => 'кг.',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::STATUS_ACTIVE => 'Активна',
self::STATUS_INACTIVE => 'Не активна',
];
}
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'product';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'article', 'company_id'], 'required'],
[['company_id', 'type', 'price', 'status'], 'integer'],
[['title', 'article'], 'string', 'max' => 255],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Название',
'article' => 'Артикул',
'company_id' => 'Компания',
'type' => 'Тип',
'price' => 'Цена',
'status' => 'Статус',
];
}
/**
* Gets query for [[Company]].
*
* @return \yii\db\ActiveQuery
*/
public function getCompany()
{
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "product_category".
*
* @property int $id
* @property string $title
* @property int|null $parent_id
* @property int $company_id
* @property int|null $status
*
* @property Company $company
*/
class ProductCategory extends \yii\db\ActiveRecord
{
const STATUS_ACTIVE = 1;
const STATUS_NOACTIVE = 0;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'product_category';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'company_id'], 'required'],
[['parent_id', 'company_id', 'status'], 'integer'],
[['title'], 'string', 'max' => 255],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Название',
'parent_id' => 'Родительская категория',
'company_id' => 'Компания',
'status' => 'Статус',
];
}
/**
* @return string[]
*/
public static function getStatus(): array
{
return [
self::STATUS_ACTIVE => "Активна",
self::STATUS_NOACTIVE => "Не активна"
];
}
/**
* Gets query for [[Company]].
*
* @return \yii\db\ActiveQuery
*/
public function getCompany()
{
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
}

222
common/models/User.php Normal file
View File

@ -0,0 +1,222 @@
<?php
namespace common\models;
use Yii;
use yii\base\NotSupportedException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
/**
* User model
*
* @property integer $id
* @property string $username
* @property string $password_hash
* @property string $password_reset_token
* @property string $verification_token
* @property string $email
* @property string $auth_key
* @property integer $status
* @property integer $created_at
* @property integer $updated_at
* @property string $password write-only password
*/
class User extends ActiveRecord implements IdentityInterface
{
const STATUS_DELETED = 0;
const STATUS_INACTIVE = 9;
const STATUS_ACTIVE = 10;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return '{{%user}}';
}
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
TimestampBehavior::class,
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE, self::STATUS_DELETED]],
];
}
/**
* {@inheritdoc}
*/
public static function findIdentity($id)
{
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
}
/**
* {@inheritdoc}
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
}
/**
* Finds user by password reset token
*
* @param string $token password reset token
* @return static|null
*/
public static function findByPasswordResetToken($token)
{
if (!static::isPasswordResetTokenValid($token)) {
return null;
}
return static::findOne([
'password_reset_token' => $token,
'status' => self::STATUS_ACTIVE,
]);
}
/**
* Finds user by verification email token
*
* @param string $token verify email token
* @return static|null
*/
public static function findByVerificationToken($token)
{
return static::findOne([
'verification_token' => $token,
'status' => self::STATUS_INACTIVE
]);
}
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return bool
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token)) {
return false;
}
$timestamp = (int)substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->getPrimaryKey();
}
/**
* {@inheritdoc}
*/
public function getAuthKey()
{
return $this->auth_key;
}
/**
* {@inheritdoc}
*/
public function validateAuthKey($authKey)
{
return $this->getAuthKey() === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return Yii::$app->security->validatePassword($password, $this->password_hash);
}
/**
* Generates password hash from password and sets it to the model
*
* @param string $password
*/
public function setPassword($password)
{
$this->password_hash = Yii::$app->security->generatePasswordHash($password);
}
/**
* Generates "remember me" authentication key
*/
public function generateAuthKey()
{
$this->auth_key = Yii::$app->security->generateRandomString();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Generates new token for email verification
*/
public function generateEmailVerificationToken()
{
$this->verification_token = Yii::$app->security->generateRandomString() . '_' . time();
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_reset_token = null;
}
/**
* @return \yii\db\ActiveQuery
*/
public function getMyCompany(): \yii\db\ActiveQuery
{
return $this->hasMany(Company::class, ['user_id' => 'id']);
}
}