Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = EstimateEntry::find();
     $query->innerJoinWith(['product']);
     $query->innerJoinWith(['estimate.receipt']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['product_id' => $this->product_id, 'estimate.client_id' => $this->client_id]);
     $query->andFilterWhere(['like', 'product.bukmark_code', $this->bukmark_code]);
     /**
      * Convert the to dates to mysql format.
      * Leave them as null so they are not used
      * by ActiveQuery::andFilterWhere().
      */
     $fromDate = null;
     $toDate = null;
     if ($this->from_date) {
         $this->from_date = DateConverter::convert($this->from_date);
     }
     if ($this->to_date) {
         $this->to_date = DateConverter::convert($this->to_date);
     }
     $query->andFilterWhere(['>=', 'receipt.created_date', $this->from_date]);
     $query->andFilterWhere(['<=', 'receipt.created_date', $this->to_date]);
     // Only checked entries are used
     $query->andFilterWhere(['checked' => true]);
     return $dataProvider;
 }
 /**
  * Override gallery api actions to remove the deleted image ids from the
  * estimate entries.
  * @param string $action
  * @return mixed
  */
 public function actionGalleryApi($action)
 {
     if ($action == 'delete') {
         $ids = Yii::$app->request->post('id');
         $entries = EstimateEntry::find()->where(['product_image_id' => $ids])->all();
         foreach ($entries as $entry) {
             $entry->product_image_id = null;
             $entry->save();
         }
     }
     $apiActionCofing = ['class' => GalleryManagerAction::className(), 'types' => [Product::GALLERY_IMAGE_TYPE => Product::className()]];
     $apiAction = Yii::createObject($apiActionCofing, ['gallery-api', $this]);
     return $apiAction->run($action);
 }
 /**
  * Finds the EstimateEntry model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return EstimateEntry the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findEntryModel($id)
 {
     if (($model = EstimateEntry::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEntries()
 {
     return $this->hasMany(EstimateEntry::className(), ['estimate_id' => 'id']);
 }