<?php

use common\logic\Config\Unit\Module\UnitModule;
use common\logic\Product\Product\Module\ProductModule;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use common\helpers\GlobalParam;

$unitModule = UnitModule::getInstance();
$userModule = $this->getUserModule();
$userGroupModule = $this->getUserGroupModule();
$pointSaleModule = $this->getPointSaleModule();
$productModule = ProductModule::getInstance();

?>

<div class="product-form">

        <?=
            $this->render('_base_price', [
                    'model' => $modelProduct,
            ]) ;
        ?>

        <?php $form = ActiveForm::begin([
                'enableClientValidation' => false,
                'options' => ['enctype' => 'multipart/form-data']
        ]); ?>

        <?= $form->field($model, 'id_user')->dropDownList($userModule->populateUserDropdownList()); ?>
        <?= $form->field($model, 'id_user_group')->dropDownList($userGroupModule->populateUserGroupDropdownList()); ?>
        <?= $form->field($model, 'id_point_sale')->dropDownList($pointSaleModule->populatePointSaleDropdownList()); ?>
        <?= $form->field($model, 'from_quantity')->label('À partir de la quantité ('. $productModule->getSolver()->strUnit($modelProduct, 'wording', true).')'); ?>

        <?php
            $producer = GlobalParam::getCurrentProducer();
            $taxRateValue = $producer->taxRate->value;
            if($modelProduct->taxRate) {
                    $taxRateValue = $modelProduct->taxRate->value ;
            }
        ?>

        <?= $form->field($model, 'price', [
                'template' => '
                        <div class="row">
                        <div class="col-xs-4">
                            <label for="reduction-increase-percent" class="control-label">Réduction / augmentation</label>
                            <div class="input-group">
                            <input type="text" id="reduction-increase-percent" class="form-control" name="" value="" data-price-base="'.$productModule->getPrice($modelProduct).'"> 
                            <span class="input-group-addon">%</span>
                            </div>
                        </div>
                        <div class="col-xs-4">
                            <label for="product-price" class="control-label without-tax">Prix ('. $productModule->getSolver()->strUnit($modelProduct, 'wording_unit', true).') HT</label>
                            <div class="input-group">
                            {input} <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
                            </div>
                        </div>
                        <div class="col-xs-4">
                            <label for="productprice-price-with-tax" class="control-label with-tax">Prix ('. $productModule->getSolver()->strUnit($modelProduct, 'wording_unit', true).') TTC</label>
                            <div class="input-group">
                                <input type="text" id="productprice-price-with-tax" class="form-control" name="" value="" data-tax-rate-value="'.$taxRateValue.'">
                                <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
                            </div>
                        </div>
                        </div>',
        ]) ?>

        <div class="form-group">
                <?= Html::a('Annuler', ['prices-list', 'id' => $model->id_product], ['class' => 'btn btn-default']) ?>
                <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?>
        </div>

        <?php ActiveForm::end(); ?>
</div>
