/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/TopupController.php (4619B)
render('index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams)
]
);
}
/**
* @return string
*
* @Title("Export")
*/
public function actionExport()
{
$searchModel = new CreditHistorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$model = $dataProvider->query->all();
$thead = [];
$tbody = [];
$theading = [
'Name',
'Vendor Name',
'Transaction ID',
'Amount',
'Balance',
'Date'
];
foreach ($theading as $index => $value) {
$thead[] = Html::tag('th', $value);
}
$thead = Html::tag('thead', Html::tag('tr', implode('', $thead)));
foreach ($model as $key => $value) {
$row = [];
$date = date("F jS, Y", strtotime($value['created_at']));
$row[] = Html::tag('td', $value['name']);
$row[] = Html::tag('td', $value['vendor_name']);
$row[] = Html::tag('td', $value['credit_history_number']);
$row[] = Html::tag('td', $value['amount']);
$row[] = Html::tag('td', $value['total_amount']);
$row[] = Html::tag('td', $date);
$tbody[] = Html::tag('tr', implode('', $row));
}
$tbody = Html::tag('tbody', implode('', $tbody));
$table = Html::tag('table', $thead . $tbody);
$fileName = 'Transaction Log'.' '.date('Y/m/d');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Length: ' . strlen($table));
header('Content-type: application/vnd.ms-excel');
header('Content-type: application/octet-stream, charset=UTF-8; encoding=UTF-8');
header('Content-Disposition: attachment; filename=' .$fileName.'.xlsx');
echo $table;
Yii::$app->end();
}
/**
*
* @return string
*
* @Title("Create")
*/
public function actionCreate()
{
$model = new Topup();
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $model->validate()) {
$model->save();
Com::successFlash('Created Successfully');
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $model->validate()) {
$model->save();
Com::successFlash('Updated Successfully');
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* @return string
* @param type $id
*
* @Title("Delete")
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model === null) {
Com::failureFlash('Unable to find the Topup Record');
return $this->redirect(['index']);
}
Topup::deleteAll(['topup_key' => $model->topup_key]);
$model->save();
Com::successFlash('Deleted Successfully');
return $this->redirect(['index']);
}
/**
*
* @param type $id
* @return $model
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = Topup::findOne(['topup_key' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}