<commit_before><?php

/**
 * @var \yii\web\View $this
 * @var \hipanel\modules\finance\models\DomainZonePrice[][] $zonePrices
 * @var \hipanel\modules\finance\models\DomainServicePrice[] $servicePrices
 * @var \hipanel\modules\finance\models\DomainZonePrice[][] $parentZonePrices
 * @var \hipanel\modules\finance\models\DomainServicePrice[] $parentServicePrices
 * @var \hipanel\modules\finance\models\Plan $plan
 */

use hipanel\modules\finance\models\DomainZonePrice;
use hipanel\modules\finance\models\DomainServicePrice;
use hipanel\widgets\Box;
use hipanel\modules\finance\widgets\PriceInput;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use hipanel\helpers\Url;

$this->registerJs("
$('#tariff-create-form').on('afterValidate', function (event, messages) {
    if(typeof $('.has-error').first().offset() !== 'undefined') {
        $('html, body').animate({
            scrollTop: $('.has-error').first().offset().top
        }, 1000);
    }
});
");

?>
<?php if (!empty($zonePrices)) : ?>
    <div class="tariff-create">
        <?php $form = ActiveForm::begin(array_filter([
            'id' => 'tariff-create-form',
            'action' => $action ?? null,
            'validateOnChange' => true,
        ])) ?>

        <?php Box::begin() ?>
        <div class="row">
            <div class="col-md-12">
                <table class="table table-condensed">
                    <thead>
                    <tr>
                        <th>
                            <h4 class="box-title" style="display: inline-block;">&nbsp;
                                <?= Yii::t('hipanel:finance', 'Prices') ?>
                            </h4>
                        </th>
                    </tr>
                    <tr>
                        <?= Html::tag('th', ''); ?>
                        <?php foreach (DomainZonePrice::getTypes() as $name) : ?>
                            <?= Html::tag('th', $name); ?>
                        <?php endforeach; ?>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i = 0; ?>
                    <?php foreach ($zonePrices as $zone => $group) : ?>
                        <tr>
                            <td><?= current($group)->object->name ?></td>
                            <?php foreach (DomainZonePrice::getTypes() as $type => $name) : ?>
                                <?php $originalPrice = $parentZonePrices[$zone][$type] ?? new DomainZonePrice; ?>
                                <?php $price = $group[$type] ?? $originalPrice; ?>
                                <?php $price->plan_id = $plan_id ?? $price->plan_id; ?>
                                <?= Html::activeHiddenInput($price, "[$i]id") ?>
                                <?= Html::activeHiddenInput($price, "[$i]plan_id") ?>
                                <?= Html::activeHiddenInput($price, "[$i]object_id") ?>
                                <?= Html::activeHiddenInput($price, "[$i]currency") ?>
                                <?= Html::activeHiddenInput($price, "[$i]type") ?>
                                <?= Html::activeHiddenInput($price, "[$i]unit") ?>
                                <td>
                                    <?= PriceInput::widget([
                                        'basePrice' => $price->price,
                                        'originalPrice' => $originalPrice ? $originalPrice->price : $price->price,
                                        'activeField' => $form->field($price, "[$i]price")]) ?>
                                </td>
                                <?php ++$i; ?>
                            <?php endforeach; ?>
                        </tr><commit_msg>Do not show domain zone price if it does not exist<commit_after><?php

/**
 * @var \yii\web\View $this
 * @var \hipanel\modules\finance\models\DomainZonePrice[][] $zonePrices
 * @var \hipanel\modules\finance\models\DomainServicePrice[] $servicePrices
 * @var \hipanel\modules\finance\models\DomainZonePrice[][] $parentZonePrices
 * @var \hipanel\modules\finance\models\DomainServicePrice[] $parentServicePrices
 * @var \hipanel\modules\finance\models\Plan $plan
 */

use hipanel\modules\finance\models\DomainZonePrice;
use hipanel\modules\finance\models\DomainServicePrice;
use hipanel\widgets\Box;
use hipanel\modules\finance\widgets\PriceInput;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use hipanel\helpers\Url;

$this->registerJs("
$('#tariff-create-form').on('afterValidate', function (event, messages) {
    if(typeof $('.has-error').first().offset() !== 'undefined') {
        $('html, body').animate({
            scrollTop: $('.has-error').first().offset().top
        }, 1000);
    }
});
");

?>
<?php if (!empty($zonePrices)) : ?>
    <div class="tariff-create">
        <?php $form = ActiveForm::begin(array_filter([
            'id' => 'tariff-create-form',
            'action' => $action ?? null,
            'validateOnChange' => true,
        ])) ?>

        <?php Box::begin() ?>
        <div class="row">
            <div class="col-md-12">
                <table class="table table-condensed">
                    <thead>
                    <tr>
                        <th>
                            <h4 class="box-title" style="display: inline-block;">&nbsp;
                                <?= Yii::t('hipanel:finance', 'Prices') ?>
                            </h4>
                        </th>
                    </tr>
                    <tr>
                        <?= Html::tag('th', ''); ?>
                        <?php foreach (DomainZonePrice::getTypes() as $name) : ?>
                            <?= Html::tag('th', $name); ?>
                        <?php endforeach; ?>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i = 0; ?>
                    <?php foreach ($zonePrices as $zone => $group) : ?>
                        <tr>
                            <td><?= current($group)->object->name ?></td>
                            <?php foreach (DomainZonePrice::getTypes() as $type => $name) : ?>
                                <?php $originalPrice = $parentZonePrices[$zone][$type] ?? null; ?>
                                <?php $price = $group[$type] ?? $originalPrice ?? null; ?>

                                <?php if ($price === null): ?>
	                                <td></td>
                                    <?php continue; ?>
                                <?php endif; ?>

                                <?php $price->plan_id = $plan_id ?? $price->plan_id; ?>
                                <?= Html::activeHiddenInput($price, "[$i]id") ?>
                                <?= Html::activeHiddenInput($price, "[$i]plan_id") ?>
                                <?= Html::activeHiddenInput($price, "[$i]object_id") ?>
                                <?= Html::activeHiddenInput($price, "[$i]currency") ?>
                                <?= Html::activeHiddenInput($price, "[$i]type") ?>
                                <?= Html::activeHiddenInput($price, "[$i]unit") ?>
                                <td>
                                    <?= PriceInput::widget([
                                        'basePrice' => $price->price,
                                        'originalPrice' => $originalPrice ? $originalPrice->price : $price->price,
                                        'activeField' => $form->field($price, "[$i]price")]) ?>
                                </td>
                                <?php ++$i; ?>
                            <?php endforeach; ?>
                        </tr>
{'fraction_non_alphanumeric': 0.1650345998172085, 'fraction_numerical': 0.0023501762632197414, 'mean_word_length': 1.343224227592536, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5301906', 'n_tokens_mistral': 2066, 'n_tokens_neox': 2000, 'n_words': 332}