Commit 03c7b7bca03c91ca1ebad17d2d5264269f7d5247
1 parent
bfd98631
Credit v2
Showing
3 changed files
with
28 additions
and
7 deletions
Show diff stats
controllers/OrderController.php
@@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
4 | 4 | ||
5 | use artweb\artbox\components\SmsSender; | 5 | use artweb\artbox\components\SmsSender; |
6 | use artweb\artbox\ecommerce\models\OrderSearch; | 6 | use artweb\artbox\ecommerce\models\OrderSearch; |
7 | + use common\components\CreditHelper; | ||
7 | use common\models\User; | 8 | use common\models\User; |
8 | use phpDocumentor\Reflection\Types\Null_; | 9 | use phpDocumentor\Reflection\Types\Null_; |
9 | use Yii; | 10 | use Yii; |
@@ -11,6 +12,7 @@ | @@ -11,6 +12,7 @@ | ||
11 | use yii\helpers\ArrayHelper; | 12 | use yii\helpers\ArrayHelper; |
12 | use yii\helpers\Json; | 13 | use yii\helpers\Json; |
13 | use yii\helpers\VarDumper; | 14 | use yii\helpers\VarDumper; |
15 | + use yii\validators\NumberValidator; | ||
14 | use yii\web\Controller; | 16 | use yii\web\Controller; |
15 | use yii\filters\VerbFilter; | 17 | use yii\filters\VerbFilter; |
16 | use yii\data\ActiveDataProvider; | 18 | use yii\data\ActiveDataProvider; |
@@ -281,7 +283,7 @@ | @@ -281,7 +283,7 @@ | ||
281 | return $this->renderPartial( | 283 | return $this->renderPartial( |
282 | 'print', | 284 | 'print', |
283 | [ | 285 | [ |
284 | - 'order' => $order, | 286 | + 'order' => $order, |
285 | 'dataProvider' => $dataProvider, | 287 | 'dataProvider' => $dataProvider, |
286 | ] | 288 | ] |
287 | ); | 289 | ); |
@@ -323,6 +325,18 @@ | @@ -323,6 +325,18 @@ | ||
323 | 325 | ||
324 | $model = $this->findModel($id); | 326 | $model = $this->findModel($id); |
325 | 327 | ||
328 | + if ($model->payment == 10) { | ||
329 | + $model->validators->append( | ||
330 | + new NumberValidator( | ||
331 | + [ | ||
332 | + 'attributes' => 'credit_sum', | ||
333 | + 'max' => $model->total - CreditHelper::MIN_CREDIT_SUM, | ||
334 | + 'min' => $model->total - CreditHelper::MAX_CREDIT_SUM, | ||
335 | + ] | ||
336 | + ) | ||
337 | + ); | ||
338 | + } | ||
339 | + | ||
326 | /** | 340 | /** |
327 | * @var User $user | 341 | * @var User $user |
328 | */ | 342 | */ |
models/Order.php
@@ -201,8 +201,7 @@ | @@ -201,8 +201,7 @@ | ||
201 | 'credit_sum', | 201 | 'credit_sum', |
202 | ], | 202 | ], |
203 | 'number', | 203 | 'number', |
204 | - 'min' => 300, | ||
205 | - 'max' => 25000, | 204 | + 'min' => 0, |
206 | ], | 205 | ], |
207 | [ | 206 | [ |
208 | [ | 207 | [ |
@@ -292,7 +291,7 @@ | @@ -292,7 +291,7 @@ | ||
292 | 'city' => Yii::t('app', 'Город'), | 291 | 'city' => Yii::t('app', 'Город'), |
293 | 'numbercard' => Yii::t('app', '№ карточки'), | 292 | 'numbercard' => Yii::t('app', '№ карточки'), |
294 | 'credit_month' => Yii::t('app', 'Количество месяцев'), | 293 | 'credit_month' => Yii::t('app', 'Количество месяцев'), |
295 | - 'credit_sum' => Yii::t('app', 'Сумма кредита'), | 294 | + 'credit_sum' => Yii::t('app', 'Первоначальный взнос'), |
296 | ]; | 295 | ]; |
297 | } | 296 | } |
298 | 297 |
views/order/_form.php
@@ -338,17 +338,25 @@ JS; | @@ -338,17 +338,25 @@ JS; | ||
338 | if ($model->payment == 10) { | 338 | if ($model->payment == 10) { |
339 | ?> | 339 | ?> |
340 | <div> | 340 | <div> |
341 | - <div class="col-xs-6"> | 341 | + <div class="col-xs-4"> |
342 | <?php | 342 | <?php |
343 | echo $form->field($model, 'credit_sum') | 343 | echo $form->field($model, 'credit_sum') |
344 | ->textInput( | 344 | ->textInput( |
345 | [ | 345 | [ |
346 | 'class' => 'form-control credit_input', | 346 | 'class' => 'form-control credit_input', |
347 | + 'data-sum' => $model->total, | ||
347 | ] | 348 | ] |
348 | ); | 349 | ); |
349 | ?> | 350 | ?> |
350 | </div> | 351 | </div> |
351 | - <div class="col-xs-6"> | 352 | + <div class="col-xs-4"> |
353 | + <?php | ||
354 | + echo Html::tag('span', $model->total - $model->credit_sum, [ | ||
355 | + 'class' => 'credit_value_full', | ||
356 | + ]); | ||
357 | + ?> | ||
358 | + </div> | ||
359 | + <div class="col-xs-4"> | ||
352 | <?php | 360 | <?php |
353 | echo $form->field($model, 'credit_month') | 361 | echo $form->field($model, 'credit_month') |
354 | ->textInput( | 362 | ->textInput( |
@@ -362,7 +370,7 @@ JS; | @@ -362,7 +370,7 @@ JS; | ||
362 | <p> | 370 | <p> |
363 | <span class="credit_value"> | 371 | <span class="credit_value"> |
364 | <?php | 372 | <?php |
365 | - echo CreditHelper::getCredit($model->total); | 373 | + echo CreditHelper::getCredit($model->total - $model->credit_sum, $model->credit_month); |
366 | ?> | 374 | ?> |
367 | </span> | 375 | </span> |
368 | <span>грн/мес</span> | 376 | <span>грн/мес</span> |