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.

160 lines
8.8KB

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