private function search($doc) { $query = \app\models\Docs::find(); $query->where("(`doctype`=:typeA) OR (`doctype`=:typeB)", [':typeA' => 1, ':typeB' => 3]); $query->andFilterWhere(['<=', 'due_date', date("Y-m-d") . " 23:59:59"]); $query->andFilterWhere(['=', 'refstatus', 0]); // $sort = new CSort(); //$sort->defaultOrder = 'due_date DESC'; return new \yii\data\ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['due_date' => SORT_ASC]], 'pagination' => array('pageSize' => 4)]); }
private function getDocs($account_id) { $sum = 0; //1=Proforma $doctype = 1; $openDocs = Docs::find()->where(['account_id' => $account_id, 'doctype' => $doctype, 'refstatus' => Docs::STATUS_OPEN])->all(); foreach ($openDocs as $doc) { $sum += $doc->total; } return $sum; }
private function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $query = \app\models\Docs::find(); //$query->where("(`doctype`=:typeA)", [':typeA' => 7]); $query->andFilterWhere(['<=', 'due_date', date("Y-m-d") . " 23:59:59"]); $query->andFilterWhere(['=', 'refstatus', 0]); // $sort = new CSort(); //$sort->defaultOrder = 'due_date DESC'; return new \yii\data\ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['due_date' => SORT_ASC]], 'pagination' => array('pageSize' => 4)]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Docs::find(); $dataProvider = new ActiveDataProvider(['query' => $query, "sort" => ['defaultOrder' => ['reg_date' => SORT_DESC, 'docnum' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'doctype' => $this->doctype, 'docnum' => $this->docnum, 'account_id' => $this->account_id, 'total' => $this->total, 'status' => $this->status, 'printed' => $this->printed, 'refstatus' => $this->refstatus]); $query->andFilterWhere(['like', 'company', $this->company])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'zip', $this->zip])->andFilterWhere(['like', 'vatnum', $this->vatnum])->andFilterWhere(['like', 'refnum', $this->refnum])->andFilterWhere(['like', 'refnum_ext', $this->refnum_ext])->andFilterWhere(['like', 'currency_id', $this->currency_id])->andFilterWhere(['like', 'comments', $this->comments])->andFilterWhere(['like', 'description', $this->description]); if (!is_null($this->issue_date)) { $tmp = explode(" to ", $this->issue_date); //var_dump($tmp); if (isset($tmp[0]) && isset($tmp[1])) { $query->andFilterWhere(['between', 'issue_date', $tmp[0], $tmp[1]]); } // //$query->andFilterWhere(['>=', 'issue_from', $tmp[1]]); } return $dataProvider; }
echo $searchModel->issue_from; $dateisOn = kartik\date\DatePicker::widget(['model' => $searchModel, 'attribute' => 'issue_from', 'attribute2' => 'issue_to', 'removeButton' => false, 'type' => 5, 'separator' => '']); //. //kartik\date\DatePicker::widget([ 'model' => $searchModel, 'attribute' => 'issue_to', 'removeButton' => false, ]); //kartik\datecontrol\DateControl::widget(['model' => $searchModel, 'attribute' => 'issue_to', 'type' => 'date']); $filter = ''; if ($searchModel->doctype != null) { $filter = \yii\helpers\ArrayHelper::map(\app\models\Docstatus::find()->where(['doc_type' => $searchModel->doctype])->All(), 'num', 'name'); } else { //$searchModel->status = null; } echo app\widgets\GridView::widget(array('dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => array(array('attribute' => 'doctype', 'filter' => \app\models\Doctype::tlist(), 'value' => function ($data) { return $data->TypeName(); }, 'width' => '150px'), array('attribute' => 'status', 'filter' => $filter, 'value' => function ($data) { return $data->docStatus->name; }, 'width' => '70px'), array('attribute' => 'refstatus', 'width' => '110px', 'filter' => \yii\helpers\ArrayHelper::map(\app\models\Docs::getRefStatuses(), 'id', 'name'), 'value' => function ($data) { return app\widgets\Switcher::widget(['model' => $data, 'name' => 'refstatus', 'url' => yii\helpers\BaseUrl::base() . '/docs/refstatus/' . $data->id, 'onLabel' => Yii::t('app', 'Open'), 'offLabel' => Yii::t('app', 'Closed')]); }, 'format' => 'raw'), array('attribute' => 'docnum', 'width' => '70px'), array('attribute' => 'account_id', 'width' => '70px'), 'company', 'refnum_ext', array('attribute' => 'issue_date', 'filterType' => \kartik\grid\GridView::FILTER_DATE_RANGE, 'filterWidgetOptions' => ['convertFormat' => true, 'useWithAddon' => true, 'pluginOptions' => ['format' => 'Y-m-d', 'separator' => ' to '], 'hideInput' => true, 'presetDropdown' => false], 'width' => '150px', 'value' => function ($data) { return $data->readDateFormat($data->issue_date); }), 'total', array('options' => array('style' => 'width:95px;'), 'class' => 'yii\\grid\\ActionColumn', 'template' => '{duplicate}{print}{view}{update}{delete}', 'buttons' => array('update' => function ($url, $model, $key) { if ($model->docStatus->looked == 1) { return ''; } // 'label' => '<i class="glyphicon glyphicon-edit"></i>', return Html::a('<i class="glyphicon glyphicon-edit"></i>', $url); }, 'duplicate' => function ($url, $model, $key) { return Html::a('<i class="glyphicon glyphicon-plus-sign"></i>', $url); //'label' => '<i class="glyphicon glyphicon-plus-sign"></i>', // //'imageUrl'=>Yii::$app->request->baseUrl.'/images/email.png', //'url' => 'yii\helpers\BaseUrl::base().("docs/duplicate/". $data->id)', }, 'delete' => function ($url, $model, $key) {
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function findModel($id) { $model = Docs::findOne($id); if ($model === null) { throw new \yii\web\HttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }