Skip to content

Commit

Permalink
Added bills creating
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Apr 1, 2016
1 parent e2bc574 commit 3141710
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 19 deletions.
31 changes: 28 additions & 3 deletions src/controllers/BillController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use hipanel\actions\SmartUpdateAction;
use hipanel\actions\ValidateFormAction;
use hipanel\actions\ViewAction;
use hipanel\helpers\ArrayHelper;
use hipanel\models\Ref;
use Yii;

Expand All @@ -41,15 +42,39 @@ public function actions()
],
'create' => [
'class' => SmartCreateAction::class,
'success' => Yii::t('app', 'Bill created'),
'data' => function ($action) {
$types = Ref::getList('type,bill', ['with_hierarchy' => 1, 'orderby' => 'name_asc']);
$billTypes = [];
$billGroupLabels = [];

foreach ($types as $key => $title) {
list($type, $name) = explode(',', $key);

if (!isset($billTypes[$type])) {
$billTypes[$type] = [];
$billGroupLabels[$type] = ['label' => $title];
}

if (isset($name)) {
foreach ($types as $k => $t) {
if (strpos($k, $type . ',') === 0) {
$billTypes[$type][$k] = $t;
}
}
}
}

return ['billTypes' => $billTypes, 'billGroupLabels' => $billGroupLabels];
},
'success' => Yii::t('hipanel/finance', 'Bill was created successfully'),
],
'update' => [
'class' => SmartUpdateAction::class,
'success' => Yii::t('app', 'Bill updated'),
'success' => Yii::t('hipanel/finance', 'Bill was updated successfully'),
],
'delete' => [
'class' => SmartPerformAction::class,
'success' => Yii::t('app', 'Bill deleted'),
'success' => Yii::t('hipanel/finance', 'Bill was deleted successfully'),
],
];
}
Expand Down
5 changes: 5 additions & 0 deletions src/messages/ru/finance.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
'Invoice' => 'Инвойс',
'Invoices' => 'Инвойсы',
'Recharge account' => 'Пополнить счёт',
'Sum' => 'Сума',
'Date' => 'Дата',
'Label' => 'Описание',
'Create payment' => 'Создать платеж',
'Payments' => 'Платежи',
];
17 changes: 14 additions & 3 deletions src/models/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Bill extends \hipanel\base\Model
public $time_from;
public $time_till;

public static $i18nDictionary = 'hipanel/finance';

/**
* {@inheritdoc}
*/
Expand All @@ -29,8 +31,7 @@ public function rules()
[['client_id', 'seller_id', 'id'], 'integer'],
[['object_id', 'tariff_id'], 'integer'],
[['client', 'seller', 'bill'], 'safe'],
[['domain', 'server'], 'safe'],
[['time'], 'date'],
[['domain', 'server', 'time'], 'safe'],
[['sum', 'balance', 'quantity'], 'number'],
[['currency', 'label', 'descr'], 'safe'],
[['object', 'domains', 'tariff'], 'safe'],
Expand All @@ -39,6 +40,12 @@ public function rules()
[['type_label', 'gtype_label'], 'safe'],

[['id'], 'integer', 'on' => 'delete'],

[['client_id'], 'integer', 'on' => 'create'],
[['type', 'label'], 'safe', 'on' => 'create'],
[['time'], 'date', 'format' => 'php:d.m.Y H:i:s', 'on' => 'create'],
[['sum'], 'number', 'on' => 'create'],
[['client_id', 'type', 'label', 'sum'], 'required', 'on' => 'create'],
];
}

Expand All @@ -48,9 +55,13 @@ public function rules()
public function attributeLabels()
{
return $this->mergeAttributeLabels([
'client' => Yii::t('hipanel', 'Client'),
'time' => Yii::t('hipanel', 'Time'),
'currency' => Yii::t('hipanel', 'Currency'),
'balance' => Yii::t('hipanel', 'Balance'),
'gtype' => Yii::t('app', 'Type'),
'gtype_label' => Yii::t('app', 'Type'),
'sum' => Yii::t('app', 'Sum'),
'sum' => Yii::t('hipanel/finance', 'Sum'),
]);
}
}
64 changes: 64 additions & 0 deletions src/views/bill/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

