Example #1
0
    public function getCompanyDetails(){

        return (new Query())->select(
            '('.(new Query())->select('count(*)')->from(Auctions::tableName())->where(['company' => $this->id])->createCommand()->rawSql.') as companyAuctions,'.
            '('.(new Query())->select('count(*)')->from(CompanyUsers::tableName())->where('company=:c and user!=:u',[':c' => $this->id , ':u' => Auction::$app->user->id])->createCommand()->rawSql.') as companyUsers,'.
            '('.(new Query())->select('count(*)')->from(DealerCompany::tableName())->where(['company' => $this->id])->createCommand()->rawSql.') as companyDealers'
        )->one();

    }
Example #2
0
    public function getDealerDetails(){

        return (new Query())->select('Coalesce(ds.security, 0) as `dealerSecurity`,count(dc.id) as dealerCompanies,count(da.dealer) as dealerAuctions')
            ->from(Dealers::tableName(). 'd')
            ->leftJoin(DealerCompany::tableName().' dc', 'dc.dealer=d.id')
            ->leftJoin(DealerSecurity::tableName(). 'ds', 'ds.dealer=d.id')
            ->leftJoin(DealerAuctions::tableName().' da', 'da.dealer=d.id')
            ->where([
                'd.id' => $this->id
            ])->one();

    }
 /**
  * Finds the Dealers model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Dealers the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DealerCompany::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDc()
 {
     return $this->hasOne(DealerCompany::className(), ['id' => 'dc_id']);
 }
    public function searchCompanyDealer(){
        $query = DealerCompany::find()->joinWith([
            'dealer0',
        ])->where([
            'dealer_company.company' => Auction::$app->session->get('user.company'),
          //  'dealer_company.is_active' => DatabaseHelper::ACTIVE
        ]);

        return new ActiveDataProvider([
            'query' => $query,
        ]);
    }
    public function actionToggleStatus($id){

        if(DealerCompany::model()->addedByDealer($id)) {
            return $this->actionView($id);
        }

        else{

            throw new HttpException(400 , 'Error in Action');
        }
    }
    /**
     * Company Added By Dealer
     * then status => 1
     *
     * is_active need to change by company/company User
     */
    public function addedByDealer($id){

        $_model = DealerCompany::find()->where([
            'company' => $id,
            'dealer' => Auction::dealer()
        ])->one();

        if($_model === null){

            $_model = new DealerCompany();
            $_model->company = $id;
            $_model->dealer = Auction::dealer();
            $_model->is_active = DatabaseHelper::IN_ACTIVE;
            $_model->status = DatabaseHelper::ACTIVE;
            $_model->mode = DatabaseHelper::DEALER_APPROVE_APPROVAL_REQUIRED;

            Auction::infoLog('Creating A new Dealer Company Since No Record of DealerCompany of',['company' => $id ,'dealer' => Auction::dealer()]);

        }else{
            switch ($_model->status){

                case DatabaseHelper::ACTIVE :
                    $_model->status = DatabaseHelper::IN_ACTIVE;
                    break;

                case DatabaseHelper::IN_ACTIVE :
                    $_model->status = DatabaseHelper::ACTIVE;
                    break;
            }
            Auction::infoLog('Updating Dealer Company Status',['company' => $id ,'dealer' => Auction::dealer()]);
        }

        return $_model->save();
    }