Your IP : 216.73.216.79


Current Path : /var/www/html/crm/models/
Upload File :
Current File : /var/www/html/crm/models/Company.php

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "company".
 *
 * @property int $id
 * @property string $uuid
 * @property string $name
 * @property string $reg_no
 * @property string $short_code
 * @property string $address1
 * @property string $address2
 * @property string $postcode
 * @property string $city
 * @property string $state
 * @property string $phone_no
 * @property string $fax_no
 * @property string $email
 * @property string $contact_name
 * @property string $contact_no
 * @property string $contact_email
 * @property string $logo
 * @property string $created_dt
 * @property int $created_by
 * @property string $updated_dt
 * @property int $updated_by
 */
class Company extends \yii\db\ActiveRecord {

    public $file;

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return 'company';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['uuid', 'name', 'short_code', 'address1', 'postcode', 'city', 'state', 'phone_no', 'logo', 'tagline', 'website', 'contact_name', 'contact_no', 'reg_no'], 'required'],
            [['created_dt', 'updated_dt', 'email', 'contact_email', 'contact_officeno', 'stamp', 'account_bank', 'account_name', 'account_number'], 'safe'],
            [['created_by', 'updated_by', 'phone_no', 'fax_no', 'contact_no'], 'integer'],
            [['name', 'address1', 'address2', 'city', 'email', 'contact_name', 'contact_email', 'logo'], 'string', 'max' => 255],
            [['reg_no', 'state', 'phone_no', 'fax_no', 'contact_no'], 'string', 'max' => 20],
            [['short_code'], 'string', 'max' => 3, 'min' => 3],
            [['postcode'], 'string', 'max' => 5],
            [['uuid', 'short_code'], 'unique'],
            [['file'], 'file'],
            [['file'], 'required', 'on' => 'create'],
            [['email', 'contact_email'], 'email'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'uuid' => 'Uuid',
            'name' => 'Company Name',
            'reg_no' => 'Registration Number',
            'short_code' => 'Short Code',
            'address1' => 'Address',
            'address2' => 'Address Line 2',
            'postcode' => 'Postcode',
            'city' => 'City',
            'state' => 'State',
            'phone_no' => 'Phone Number',
            'fax_no' => 'Fax Number',
            'email' => 'Email',
            'contact_name' => 'Contact Person',
            'contact_no' => 'Contact Mobile Phone',
            'contact_email' => 'Contact Email',
            'contact_officeno' => 'Contact Office Number',
            'logo' => 'Logo',
            'created_dt' => 'Created Dt',
            'created_by' => 'Created By',
            'updated_dt' => 'Updated Dt',
            'updated_by' => 'Updated By',
            'file' => 'Logo',
            'tagline' => 'Tagline',
            'website' => 'Website URL',
            'stamp' => 'Company Stamp',
            'account_bank' => 'Account Bank',
            'account_name' => 'Account Holder Name',
            'account_number' => 'Account Number',
        ];
    }

    public function getname($id) {
        $output = '';
        if (($model = static::findOne($id)) !== null) {
            $output = $model->name;
        }
        return $output;
    }

    public function getname2($uuid) {
        $output = '';
        if (($model = static::findOne(['uuid' => $uuid])) !== null) {
            $output = $model->name;
        }
        return $output;
    }

    public function getname3($shortcode) {
        $output = '';
        if (($model = static::findOne(['short_code' => $shortcode])) !== null) {
            $output = $model->name;
        }
        return $output;
    }

    public function getshortcode($id) {
        $output = '';
        if (($model = static::findOne($id)) !== null) {
            $output = $model->short_code;
        }
        return $output;
    }

    public function getid($uuid) {
        $output = '';
        if (($model = static::findOne(['uuid' => $uuid])) !== null) {
            $output = $model->id;
        }
        return $output;
    }

    public function getCompanyList() {
        $output = [];
        $model = static::find()->alias('c')->leftJoin('company_access a', 'a.com_id=c.id')
                        ->where(['=', 'a.user_id', Yii::$app->user->identity->id])->orderBy(['name' => SORT_ASC])->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $arr = [];
                $arr['id'] = $row->id;
                $arr['uuid'] = $row->uuid;
                $arr['name'] = $row->name;
                $arr['logo'] = $row->logo;
                $arr['short_code'] = $row->short_code;
                $arr['reg_no'] = $row->reg_no;
                $output[] = $arr;
            }
        }
        return $output;
    }

    public function getCompanyIdList() {
        $output = [];
        $model = static::find()->alias('c')->leftJoin('company_access a', 'a.com_id=c.id')
                        ->where(['=', 'a.user_id', Yii::$app->user->identity->id])->orderBy(['name' => SORT_ASC])->all();
        if (!empty($model)) {
            foreach ($model as $row) {
                $output[] = $row->id;
            }
        }
        return $output;
    }

}