Your IP : 216.73.216.79


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

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "customer".
 *
 * @property int $id
 * @property string $uuid
 * @property string $type
 * @property int $parent_id
 * @property string $name
 * @property string $reg_no
 * @property string $address1
 * @property string $address2
 * @property string $postcode
 * @property string $city
 * @property string $state
 * @property string $contact_name
 * @property string $contact_no
 * @property string $contact_email
 * @property string $contact_fax
 * @property string $created_dt
 * @property int $created_by
 * @property string $updated_dt
 * @property int $updated_by
 */
class Customer extends \yii\db\ActiveRecord {

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

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['uuid', 'type', 'name', 'address1', 'postcode', 'city', 'state', 'contact_name', 'contact_no'], 'required'],
            [['parent_id', 'created_by', 'updated_by', 'contact_no', 'contact_fax', 'postcode'], 'integer'],
            [['created_dt', 'updated_dt', 'contact_email', 'cat', 'account_bank', 'account_name', 'account_number'], 'safe'],
            [['name', 'address1', 'address2', 'city', 'contact_name', 'contact_email', 'contact_officeno'], 'string', 'max' => 255],
            [['type'], 'string', 'max' => 10],
            [['reg_no', 'state', 'contact_no', 'contact_fax'], 'string', 'max' => 20],
            [['postcode'], 'string', 'max' => 5],
            [['uuid'], 'unique'],
            [['contact_email'], 'email'],
            ['parent_id', 'required', 'when' => function ($model) {
                    return $model->type != 'parent';
                }, 'whenClient' => "function (attribute, value) {
  return $('#customer-type').val() != 'parent';
}"]
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'uuid' => 'Uuid',
            'type' => 'Type',
            'parent_id' => 'Parent Company',
            'name' => 'Customer Name',
            'reg_no' => 'Registration Number',
            'address1' => 'Address',
            'address2' => 'Address2',
            'postcode' => 'Postcode',
            'city' => 'City',
            'state' => 'State',
            'contact_name' => 'Contact Person',
            'contact_no' => 'Mobile Phone',
            'contact_email' => 'Email',
            'contact_fax' => 'Fax Number',
            'created_dt' => 'Created Dt',
            'created_by' => 'Created By',
            'updated_dt' => 'Updated Dt',
            'updated_by' => 'Updated By',
            'contact_officeno' => 'Office Number',
            'cat' => 'Category',
            'account_bank' => 'Account Bank',
            'account_name' => 'Account Holder Name',
            'account_number' => 'Account Number',
        ];
    }

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

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

    public function getcustomerdetails($id) {
        $output = '';
        if (($model = static::findOne($id)) !== null) {
            $output = $model->name . '<->' .
                    $model->address1 . '<->' .
                    $model->address2 . '<->' .
                    $model->postcode . '<->' .
                    $model->city . '<->' .
                    $model->state . '<->' .
                    $model->contact_name . '<->' .
                    $model->contact_no;
        }

        return $output;
    }

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

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

}