use hipanel\helpers\Url;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\client\widgets\combo\SellerCombo;
use kartik\date\DatePicker;
use yii\helpers\Html;
use yii\widgets\ActiveForm;

/** @var yii\web\View $this */
/** @var hipanel\modules\finance\models\Bill $model */
/** @var array $billTypes */
/** @var array $billGroupLabels */

$form = ActiveForm::begin([
'id' => 'dynamic-form',
'enableClientValidation' => true,
'validationUrl' => Url::toRoute([
'validate-form',
'scenario' => $model->isNewRecord ? $model->scenario : 'update'
]),
]) ?>

<div class="container-items"><!-- widgetContainer -->
<?php foreach ($models as $i => $model) { ?>
<div class="row">
<div class="col-md-4">
<div class="box box-danger">
<div class="box-body">
<div class="form-instance" xmlns="http://www.w3.org/1999/html"
xmlns="http://www.w3.org/1999/html">
<?php
print $form->field($model, "[$i]client_id")->widget(ClientCombo::className(),
['formElementSelector' => '.form-instance']);
print $form->field($model, "[$i]type")->dropDownList($billTypes, ['groups' => $billGroupLabels]);
print $form->field($model, "[$i]sum");
?>
<div class="form-group">
<?= Html::label(Yii::t('hipanel/finance', 'Date')) ?>
<?= \kartik\widgets\DateTimePicker::widget([
'model' => $model,
'attribute' => "[$i]time",
'type' => DatePicker::TYPE_COMPONENT_APPEND,
'pluginOptions' => [
'autoclose' => true,
'format' => 'dd.mm.yyyy HH:ii:ss'
],
]) ?>
</div>
<?php
print $form->field($model, "[$i]label");
?>
</div>
</div>
</div>
<!-- ticket-_form -->
</div>
</div>
<?php } ?>
</div>
<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-default']) ?>
&nbsp;
<?= Html::button(Yii::t('hipanel', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?>
<?php ActiveForm::end(); ?>
17 changes: 17 additions & 0 deletions src/views/bill/create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/* @var $this yii\web\View */
/* @var $model hipanel\modules\ticket\models\Thread */
/* @var $type string */

$this->title = Yii::t('hipanel/finance', 'Create payment');
$this->breadcrumbs->setItems([['label' => Yii::t('hipanel/finance', 'Payments'), 'url' => ['index']]]);
$this->breadcrumbs->setItems([$this->title]);
?>

<div class="bill-create">
<?= $this->render('_form', [
'models' => $models,
'billTypes' => $billTypes,
'billGroupLabels' => $billGroupLabels
]) ?>
</div>
28 changes: 15 additions & 13 deletions src/views/bill/view.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<?php

use hipanel\helpers\Url;
use hipanel\modules\finance\grid\BillGridView;
use hipanel\widgets\Pjax;
use yii\helpers\Html;

$this->title = Html::encode($model->domain);
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Domains'), 'url' => ['index']];
$this->title = Html::encode($model->domain);
$this->params['breadcrumbs'][] = ['label' => Yii::t('hipanel/finance', 'Payments'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

?>
Yii::$app->response->redirect(Url::to('@bill/index'))->send();

<?php Pjax::begin(Yii::$app->params['pjax']) ?>
Pjax::begin(Yii::$app->params['pjax']) ?>
<div class="row">

<div class="col-md-4">
<?= BillGridView::detailView([
'model' => $model,
'columns' => [
'seller_id', 'client_id',
['attribute' => 'bill'],
],
]) ?>
</div>
<div class="col-md-4">
<?= BillGridView::detailView([
'model' => $model,
'columns' => [
'seller_id',
'client_id',

],
]) ?>
</div>

</div>
<?php Pjax::end() ?>

0 comments on commit 3141710

Please sign in to comment.