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

@@ -0,0 +1,28 @@
<?php
namespace frontend\components;
use yii\base\Widget;
class TransferTotalWidget extends Widget{
public $options = [
'totalHeading' => 'Összessen'
];
public $viewFile = '//common/_transfer_total';
public function init(){
parent::init();
if ( !isset($this->options['totalHeading'] ) ){
$this->options['totalHeading'] = 'Összesen';
}
}
public function run(){
echo $this->render($this->viewFile,[ 'options' => $this->options ]);
}
}

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.

View File

@@ -0,0 +1,57 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Product;
use common\models\Transfer;
use yii\base\Object;
use common\models\Account;
use common\models\Discount;
use common\models\Currency;
use common\models\UserSoldItem;
use common\models\Sale;
use common\models\ShoppingCart;
/**
* ContactForm is the model behind the contact form.
*
* @property integer id_account
* @property common\models\Account $account
*
*
*/
class CreateAccountSelectForm extends Model
{
public $id_account;
public $account;
public $accounts;
public function rules(){
return [
[['id_account'], 'integer' ],
[['id_account'], 'validateAccount' ],
];
}
public function validateAccount($attribute,$params){
$this->account = Account::readOne($this->id_account);
if ( !isset($this->account)){
$this->addError($attribute, Yii::t('frontend/collection', 'Invalid transfer!'));
}
}
public function attributeLabels(){
return [
'id_account' => Yii::t('frontend/collection', 'Account'),
];
}
}

View File

@@ -199,7 +199,6 @@ class TransferSearch extends Transfer
$totals['accounts'] = [];
foreach ($this->accounts as $account){
// echo 'account="'. $this->id_account .'"<br>';
if ( isset($this->id_account) && is_numeric($this->id_account) && $this->id_account != $account->id_account ){
continue ;
}
@@ -227,7 +226,6 @@ class TransferSearch extends Transfer
$command = $query->createCommand();
$result = $command->queryAll();
// $paidAtTotals = $this->mkTotalsResult($result, $accountMap);
$paidAtTotals = $this->mkTotalsResultWithAllAvailableAccount($result, $accountMap);
return $paidAtTotals;

View File

@@ -0,0 +1,50 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */
/* @var $model common\models\Collection */
$this->title = Yii::t('frontend/collection', 'Create Collection - Select Account');
$this->params['breadcrumbs'][] = ['label' => Yii::t('frontend/collection', 'Collections'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$accountOptions = HtmlHelper::mkAccountOptions($model->accounts);
?>
<div class="collection-create select-account">
<h1><?= Html::encode($this->title) ?></h1>
<div class="collection-form">
<?php $form = ActiveForm::begin(
[
'method' => 'post',
'action' => ['collection/select-account'],
]
); ?>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton( Yii::t('frontend/collection', 'Next') ,['class' =>'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>

View File

@@ -2,26 +2,23 @@
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */
/* @var $model common\models\Collection */
/* @var $form yii\widgets\ActiveForm */
?>
<?php
?>
<div class="collection-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'id_account')->textInput() ?>
<?= $form->field($model, 'money')->textInput() ?>
<?= $form->field($model, 'start')->textInput() ?>
<?= $form->field($model, 'end')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('frontend/collection', 'Create') : Yii::t('frontend/collection', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

View File

@@ -1,6 +1,7 @@
<?php
use yii\helpers\Html;
use frontend\components\TransferTotalWidget;
/* @var $this yii\web\View */
@@ -15,13 +16,41 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1>
<dl class='dl-horizontal'>
<dt>Utolsó zárás</dt>
<dd>asdf</dd>
<dt></dt>
<dd></dd>
<dt></dt>
<dd></dd>
</dl>
<dt><?= Yii::t('frontend/collection', "Last collection")?></dt>
<dd><?php echo isset($model->lastCollection) ? Yii::$app->formatter->asDatetime($model->lastCollection->end) : Yii::t('frontend/collection', "No collection found") ?></dd>
<dt><?= Yii::t('frontend/collection', "Start of interval")?></dt>
<dd><?php echo Yii::$app->formatter->asDatetime($model->start) ?></dd>
<dt><?= Yii::t('frontend/collection', "End of interval")?></dt>
<dd><?php echo Yii::$app->formatter->asDatetime($model->end) ?></dd>
</dl>
<?php
echo TransferTotalWidget::widget([
'options' => [
'statistic' => $model->totals['paid_at'],
'panelHeading' => 'Fizetve' ,
]
]);
echo TransferTotalWidget::widget([
'options' => [
'statistic' => $model->totals['created_at'],
'panelHeading' => 'Kiadva',
]
]);
echo TransferTotalWidget::widget([
'options' => [
'statistic' => $model->totals['created_at_paid'],
'panelHeading' => 'Kiadva és fizetve',
]
]);
?>
<?= $this->render('_form', [
'model' => $model,

View File

@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('frontend/collection', 'Create Collection'), ['create'], ['class' => 'btn btn-success']) ?>
<?= Html::a(Yii::t('frontend/collection', 'Create Collection'), ['select-account'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([

View File

@@ -0,0 +1,21 @@
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-info">
<div class="panel-heading"><?php echo $options['panelHeading']?></div>
<div class="panel-body">
<dl class="dl-horizontal dl-totals">
<?php
foreach ($options['statistic']['accounts'] as $acc ){
?>
<dt><?php echo $acc['label'] ?></dt>
<dd class="text-right"><?php echo $acc['money'] ?></dd>
<?php
}
?>
<dt><?php echo $options['totalHeading']?></dt>
<dd class="text-right"><?php echo $options['statistic']['total'] ?></dd>
</dl>
</div>
</div>
</div>
</div>