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.

148 lines
7.6KB

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