add reception collection basics

This commit is contained in:
2015-11-03 17:27:14 +01:00
parent 33bf52df60
commit 931b83040b
12 changed files with 385 additions and 26 deletions

View File

@@ -11,6 +11,9 @@ use yii\filters\VerbFilter;
use common\models\Account;
use common\models\User;
use common\models\CollectionCreate;
use common\models\Transfer;
use frontend\models\CreateAccountSelectForm;
use yii\helpers\ArrayHelper;
/**
* CollectionController implements the CRUD actions for Collection model.
@@ -64,15 +67,27 @@ class CollectionController extends Controller
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
public function actionCreate($id_account)
{
$model = new CollectionCreate();
$user = User::findOne(Yii::$app->user->id);
// $accounts = Account::find()->orderBy("name asc")->all();
$model->accounts = Account::read();
$model->lastCollection = Collection::readLast($user);
$model->id_user = $user->id;
$model->id_account = Account::readDefault();
$model->account = Account::readOne($model->id_account);
$accountMap = ArrayHelper::map( $model->accounts ,'id_account','name' );
$model->start = isset($model->lastCollection) ? $model->lastCollection->end :null;
$model->end = date("Y-m-d H:i:s");
$model->totals = Transfer::mkTotals($model->start, $model->end, $model->user->id, null, $model->account->id_account, $model->accounts, $accountMap);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_collection]);
} else {
@@ -81,6 +96,26 @@ class CollectionController extends Controller
]);
}
}
/**
* Select account for which we will create collection
* If selection is successful, the browser will be redirected to the 'create' page.
* @return mixed
*/
public function actionSelectAccount()
{
$model = new CreateAccountSelectForm();
$model->accounts = Account::read();
$model->id_account = Account::readDefault();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
return $this->redirect(['create', 'id_account' => $model->id_account]);
}
return $this->render('_create_select_account.php', [
'model' => $model,
]);
}
/**
* Updates an existing Collection model.