/** * Lists all SalesActivity models. * @return mixed */ public function actionIndex() { $resGroupsModel = \app\models\ResGroups::find()->where('name like :name')->addParams([':name' => 'All Sales User'])->one(); $salesData = new ArrayDataProvider(['allModels' => $resGroupsModel->users, 'sort' => ['attributes' => ['name'], 'defaultOrder' => ['name' => SORT_ASC]]]); $searchModel = new SalesActivitySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'salesData' => $salesData]); }
public function actionUserlist($search = null, $id = null) { $out = ['more' => false]; if (!is_null($search)) { $query = new Query(); $query->select('id, login AS text')->from('res_users')->where(['like', 'login', $search])->limit(20); $command = $query->createCommand(); $data = $command->queryAll(); $out['results'] = array_values($data); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => ResGroups::find($id)->login]; } else { $out['results'] = ['id' => 0, 'text' => 'No matching records found']; } echo Json::encode($out); }
use yii\helpers\Html; use yii\helpers\Url; use kartik\widgets\ActiveForm; use kartik\widgets\DatePicker; use kartik\widgets\Select2; use yii\web\JsExpression; /* @var $this yii\web\View */ /* @var $model app\models\SalesActivitySearch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="sales-activity-search"> <?php $form = ActiveForm::begin(['action' => [''], 'method' => 'get']); $saleGroup = \app\models\ResGroups::find()->select('id')->with(['users', 'users.partner' => function ($query) { $query->orderBy('name ASC'); }])->where(['name' => 'All Sales User'])->asArray()->one(); $saleUsers = \yii\helpers\ArrayHelper::map($saleGroup['users'], 'id', 'partner.name'); // var_dump($saleGroup); ?> <div class="form-group"> <label class="controll-label" for="sales">Sales</label> <?php echo Select2::widget(['model' => $model, 'attribute' => 'sales', 'data' => $saleUsers, 'value' => Yii::$app->request->get('sales'), 'options' => ['placeholder' => 'Select Sales ...'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="form-group"> <label class="controll-label" for="customer">Customer</label> <?php
public function actionDashboard() { $title['between'] = ""; $connection = \Yii::$app->db; $model = new OrderInvoiceReportForm(); $saleGroup = ResGroups::findOne(['name' => 'All Sales User']); $saleUsers = ArrayHelper::map($saleGroup->users, 'id', 'name'); $aiSearch = new AccountInvoiceSearch(); $aiSearch->start_date = '2014-07-01'; #DEFAULT START DATE FROM JULLY 2014 CAUSE ERP START LIVE IN JULY 2014 $aiSearch->end_date = date('Y-m-d'); $submited = false; $sales_ids = []; #sales ids if empty then show all sales man data if ($model->load(Yii::$app->request->get())) { $model->sales = Yii::$app->request->get('sales'); $submited = true; $aiSearch->start_date = $model->date_from; $aiSearch->end_date = $model->date_to; $getSalesUsers = []; // if($model->validate()){ // Sales ids $getSalesUsers = Yii::$app->request->get('sales'); // }else{ // Yii::$app->session->setFlash('danger','SalesMan is not valid'); $salesError = true; // } // check if has sear for group // FIND BY GROUP $group_ids = []; #sale group ids if ($getSalesUsers) { // echo 'AAAAAAAAA'; foreach ($getSalesUsers as $searchFor) { if (preg_match('/group\\:/', $searchFor)) { // search for group $expl = explode(':', $searchFor); $groupQ = GroupSales::find()->where(['is_main_group' => true, 'name' => $expl[1]]); // var_dump($groupQ->createCommand()->sql); $group = $groupQ->one(); /*foreach($group->groupSalesLines as $gLine): $sales_ids[]=$gLine->name; endforeach;*/ $group_ids[] = $group->id; } else { $sales_ids[] = $searchFor; } } } $aiSearch->group_ids = $group_ids; $aiSearch->sales_ids = $sales_ids; } // var_dump($aiSearch->group_ids); $ai = $aiSearch->getSum(); #result from query->all() // \yii\helpers\VarDumper::dump($aiPie); $resGrid['dataProvider'] = new \yii\data\ArrayDataProvider(['allModels' => $ai, 'pagination' => ['pageSize' => 100]]); $aiPie = $aiSearch->getSumGroup(); /*var_dump($ai); die();*/ if (!$ai) { throw new NotFoundHttpException('Data not found.'); } $fields = array_keys($ai[0]); $uidF = array_search('user_id', $fields); # SEARCH USER ID INDEX unset($fields[$uidF]); # UNSET FIELD WITH SEARCHED INDEX KEY REMOVE USER_ID $fields = array_values($fields); # RE GENERATE ARRAY KEY $totalSummaryFields = count($fields) - 1; # INIT GRID COLUMNS FORMAT foreach ($fields as $fieldName) { $summary = false; $format = 'html'; $header = ucwords(str_replace('_', ' ', $fieldName)); if (preg_match('/summary_/', $fieldName)) { $summary = true; $format = 'currency'; $expl = explode('_', $fieldName); $monthName = \DateTime::createFromFormat('m', $expl[2]); $header = $expl[1] . '-' . $monthName->format('F'); $resGrid['columns'][] = ['attribute' => $fieldName, 'header' => $header, 'format' => $format, 'pageSummary' => $summary]; } else { $resGrid['columns'][] = ['attribute' => $fieldName, 'header' => $header, 'format' => $format, 'pageSummary' => $summary, 'value' => function ($model, $key, $index, $grid) use($fieldName, $aiSearch) { return \yii\helpers\Html::a($model[$fieldName], ['account-invoice/index', 'uid' => $model['user_id'], 'type' => 'out', 'start_date' => $aiSearch->start_date, 'end_date' => $aiSearch->end_date]); }]; } } $resGrid['columns'][] = ['class' => '\\kartik\\grid\\FormulaColumn', 'format' => ['currency'], 'header' => 'Subtotal', 'pageSummary' => true, 'value' => function ($model, $key, $index, $widget) use($totalSummaryFields) { $p = compact('model', 'key', 'index'); $res = 0; for ($c = 1; $c <= $totalSummaryFields; $c++) { $res += $widget->col($c, $p); } return $res; }]; // ACTION COLUMN /*$resGrid['columns'][]=[ 'class'=>'\yii\grid\ActionColumn', 'template'=>'{view}', 'buttons'=>[ 'view'=>function($url,$model,$key){ return 'Viewsss'; } ] ];*/ $pie = []; $y = []; foreach ($aiPie as $idx => $inv) { foreach ($fields as $fieldName) { if ($fieldName != 'sales_name') { if (isset($y[$idx])) { $y[$idx] += $inv[$fieldName]; } else { if ($fieldName != 'group_name') { $y[$idx] = $inv[$fieldName]; } } } } $pie['series'][] = ['name' => $inv['sales_name'], 'y' => $y[$idx]]; } $title['between'] = ' Between ' . \DateTime::createFromFormat('Y-m-d', $aiSearch->start_date)->format('d-F-Y') . ' and ' . \DateTime::createFromFormat('Y-m-d', $aiSearch->end_date)->format('d-F-Y'); return $this->render('order_invoice_dashboard', ['title' => $title, 'model' => $model, 'saleUsers' => $saleUsers, 'resGrid' => $resGrid, 'pie' => $pie]); }
/** * @return \yii\db\ActiveQuery */ public function getG() { return $this->hasOne(ResGroups::className(), ['id' => 'gid']); }
public function actionGetAllUserList($search = null, $id = null) { $out = ['more' => false]; $q = new \yii\db\Query(); if (!is_null($search)) { $q->select('usr.id, prf.name as text')->from(ResGroups::tableName() . ' rg')->leftJoin(ResGroupsUsersRel::tableName() . ' rgu', 'rgu.gid = rg.id')->leftJoin(ResUsers::tableName() . ' usr', 'usr.id=rgu.uid')->leftJoin(ResPartner::tableName() . ' prf', 'prf.id=usr.partner_id')->where('rg.name like :rgName')->addParams([':rgName' => 'All Sales User'])->andWhere('LOWER(prf.name) LIKE :search', [':search' => '%' . strtolower($search) . '%']); $users = $q->createCommand()->queryAll(); // var_dump($q->createCommand()->sql); $out['results'] = array_values($users); } elseif ($id > 0) { $out['results'] = ['id' => $id, 'text' => ResUsers::find()->where(['id' => $id])->with('partner')->one()->partner->name]; } else { $out['results'] = ['id' => 0, 'text' => 'No matching records found']; } echo \yii\helpers\Json::encode($out); }