Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

382 lines
21KB

  1. <?php
  2. /**
  3. * Copyright distrib (2018)
  4. *
  5. * contact@opendistrib.net
  6. *
  7. * Ce logiciel est un programme informatique servant à aider les producteurs
  8. * à distribuer leur production en circuits courts.
  9. *
  10. * Ce logiciel est régi par la licence CeCILL soumise au droit français et
  11. * respectant les principes de diffusion des logiciels libres. Vous pouvez
  12. * utiliser, modifier et/ou redistribuer ce programme sous les conditions
  13. * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  14. * sur le site "http://www.cecill.info".
  15. *
  16. * En contrepartie de l'accessibilité au code source et des droits de copie,
  17. * de modification et de redistribution accordés par cette licence, il n'est
  18. * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  19. * seule une responsabilité restreinte pèse sur l'auteur du programme, le
  20. * titulaire des droits patrimoniaux et les concédants successifs.
  21. *
  22. * A cet égard l'attention de l'utilisateur est attirée sur les risques
  23. * associés au chargement, à l'utilisation, à la modification et/ou au
  24. * développement et à la reproduction du logiciel par l'utilisateur étant
  25. * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  26. * manipuler et qui le réserve donc à des développeurs et des professionnels
  27. * avertis possédant des connaissances informatiques approfondies. Les
  28. * utilisateurs sont donc invités à charger et tester l'adéquation du
  29. * logiciel à leurs besoins dans des conditions permettant d'assurer la
  30. * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  31. * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  32. *
  33. * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  34. * pris connaissance de la licence CeCILL, et que vous en avez accepté les
  35. * termes.
  36. */
  37. use yii\helpers\Html;
  38. use yii\widgets\ActiveForm;
  39. use common\models\Product;
  40. use yii\helpers\ArrayHelper;
  41. use common\models\TaxRate;
  42. use common\models\Producer;
  43. \backend\assets\VuejsDocumentFormAsset::register($this);
  44. ?>
  45. <div class="document-form" id="app-document-form" data-class-document="<?= $model->getClass() ?>"
  46. data-id-document="<?= ($model->id > 0) ? $model->id : $model->id ?>">
  47. <div class="<?= ($action == 'update') ? 'col-md-6' : '' ?>">
  48. <div class="panel panel-default">
  49. <div class="panel-heading">
  50. Général
  51. </div>
  52. <div class="panel-body">
  53. <?php $form = ActiveForm::begin(); ?>
  54. <?= Html::hiddenInput('classDocument', $model->getClass(), ['id' => 'class-document']) ?>
  55. <?= Html::hiddenInput('typeAction', $action, ['id' => 'type-action']) ?>
  56. <?php if ($action == 'update'): ?>
  57. <?= Html::hiddenInput('idDocument', $model->id, ['id' => 'id-document']) ?>
  58. <?php endif; ?>
  59. <?= $form->field($model, 'name')->label('Nom du document') ?>
  60. <?php if ($action == 'update'): ?>
  61. <?= $form->field($model, 'id_user', [
  62. 'template' => '{label} <div>{input}</div>' . $model->user->getUsername(),
  63. ])->hiddenInput(); ?>
  64. <?php else: ?>
  65. <?= $form->field($model, 'id_user', [
  66. 'template' => '{label} <a href="' . Yii::$app->urlManager->createUrl(['user/create']) . '" class="btn btn-xs btn-default">Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span></a><div>{input}</div>{hint}',
  67. ])
  68. ->dropDownList(
  69. User::populateDropdownList(),
  70. [
  71. '@change' => 'changeUser',
  72. 'v-model' => 'idUser',
  73. 'class' => 'select2'
  74. ]
  75. ); ?>
  76. <?php endif; ?>
  77. <?= $form->field($model, 'address')->textarea(['rows' => 2, 'v-model' => 'document.address']) ?>
  78. <?php if ($action == 'update'): ?>
  79. <?= $form->field($model, 'comment')->textarea(['rows' => 2])->hint('Affiché en bas du document') ?>
  80. <?php endif; ?>
  81. <?php if ($action == 'create' && $model->getClass() == 'Invoice'): ?>
  82. <template v-if="idUser > 0">
  83. <strong>Bons de livraison</strong>
  84. <table v-if="deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0" class="table table-bordered">
  85. <thead>
  86. <tr>
  87. <th></th>
  88. <th>Libellé</th>
  89. <th v-if="taxRateProducer != 0">Montant (TTC)</th>
  90. <th v-else>Montant</th>
  91. </tr>
  92. </thead>
  93. <tbody>
  94. <tr v-for="deliveryNote in deliveryNoteCreateArray">
  95. <td><input type="checkbox" name="Invoice[deliveryNotes][]" :value="deliveryNote.id"/></td>
  96. <td>{{ deliveryNote.name }}</td>
  97. <td>{{ formatPrice(deliveryNote.total) }}</td>
  98. </tr>
  99. </tbody>
  100. </table>
  101. <div v-else class="alert alert-warning">Aucun bon de livraison pour cet utilisateur.</div>
  102. </template>
  103. <?php endif; ?>
  104. <div class="form-group">
  105. <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?>
  106. </div>
  107. <?php ActiveForm::end(); ?>
  108. </div>
  109. </div>
  110. <?php if ($action == 'update' && $model->getClass() == 'Invoice'): ?>
  111. <div class="panel panel-default">
  112. <div class="panel-heading">
  113. Bons de livraison
  114. </div>
  115. <div class="panel-body">
  116. <table v-if="deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0" class="table table-bordered">
  117. <thead>
  118. <tr>
  119. <th>Libellé</th>
  120. <th v-if="taxRateProducer != 0">Montant (TTC)</th>
  121. <th v-else>Montant</th>
  122. <th v-if="document.status == 'draft'"></th>
  123. </tr>
  124. </thead>
  125. <tbody>
  126. <tr v-for="deliveryNote in deliveryNoteUpdateArray">
  127. <td><a :href="deliveryNote.url">{{ deliveryNote.name }}</a></td>
  128. <td>{{ formatPrice(deliveryNote.total) }}</td>
  129. <td v-if="document.status == 'draft'"><a class="btn btn-default" href="javascript:void(0);" @click="deleteDeliveryNoteOfInvoice" :data-id="deliveryNote.id"><span class="glyphicon glyphicon-trash"></span></a></td>
  130. </tr>
  131. </tbody>
  132. </table>
  133. <div v-else class="alert alert-warning">Aucun bon de livraison associé.</div>
  134. <div v-if="document.status == 'draft'" id="delivery-note-add">
  135. <div class="col-md-8">
  136. <select class="form-control" v-model="deliveryNoteAddId">
  137. <option value="0" selected="selected">--</option>
  138. <option v-for="deliveryNote in deliveryNoteCreateArray" :value="deliveryNote.id">
  139. {{ deliveryNote.name }}
  140. </option>
  141. </select>
  142. </div>
  143. <div class="col-md-4">
  144. <button class="btn btn-primary" value="Ajouter" @click="submitDeliveryNoteAddToInvoice">Ajouter</button>
  145. </div>
  146. </div>
  147. </div>
  148. </div>
  149. <?php endif; ?>
  150. </div>
  151. <?php if ($action == 'update'): ?>
  152. <div class="col-md-6">
  153. <div id="" class="info-box">
  154. <span class="info-box-icon bg-green"><i class="fa fa-sticky-note-o"></i></span>
  155. <div class="info-box-content">
  156. <span class="info-box-text">
  157. <?= $typeDocument ?>
  158. <span v-html="document.html_label"></span>
  159. <span v-if="document.is_sent" class="label label-success">Envoyé</span>
  160. </span>
  161. <span class="info-box-number">{{ document.reference }}</span>
  162. <span class="info-box-text">Date</span>
  163. <span class="info-box-number">{{ document.date }}</span>
  164. </div>
  165. </div>
  166. <div id="" class="info-box">
  167. <span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span>
  168. <div class="info-box-content">
  169. <span class="info-box-text">Total<span v-if="taxRateProducer != 0"> (TTC)</span></span>
  170. <span class="info-box-number">{{ formatPrice(total_with_tax) }}</span>
  171. <p v-if="invoiceUrl">
  172. <a class="btn btn-sm btn-default" :href="invoiceUrl">
  173. <span class="glyphicon glyphicon-eye-open"></span> Voir la facture
  174. </a>
  175. </p>
  176. </div>
  177. </div>
  178. <div id="" class="info-box">
  179. <span class="info-box-icon bg-yellow"><i class="fa fa-calendar"></i></span>
  180. <div class="info-box-content">
  181. <span class="info-box-text">Commandes</span>
  182. <?php foreach($model->orders as $order): ?>
  183. <a class="btn btn-sm btn-default" href="<?= Yii::$app->urlManager->createUrl(['distribution/index', 'idOrderUpdate' => $order->id]); ?>">
  184. <?= date('d/m/Y', strtotime($order->distribution->date)) ?>
  185. </a>
  186. <?php endforeach; ?>
  187. </div>
  188. </div>
  189. <div id="" class="info-box">
  190. <span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span>
  191. <div class="info-box-content">
  192. <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/download', 'id' => $model->id]) ?>"
  193. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger (PDF)</a>
  194. <?php if ($model->getClass() == 'Invoice' && Producer::getConfig('option_export_evoliz')): ?>
  195. <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>"
  196. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz
  197. (CSV)</a>
  198. <?php endif; ?>
  199. </div>
  200. </div>
  201. <div v-if="document.status == 'draft' || !document.is_sent" class="info-box">
  202. <span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span>
  203. <div class="info-box-content">
  204. <a v-if="document.status == 'draft'" href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/validate', 'id' => $model->id, 'backUpdateForm' => 1]) ?>"
  205. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-ok"></span> Valider le document</a>
  206. <?php if (isset($model->user) && strlen($model->user->email) > 0): ?>
  207. <a v-if="!document.is_sent" href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/send', 'id' => $model->id, 'backUpdateForm' => 1]) ?>"
  208. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-send"></span> Envoyer le
  209. document</a>
  210. <?php endif; ?>
  211. </div>
  212. </div>
  213. </div>
  214. <div class="clr"></div>
  215. <div class="">
  216. <div class="panel panel-default" id="block-add-product">
  217. <div class="panel-heading">
  218. Ajouter un produit
  219. </div>
  220. <div class="panel-body">
  221. <div class="col-md-6">
  222. <strong>Produit</strong>
  223. <select class="form-control" v-model="productAddId"
  224. @change="changeProductAdd">
  225. <option value="0" selected="selected">--</option>
  226. <option v-for="product in productsArray" :value="product.id">
  227. {{ product.name }}
  228. </option>
  229. </select>
  230. </div>
  231. <template v-if="productAddId > 0">
  232. <div class="col-md-3">
  233. <strong>Prix unitaire</strong>
  234. <div class="input-group">
  235. <input type="text" class="form-control input-price"
  236. v-model="productAddPrice" @change="formatProductAddPrice"/>
  237. <span class="input-group-addon"><span
  238. class="glyphicon glyphicon-euro"></span> <span v-if="taxRateProducer != 0">HT</span></span>
  239. </div>
  240. </div>
  241. <div class="col-md-3 total">
  242. <strong>Quantité</strong>
  243. <div class="input-group input-group-quantity">
  244. <span class="input-group-btn">
  245. <button class="btn btn-default" type="button"
  246. @click="changeQuantityProductAdd(-1)">-</button>
  247. </span>
  248. <input type="text" class="form-control input-quantity"
  249. v-model="productAddQuantity" @change="formatProductAddQuantity"/>
  250. <span class="input-group-addon">{{ getProductById(productAddId).wording_unit }}</span>
  251. <span class="input-group-btn">
  252. <button class="btn btn-default"
  253. type="button"
  254. @click="changeQuantityProductAdd(1)">+</button>
  255. </span>
  256. </div>
  257. <button class="btn btn-primary" value="Ajouter"
  258. @click="submitProductAdd">Ajouter
  259. </button>
  260. <div class="clr"></div>
  261. </div>
  262. <!--<div class="col-md-3 total">
  263. <strong>Total</strong>
  264. <div class="input-group">
  265. <input type="text" class="form-control input-price" readonly
  266. :value="formatPrice(productAddPrice * productAddQuantity)"/>
  267. <span class="input-group-addon"><span
  268. class="glyphicon glyphicon-euro"></span> <span v-if="taxRateProducer != 0">HT</span></span>
  269. </div>
  270. </div>-->
  271. </template>
  272. <div class="clr"></div>
  273. </div>
  274. </div>
  275. <div class="panel panel-default">
  276. <div class="panel-heading">
  277. Produits
  278. </div>
  279. <div class="panel-body">
  280. <div id="block-list-products">
  281. <table class="table table-bordered" v-if="total > 0">
  282. <thead>
  283. <tr>
  284. <th>Nom</th>
  285. <th>Prix (unité)</th>
  286. <th>Quantité</th>
  287. <th v-if="taxRateProducer != 0">TVA</th>
  288. <th v-if="taxRateProducer != 0">Total HT</th>
  289. <th v-else>Total</th>
  290. <th>Supprimer</th>
  291. </tr>
  292. </thead>
  293. <tbody>
  294. <template v-for="order in ordersArray">
  295. <tr v-for="productOrder in order.productOrder">
  296. <td class="col-md-4">
  297. <div class="product-name">{{ getProductById(productOrder.id_product).name }}
  298. </div>
  299. <ul class="product-order-meta">
  300. <li v-if="order.distribution_date">Commande : <a class="btn btn-sm btn-default" :href="productOrder.url_order">{{ order.distribution_date }}</a></li>
  301. <li>Utilisateur : {{ order.username }}</li>
  302. <li v-if="order.point_sale_name">Point de vente : {{ order.point_sale_name }}</li>
  303. </ul>
  304. </td>
  305. <td class="col-md-2">
  306. {{ formatPrice(getProductOrderPrice(productOrder)) }}
  307. <template v-if="document.status == 'draft' && getProductOrderPrice(productOrder) != getBestProductPrice(productOrder.id_product, productOrder.quantity)">
  308. <i class="fa fa-exclamation-triangle" title="Prix différent de celui défini au niveau du produit"></i>
  309. </template>
  310. </td>
  311. <td class="col-md-2">{{ productOrder.quantity }}</td>
  312. <td class="col-md-1" v-if="taxRateProducer != 0">
  313. {{ getProductById(productOrder.id_product).tax_rate * 100 }} %
  314. </td>
  315. <td class="col-md-2">
  316. {{ formatPrice(productOrder.quantity * getProductOrderPrice(productOrder)) }}
  317. </td>
  318. <td class="col-md-1">
  319. <a class="btn btn-default" @click="deleteProductOrder(productOrder.id)">
  320. <span class="glyphicon glyphicon-trash"></span>
  321. </a>
  322. </td>
  323. </tr>
  324. </template>
  325. <template v-if="taxRateProducer != 0">
  326. <tr>
  327. <td colspan="4"><strong>Total HT</strong></td>
  328. <td><strong>{{ formatPrice(total) }} HT</strong></td>
  329. <td></td>
  330. </tr>
  331. <tr>
  332. <td colspan="4"><strong>Montant TVA</strong></td>
  333. <td><strong>{{ formatPrice(total_with_tax - total) }}</strong></td>
  334. <td></td>
  335. </tr>
  336. <tr>
  337. <td colspan="4"><strong>Total TTC</strong></td>
  338. <td><strong>{{ formatPrice(total_with_tax) }} TTC</strong></td>
  339. <td></td>
  340. </tr>
  341. </template>
  342. <template v-else>
  343. <tr>
  344. <td colspan="3"><strong>Total</strong></td>
  345. <td><strong>{{ formatPrice(total) }}</strong></td>
  346. <td></td>
  347. </tr>
  348. </template>
  349. </tbody>
  350. </table>
  351. <div v-else class="alert alert-info">
  352. Aucun produit.
  353. </div>
  354. </div>
  355. </div>
  356. </div>
  357. </div>
  358. <?php endif; ?>
  359. </div>