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.

147 satır
7.5KB

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