You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 line
8.8KB

  1. <?php
  2. use yii\helpers\Html;
  3. use yii\bootstrap\ActiveForm;
  4. use common\models\Product;
  5. use yii\helpers\ArrayHelper;
  6. use common\models\TaxRate;
  7. use common\models\Producer;
  8. use common\helpers\GlobalParam;
  9. ?>
  10. <div class="product-form">
  11. <?php $form = ActiveForm::begin([
  12. 'enableClientValidation' => false,
  13. 'options' => ['enctype' => 'multipart/form-data']
  14. ]); ?>
  15. <div>
  16. <div class="col-md-8">
  17. <?= $form->field($model, 'active')->radioList([1 => 'Oui', 0 => 'Non']) ?>
  18. <?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?>
  19. <?= $form->field($model, 'reference')->textInput(['maxlength' => 255]) ?>
  20. <?= $form->field($model, 'id_product_category')->dropDownList(ProductCategory::populateDropdownList()); ?>
  21. <?= $form->field($model, 'description')->textInput(['maxlength' => 255]) ?>
  22. <?= $form->field($model, 'recipe')->textarea()->label('Description longue') ?>
  23. <?= $form->field($model, 'unit')
  24. ->dropDownList(ArrayHelper::map(Product::$unitsArray, 'unit', 'wording'))
  25. ->label('Unité (pièce, poids ou volume)'); ?>
  26. <?php
  27. //Récupère la tva par défaut du producteur courant
  28. $producer = \common\helpers\GlobalParam::getCurrentProducer();
  29. $taxRateDefault = $producer->taxRate;
  30. $taxRateNamesArray = array_merge(array(0 => 'Tva par défaut'), ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) {
  31. return $model->name;
  32. }));
  33. $taxRateValuesArray = array_merge(array(0 => $taxRateDefault->value), ArrayHelper::map(TaxRate::find()->all(), 'id', function ($model) {
  34. return $model->value;
  35. }));
  36. foreach ($taxRateValuesArray as $key => $taxRateValue) {
  37. $taxRateValuesArrayFormatted[$key] = array('data-tax-rate-value' => $taxRateValue);
  38. }
  39. ?>
  40. <?php if($taxRateDefault->value != 0): ?>
  41. <?= $form->field($model, 'id_tax_rate')->dropDownList($taxRateNamesArray, ['options' => $taxRateValuesArrayFormatted])->label('Taxe'); ?>
  42. <?php endif; ?>
  43. <?= $form->field($model, 'price', [
  44. 'template' => '
  45. <div class="row">
  46. <div class="col-xs-6">
  47. <label for="product-price" class="control-label without-tax"></label>
  48. <div class="input-group">
  49. {input}<span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
  50. </div>
  51. </div>
  52. <div class="col-xs-6">
  53. <label for="product-price-with-tax" class="control-label with-tax"></label>
  54. <div class="input-group">
  55. <input type="text" id="product-price-with-tax" class="form-control" name="" value="">
  56. <span class="input-group-addon"><span class="glyphicon glyphicon-euro"></span></span>
  57. </div>
  58. </div>
  59. </div>
  60. ',
  61. ]) ?>
  62. <?= $form->field($model, 'step')->textInput()->hint('Définit ce qui est ajouté ou enlevé lors des changements de quantité.') ?>
  63. <?= $form->field($model, 'weight')->textInput()->label('Poids (g)') ?>
  64. <div class="col-md-3">
  65. <?= $form->field($model, 'quantity_max')->textInput() ?>
  66. </div>
  67. <div class="col-md-3">
  68. <?= $form->field($model, 'quantity_max_monday')->textInput() ?>
  69. </div>
  70. <div class="col-md-3">
  71. <?= $form->field($model, 'quantity_max_tuesday')->textInput() ?>
  72. </div>
  73. <div class="col-md-3">
  74. <?= $form->field($model, 'quantity_max_wednesday')->textInput() ?>
  75. </div>
  76. <div class="col-md-3">
  77. <?= $form->field($model, 'quantity_max_thursday')->textInput() ?>
  78. </div>
  79. <div class="col-md-3">
  80. <?= $form->field($model, 'quantity_max_friday')->textInput() ?>
  81. </div>
  82. <div class="col-md-3">
  83. <?= $form->field($model, 'quantity_max_saturday')->textInput() ?>
  84. </div>
  85. <div class="col-md-3">
  86. <?= $form->field($model, 'quantity_max_sunday')->textInput() ?>
  87. </div>
  88. <div class="clr"></div>
  89. <?php
  90. if (!$model->isNewRecord) {
  91. echo $form->field($model, 'apply_distributions')
  92. ->checkbox()
  93. ->hint('Sélectionnez cette option si vous souhaitez que ces modifications (actif / non actif, quantité max) soient répercutées dans les distributions à venir déjà initialisées.');
  94. }
  95. ?>
  96. </div>
  97. <div class="col-md-4">
  98. <?= $form->field($model, 'photo')->fileInput() ?>
  99. <?php
  100. if (strlen($model->photo)) {
  101. $url = Yii::$app->urlManagerProducer->getHostInfo() . '/' . Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $model->photo;
  102. $url = str_replace('//uploads','/uploads', $url) ;
  103. echo '<img class="photo-product" src="' . $url . '" width="200px" /><br />';
  104. echo '<input type="checkbox" name="delete_photo" id="delete_photo" /> <label for="delete_photo">Supprimer la photo</label>';
  105. }
  106. ?>
  107. <div id="days-production">
  108. <h2>Jours de distribution</h2>
  109. <?= $form->field($model, 'monday')->checkbox() ?>
  110. <?= $form->field($model, 'tuesday')->checkbox() ?>
  111. <?= $form->field($model, 'wednesday')->checkbox() ?>
  112. <?= $form->field($model, 'thursday')->checkbox() ?>
  113. <?= $form->field($model, 'friday')->checkbox() ?>
  114. <?= $form->field($model, 'saturday')->checkbox() ?>
  115. <?= $form->field($model, 'sunday')->checkbox() ?>
  116. </div>
  117. <div class="clr"></div>
  118. <div id="availability-points-sale">
  119. <h2>Disponibilité points de vente</h2>
  120. <?= $form->field($model, 'available_on_points_sale')->radioList([1 => 'Disponible', 0 => 'Indisponible']) ?>
  121. <strong id="label-availability-points-sale">Et <span><?php if($model->available_on_points_sale): ?>indisponible<?php else: ?>disponible<?php endif; ?></span> sur les points de vente</strong>
  122. <?php $pointSaleArray = PointSale::find()
  123. ->where(['id_producer' => GlobalParam::getCurrentProducerId()])
  124. ->orderBy('is_bread_box ASC, name ASC')
  125. ->all(); ?>
  126. <?= Html::activeCheckboxList($model, 'pointsSale', ArrayHelper::map($pointSaleArray, 'id', function ($pointSale, $defaultValue) use ($model) {
  127. return Html::encode($pointSale->name) ;
  128. }), ['encode' => false, 'class' => '']) ?>
  129. </div>
  130. </div>
  131. <div class="clr"></div>
  132. </div>
  133. <?= $form->field($model, 'id_producer')->hiddenInput()->label('') ?>
  134. <div class="form-group">
  135. <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
  136. </div>
  137. <?php ActiveForm::end(); ?>
  138. </div>