add frontend collection
This commit is contained in:
@@ -14,6 +14,7 @@ use common\models\CollectionCreate;
|
||||
use common\models\Transfer;
|
||||
use frontend\models\CreateAccountSelectForm;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\models\UserSoldItem;
|
||||
|
||||
/**
|
||||
* CollectionController implements the CRUD actions for Collection model.
|
||||
@@ -41,8 +42,10 @@ class CollectionController extends Controller
|
||||
$searchModel = new CollectionSearch();
|
||||
|
||||
$searchModel->accounts = Account::read();
|
||||
$searchModel->accountMap = Account::toAccaountMap($searchModel->accounts);
|
||||
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
$searchModel->searchTotal();
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
@@ -57,8 +60,16 @@ class CollectionController extends Controller
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
$accounts = Account::read();
|
||||
$accountMap = Account::toAccaountMap($accounts);
|
||||
|
||||
$totals = Transfer::mkTotals($model->start, $model->end, $model->id_user, null, $model->id_account, $accounts, $accountMap);
|
||||
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
'model' => $model,
|
||||
'totals' => $totals,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -83,12 +94,14 @@ class CollectionController extends Controller
|
||||
$model->timestampStart = isset($model->lastCollection) ? $model->lastCollection->end :null;
|
||||
$model->timestampEnd = date("Y-m-d H:i:s");
|
||||
|
||||
$model->start = isset($model->timestampStart) ? Yii::$app->formatter->asDatetime( $model->timestampStart ) : '';
|
||||
$model->end = isset($model->timestampEnd) ? Yii::$app->formatter->asDatetime( $model->timestampEnd ): '';
|
||||
$model->start = isset($model->timestampStart) ? Yii::$app->formatter->asDatetime( $model->timestampStart ,'yyyy-MM-dd HH:mm:ss') : '';
|
||||
$model->end = isset($model->timestampEnd) ? Yii::$app->formatter->asDatetime( $model->timestampEnd ,'yyyy-MM-dd HH:mm:ss'): '';
|
||||
|
||||
$model->type = Collection::TYPE_RECEPTION;
|
||||
|
||||
|
||||
$model->userCartTotal = UserSoldItem::readTotalForAccount($model->id_user, $model->id_account);
|
||||
|
||||
if ( $model->load(Yii::$app->request->post()) && $model->save() ) {
|
||||
return $this->redirect(['view', 'id' => $model->id_collection]);
|
||||
} else {
|
||||
@@ -119,37 +132,7 @@ class CollectionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Collection model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_collection]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Collection model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Collection model based on its primary key value.
|
||||
|
||||
Reference in New Issue
Block a user