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.

168 lines
9.1KB

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