Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CategoryModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #2
0
 public function actionByProductMonthCsv()
 {
     header('Content-Type: application/excel');
     header('Content-Disposition: attachment; filename="sales_monthly.csv"');
     $searchModel = new SalesDtlSearch();
     $searchModel->fr_date = date('Y-m-01');
     $searchModel->to_date = date('Y-m-d');
     $dataProvider = $searchModel->searchByProduct(Yii::$app->request->queryParams);
     $dataProvider->pagination = false;
     $dcats = \backend\models\master\Category::find();
     $rcats = [];
     foreach ($dcats->all() as $crows) {
         $rcats[$crows->id] = [$crows->code, $crows->name];
     }
     $days = $this->getDay();
     $fp = fopen('php://output', 'w');
     $dbfore = '';
     $is_first = true;
     $i = 0;
     $tot = 0;
     $tot_disc = 0;
     $tot_all = 0;
     $tot_jend = 0;
     $tot_jend_disc = 0;
     $tot_jend_all = 0;
     $hdr = ['HARI/TANGGAL', 'NO.BON', 'ARTIKEL', 'NAMA BARANG', 'KATEGORI', 'SIZE', 'QTY', 'HARGA', 'DISKON', 'JUMLAH'];
     fputcsv($fp, $hdr, chr(9));
     foreach ($dataProvider->models as $row) {
         if (!$is_first && $row->SDate != $dbfore) {
             if ($tot_jend > $tot) {
                 fputcsv($fp, [null, null, null, null, null, null, null, $tot, $tot_disc, $tot_all], chr(9));
                 fputcsv($fp, [null, null, null, null, null, null, null, $tot_jend, $tot_jend_disc, $tot_jend_all, PHP_EOL], chr(9));
             } else {
                 fputcsv($fp, [null, null, null, null, null, null, null, $tot, $tot_disc, $tot_all, PHP_EOL], chr(9));
             }
             fputcsv($fp, $hdr, chr(9));
             $tot = $row->price * $row->qty;
             $tot_disc = $row->disc;
             $tot_all = $tot - $tot_disc;
         } else {
             $tot += $row->price * $row->qty;
             $tot_disc += $row->disc;
             $tot_all += $row->price * $row->qty - $row->disc;
         }
         $tot_jend += $row->price * $row->qty;
         $tot_jend_disc += $row->disc;
         $tot_jend_all += $row->price * $row->qty - $row->disc;
         $tanggal = $row->sdate;
         $day = date('D', strtotime($tanggal));
         $r = [];
         $r[] = $row->SDate == $dbfore ? '' : $days[$day] . ', ' . $row->SDate;
         //tgl
         $r[] = $row->faktur;
         //bon
         $prod = explode(';', $row->pname);
         $r[] = isset($prod[1]) ? $prod[1] : '';
         //artikel
         $r[] = isset($prod[0]) ? $prod[0] : '';
         //product name
         $r[] = isset($row->ctgr) ? $rcats[$row->ctgr][1] : '';
         //category
         $r[] = isset($prod[2]) ? $prod[2] : '';
         //size
         $r[] = $row->qty;
         $r[] = $row->price * $row->qty;
         $r[] = $row->disc;
         $r[] = $row->price * $row->qty - $row->disc;
         fputcsv($fp, $r, chr(9));
         $dbfore = $row->SDate;
         $is_first = false;
         $i++;
     }
     fputcsv($fp, [null, null, null, null, null, null, null, $tot, $tot_disc, $tot_all], chr(9));
     if ($tot_jend > $tot) {
         fputcsv($fp, [null, null, null, null, null, null, null, $tot_jend, $tot_jend_disc, $tot_jend_all], chr(9));
     }
     fclose($fp);
     return false;
 }
 /**
  * Finds the Category model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Category the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\master\search\Product */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Products';
$this->params['breadcrumbs'][] = $this->title;
?>


<p class="pull-right">
    <?php 
echo Html::a('Create', ['create'], ['class' => 'btn btn-default']);
?>
    <?php 
echo Html::a('<i class="fa fa-download"></i>', ['csv-download', 'id' => $searchModel->id, 'params' => $_GET], ['class' => 'btn btn-default', 'title' => 'CSV Download', 'data' => ['method' => 'post']]);
?>
</p><br>
<div class="product-index">

    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'tableOptions' => ['class' => 'table table-hover'], 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'code', 'name', ['header' => 'Product Group', 'attribute' => 'group_id', 'value' => 'group.name', 'format' => 'raw', 'filter' => backend\models\master\ProductGroup::selectOptions()], ['header' => 'Product Category', 'attribute' => 'category_id', 'value' => 'category.name', 'format' => 'raw', 'filter' => \backend\models\master\Category::selectOptions()], ['attribute' => 'status', 'value' => 'nmStatus', 'filter' => $searchModel::enums('STATUS_')], 'edition:date', ['header' => 'stockable', 'class' => 'yii\\grid\\CheckboxColumn', 'checkboxOptions' => function ($model, $key, $index, $column) {
    return ['value' => $model->id, 'checked' => $model->stockable];
}], 'created_at:datetime', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Example #5
0
?>
    <div class="row">
        <div class="col-lg-4">
            <?php 
echo $form->field($model, 'code')->textInput(['maxlength' => true]);
?>
            <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
        </div>
        <div  class="col-lg-4">
            <?php 
echo $form->field($model, 'group_id')->dropDownList(backend\models\master\ProductGroup::selectOptions(), ['prompt' => '-- select --', 'style' => 'width:60%']);
?>
            <?php 
echo $form->field($model, 'category_id')->dropDownList(\backend\models\master\Category::selectOptions(), ['prompt' => '-- select --', 'style' => 'width:60%']);
?>
        </div>
        <div  class="col-lg-4">   
            <?php 
echo $form->field($model, 'Edition')->widget('yii\\jui\\DatePicker', ['dateFormat' => 'dd-MM-yyyy', 'options' => ['class' => 'form-control', 'style' => 'width:40%;']]);
?>
            <?php 
echo $form->field($model, 'stockable')->checkbox();
echo $form->field($model, 'status')->dropDownList($model::enums('STATUS_'), ['prompt' => '-- select status--', 'style' => 'width:40%']);
?>
        </div>

        <div class="nav-tabs-justified col-lg-12"  style="margin-top: 20px;">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#uom" data-toggle="tab" aria-expanded="false">Uoms</a></li>
Example #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }