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.

_form.php 24KB

3 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <?php
  2. /**
  3. * Copyright Guillaume Bourgeois (2018)
  4. *
  5. * contact@souke.fr
  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 domain\Document\Document\DocumentModule;
  38. use domain\Document\Invoice\InvoiceModule;
  39. use domain\Payment\PaymentModule;
  40. use domain\Producer\Producer\ProducerModule;
  41. use domain\User\User\UserModule;
  42. use yii\helpers\Html;
  43. use yii\widgets\ActiveForm;
  44. $producerModule = ProducerModule::getInstance();
  45. $documentModule = DocumentModule::getInstance();
  46. $invoiceModule = InvoiceModule::getInstance();
  47. $userModule = UserModule::getInstance();
  48. $paymentManager = PaymentModule::getInstance();
  49. $documentClass = $documentModule->getClass($model);
  50. ?>
  51. <div class="document-form" id="app-document-form" data-class-document="<?= $documentClass ?>"
  52. data-id-document="<?= ($model->id > 0) ? $model->id : $model->id ?>">
  53. <div class="<?= ($action == 'update') ? 'col-md-6' : '' ?>">
  54. <div class="panel panel-default">
  55. <div class="panel-heading">
  56. Général
  57. </div>
  58. <div class="panel-body">
  59. <?php $form = ActiveForm::begin(); ?>
  60. <?= Html::hiddenInput('classDocument', $documentClass, ['id' => 'class-document']) ?>
  61. <?= Html::hiddenInput('typeAction', $action, ['id' => 'type-action']) ?>
  62. <?php if ($action == 'update'): ?>
  63. <?= Html::hiddenInput('idDocument', $model->id, ['id' => 'id-document']) ?>
  64. <?php endif; ?>
  65. <?= $form->field($model, 'name')->textInput(['v-model' => 'document.name'])->label('Nom du document') ?>
  66. <?php if ($action == 'update'): ?>
  67. <?= $form->field($model, 'id_user', [
  68. 'template' => '{label} <div>{input}</div>' . $userModule->getUsername($model->user),
  69. ])->hiddenInput(); ?>
  70. <?php else: ?>
  71. <?= $form->field($model, 'id_user', [
  72. '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}',
  73. ])
  74. ->dropDownList(
  75. $userModule->populateUserDropdownList(),
  76. [
  77. '@change' => 'changeUser',
  78. 'v-model' => 'idUser',
  79. 'class' => 'select2 select2-document-form'
  80. ]
  81. ); ?>
  82. <?php endif; ?>
  83. <?= $form->field($model, 'address')->textarea(['rows' => 2, 'v-model' => 'document.address']) ?>
  84. <?php if ($action == 'update'): ?>
  85. <?= $form->field($model, 'comment')->textarea(['rows' => 2])->hint('Affiché en bas du document') ?>
  86. <?php endif; ?>
  87. <?php if ($action == 'create' && $documentClass == 'Invoice'): ?>
  88. <template v-if="idUser > 0">
  89. <template v-if="deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0">
  90. <strong>Bons de livraison</strong>
  91. <table v-if="deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0"
  92. class="table table-bordered">
  93. <thead>
  94. <tr>
  95. <th>
  96. <input type="checkbox" class="check-all-checkboxes" data-selector=".checkbox-delivery-note" />
  97. </th>
  98. <th>Libellé</th>
  99. <th v-if="taxRateProducer != 0">Montant (TTC)</th>
  100. <th v-else>Montant</th>
  101. </tr>
  102. </thead>
  103. <tbody>
  104. <tr v-for="deliveryNote in deliveryNoteCreateArray">
  105. <td><input type="checkbox" class="checkbox-delivery-note" name="Invoice[deliveryNotes][]" :value="deliveryNote.id"/></td>
  106. <td>{{ deliveryNote.name }}</td>
  107. <td>{{ formatPrice(deliveryNote.total) }}</td>
  108. </tr>
  109. </tbody>
  110. </table>
  111. <div v-else class="alert alert-warning">Aucun bon de livraison pour cet utilisateur.</div>
  112. </template>
  113. <template v-else-if="ordersCreateArray && ordersCreateArray.length > 0">
  114. <strong>Commandes</strong>
  115. <table v-if="ordersCreateArray && ordersCreateArray.length > 0"
  116. class="table table-bordered">
  117. <thead>
  118. <tr>
  119. <th></th>
  120. <th>Date</th>
  121. <th v-if="taxRateProducer != 0">Montant (TTC)</th>
  122. <th v-else>Montant</th>
  123. </tr>
  124. </thead>
  125. <tbody>
  126. <tr v-for="order in ordersCreateArray">
  127. <td><input type="checkbox" name="Invoice[ordersOnCreate][]" :value="order.id"/></td>
  128. <td>{{ order.name }}</td>
  129. <td>{{ formatPrice(order.amount_with_tax) }}</td>
  130. </tr>
  131. </tbody>
  132. </table>
  133. <div v-else class="alert alert-warning">Aucune commande pour cet utilisateur.</div>
  134. </template>
  135. </template>
  136. <?php endif; ?>
  137. <div class="form-group">
  138. <?= Html::submitButton($model->isNewRecord ? 'Ajouter' : 'Modifier', ['class' => 'btn btn-primary']) ?>
  139. </div>
  140. <?php ActiveForm::end(); ?>
  141. </div>
  142. </div>
  143. </div>
  144. <?php if ($action == 'update'): ?>
  145. <div class="col-md-6">
  146. <div id="" class="info-box">
  147. <span class="info-box-icon bg-green"><i class="fa fa-sticky-note-o"></i></span>
  148. <div class="info-box-content">
  149. <span class="info-box-text">
  150. <?= $typeDocument ?>
  151. <span v-html="document.html_label"></span>
  152. <span v-if="document.is_sent" class="label label-success">Envoyé</span>
  153. </span>
  154. <span class="info-box-number">{{ document.reference }}</span>
  155. <span class="info-box-text">Date</span>
  156. <span class="info-box-number">{{ document.date }}</span>
  157. </div>
  158. </div>
  159. <div id="" class="info-box">
  160. <span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span>
  161. <div class="info-box-content">
  162. <span class="info-box-text">
  163. Total<span v-if="taxRateProducer != 0"> (TTC)</span>
  164. <?php if( $invoiceModule->isDocumentInvoice($model) && $invoiceModule->isInvoicePaid($model)): ?>
  165. <span class="label label-success">PAYÉE</span>
  166. <?php endif; ?>
  167. </span>
  168. <span class="info-box-number">{{ formatPrice(total_with_tax) }}</span>
  169. <p v-if="invoiceUrl">
  170. <a class="btn btn-sm btn-default" :href="invoiceUrl">
  171. <span class="glyphicon glyphicon-eye-open"></span> Voir la facture
  172. </a>
  173. </p>
  174. </div>
  175. </div>
  176. <div id="" class="info-box">
  177. <span class="info-box-icon bg-yellow"><i class="fa fa-calendar"></i></span>
  178. <div class="info-box-content">
  179. <span class="info-box-text">Commandes</span>
  180. <?php foreach ($model->orders as $order): ?>
  181. <?php if ($order->distribution): ?>
  182. <a class="btn btn-sm btn-default"
  183. href="<?= Yii::$app->urlManager->createUrl(['distribution/index', 'idOrderUpdate' => $order->id]); ?>">
  184. <?= date('d/m/Y', strtotime($order->distribution->date)) ?>
  185. </a>
  186. <?php endif; ?>
  187. <?php endforeach; ?>
  188. </div>
  189. </div>
  190. <div id="" class="info-box">
  191. <span class="info-box-icon bg-blue"><i class="fa fa-download"></i></span>
  192. <div class="info-box-content">
  193. <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/download', 'id' => $model->id]) ?>"
  194. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-download-alt"></span> Télécharger
  195. (PDF)</a>
  196. <?php if ($documentClass == 'Invoice' && $producerModule->getConfig('option_export_evoliz')): ?>
  197. <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/export-csv-evoliz', 'id' => $model->id]) ?>"
  198. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-save-file"></span> Export Evoliz
  199. (CSV)</a>
  200. <?php endif; ?>
  201. </div>
  202. </div>
  203. <div class="info-box">
  204. <span class="info-box-icon bg-red"><i class="fa fa-flash"></i></span>
  205. <div class="info-box-content">
  206. <a v-if="document.status == 'draft'"
  207. href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/validate', 'id' => $model->id, 'backUpdateForm' => 1]) ?>"
  208. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-ok"></span> Valider le document</a>
  209. <?php if ($documentModule->isStatusValid($model)): ?>
  210. <a href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/regenerate', 'id' => $model->id]) ?>"
  211. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-repeat"></span> Regénérer
  212. (PDF)</a>
  213. <?php endif; ?>
  214. <?php if (isset($model->user) && strlen($model->user->email) > 0): ?>
  215. <a v-if="!document.is_sent"
  216. href="<?= Yii::$app->urlManager->createUrl([Yii::$app->controller->getControllerUrl() . '/send', 'id' => $model->id, 'backUpdateForm' => 1]) ?>"
  217. class="btn btn-sm btn-default"><span class="glyphicon glyphicon-send"></span> Envoyer le
  218. document</a>
  219. <?php endif; ?>
  220. </div>
  221. </div>
  222. </div>
  223. <div class="clr"></div>
  224. <?php if ($action == 'update' && $documentClass == 'DeliveryNote'): ?>
  225. <?= $this->render('form/_orders'); ?>
  226. <?php endif; ?>
  227. <?php if ($action == 'update' && $documentClass == 'Invoice'): ?>
  228. <?= $this->render('form/_payment', ['model' => $model, 'payment' => $payment]); ?>
  229. <div v-if="(deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0) || (deliveryNoteCreateArray && deliveryNoteCreateArray.length > 0)">
  230. <div class="panel panel-default">
  231. <div class="panel-heading">
  232. Bons de livraison
  233. </div>
  234. <div class="panel-body">
  235. <table v-if="deliveryNoteUpdateArray && deliveryNoteUpdateArray.length > 0"
  236. class="table table-bordered">
  237. <thead>
  238. <tr>
  239. <th>Libellé</th>
  240. <th v-if="taxRateProducer != 0">Montant (TTC)</th>
  241. <th v-else>Montant</th>
  242. <th v-if="document.status == 'draft'"></th>
  243. </tr>
  244. </thead>
  245. <tbody>
  246. <tr v-for="deliveryNote in deliveryNoteUpdateArray">
  247. <td><a :href="deliveryNote.url">{{ deliveryNote.name }}</a></td>
  248. <td>{{ formatPrice(deliveryNote.total) }}</td>
  249. <td v-if="document.status == 'draft'"><a class="btn btn-default" href="javascript:void(0);"
  250. @click="deleteDeliveryNoteFromInvoice"
  251. :data-id="deliveryNote.id"><span
  252. class="glyphicon glyphicon-trash"></span></a></td>
  253. </tr>
  254. </tbody>
  255. </table>
  256. <div v-else class="alert alert-warning">Aucun bon de livraison associé.</div>
  257. <div v-if="document.status == 'draft'" id="delivery-note-add">
  258. <div class="col-md-8">
  259. <select class="form-control" v-model="deliveryNoteAddId">
  260. <option value="0" selected="selected">--</option>
  261. <option v-for="deliveryNote in deliveryNoteCreateArray" :value="deliveryNote.id">
  262. {{ deliveryNote.name }}
  263. </option>
  264. </select>
  265. </div>
  266. <div class="col-md-4">
  267. <button class="btn btn-primary" value="Ajouter" @click="submitDeliveryNoteAddToInvoice">
  268. Ajouter
  269. </button>
  270. </div>
  271. </div>
  272. </div>
  273. </div>
  274. </div>
  275. <div v-else>
  276. <?= $this->render('form/_orders'); ?>
  277. </div>
  278. <div class="clr"></div>
  279. <?php endif; ?>
  280. <div class="panel panel-default" id="block-add-product">
  281. <div class="panel-heading">
  282. Ajouter un produit
  283. </div>
  284. <div class="panel-body">
  285. <div class="col-md-6">
  286. <strong>Produit</strong>
  287. <select class="form-control" v-model="productAddId"
  288. @change="changeProductAdd">
  289. <option value="0" selected="selected">--</option>
  290. <option v-for="product in productsArray" v-if="product.status >= 0" :value="product.id">
  291. {{ product.name }}
  292. </option>
  293. </select>
  294. </div>
  295. <template v-if="productAddId > 0">
  296. <div class="col-md-3">
  297. <strong>Prix unitaire</strong>
  298. <div class="input-group">
  299. <input type="text" class="form-control input-price"
  300. v-model="productAddPrice" @change="formatProductAddPrice"/>
  301. <span class="input-group-addon"><span
  302. class="glyphicon glyphicon-euro"></span> <span v-if="taxRateProducer != 0">HT</span></span>
  303. </div>
  304. </div>
  305. <div class="col-md-3 total">
  306. <strong>Quantité</strong>
  307. <div class="input-group input-group-quantity">
  308. <span class="input-group-btn">
  309. <button class="btn btn-default" type="button"
  310. @click="changeQuantityProductAdd(-1)">-</button>
  311. </span>
  312. <input type="text" class="form-control input-quantity"
  313. v-model="productAddQuantity" @change="formatProductAddQuantity"/>
  314. <span class="input-group-addon">{{ getProductById(productAddId).wording_unit }}</span>
  315. <span class="input-group-btn">
  316. <button class="btn btn-default"
  317. type="button"
  318. @click="changeQuantityProductAdd(1)">+</button>
  319. </span>
  320. </div>
  321. <button class="btn btn-primary" value="Ajouter"
  322. @click="submitProductAdd">Ajouter
  323. </button>
  324. <div class="clr"></div>
  325. </div>
  326. </template>
  327. <div class="clr"></div>
  328. </div>
  329. </div>
  330. <div class="panel panel-default">
  331. <div class="panel-heading">
  332. Produits
  333. </div>
  334. <div class="panel-body">
  335. <div id="block-list-products">
  336. <table class="table table-bordered" v-if="Object.keys(ordersArray).length > 0">
  337. <thead>
  338. <tr>
  339. <th>Nom</th>
  340. <th>Prix (unité)</th>
  341. <th>Quantité</th>
  342. <th v-if="taxRateProducer != 0">TVA</th>
  343. <th v-if="taxRateProducer != 0">Total HT</th>
  344. <th v-else>Total</th>
  345. <th>Supprimer</th>
  346. </tr>
  347. </thead>
  348. <tbody>
  349. <template v-for="order in ordersArray">
  350. <tr v-for="productOrder in order.productOrder">
  351. <td class="col-md-4">
  352. <div class="product-name">
  353. <a :href="productOrder.url_product" target="_blank">
  354. {{ getProductById(productOrder.id_product).name }}
  355. </a>
  356. </div>
  357. <ul class="product-order-meta">
  358. <li v-if="order.distribution_date">Commande : <a :href="productOrder.url_order">{{
  359. order.distribution_date }}</a></li>
  360. <li>Utilisateur : {{ order.username }}</li>
  361. <li v-if="order.point_sale_name">Point de vente : {{ order.point_sale_name }}</li>
  362. </ul>
  363. </td>
  364. <td class="col-md-2">
  365. <template v-if="document.status == 'draft'">
  366. <div class="input-group input-group-edit-invoice-price">
  367. <input type="text" class="form-control" :id="'input-product-order-invoice-price-'+productOrder.id" :value="getProductOrderPrice(productOrder)" :data-id-product-order="productOrder.id" @keyup="showProductOrderInvoicePriceButtonApply" />
  368. <span class="input-group-addon">€</span>
  369. </div>
  370. <div class="product-order-invoice-price-button-apply" :id="'product-order-invoice-price-button-apply-'+productOrder.id">
  371. <button class="btn btn-success" type="button" :data-id-product-order="productOrder.id" @click="updateProductOrderInvoicePrice">
  372. <span class="glyphicon glyphicon-ok"></span>
  373. </button>
  374. </div>
  375. </template>
  376. <template v-else>
  377. {{ formatPrice(getProductOrderPrice(productOrder)) }}
  378. </template>
  379. <template
  380. v-if="document.status == 'draft' && getProductOrderPrice(productOrder) != getBestProductPrice(productOrder.id_product, productOrder.quantity)">
  381. <i class="different-price fa fa-exclamation-triangle"
  382. :title="'Prix différent de celui défini au niveau du produit ('+getBestProductPrice(productOrder.id_product, productOrder.quantity)+' €)'"></i>
  383. </template>
  384. </td>
  385. <td class="col-md-2">{{ productOrder.quantity }}</td>
  386. <td class="col-md-1" v-if="taxRateProducer != 0">
  387. {{ getProductById(productOrder.id_product).tax_rate * 100 }} %
  388. </td>
  389. <td class="col-md-2">
  390. {{ formatPrice(productOrder.quantity * getProductOrderPrice(productOrder)) }}
  391. </td>
  392. <td class="col-md-1">
  393. <a class="btn btn-default" @click="deleteProductOrder(productOrder.id)">
  394. <span class="glyphicon glyphicon-trash"></span>
  395. </a>
  396. </td>
  397. </tr>
  398. </template>
  399. <template v-if="taxRateProducer != 0">
  400. <tr>
  401. <td colspan="4"><strong>Total HT</strong></td>
  402. <td><strong>{{ formatPrice(total) }} HT</strong></td>
  403. <td></td>
  404. </tr>
  405. <tr>
  406. <td colspan="4"><strong>Montant TVA</strong></td>
  407. <td><strong>{{ formatPrice(total_with_tax - total) }}</strong></td>
  408. <td></td>
  409. </tr>
  410. <tr>
  411. <td colspan="4"><strong>Total TTC</strong></td>
  412. <td><strong>{{ formatPrice(total_with_tax) }} TTC</strong></td>
  413. <td></td>
  414. </tr>
  415. </template>
  416. <template v-else>
  417. <tr>
  418. <td colspan="3"><strong>Total</strong></td>
  419. <td><strong>{{ formatPrice(total) }}</strong></td>
  420. <td></td>
  421. </tr>
  422. </template>
  423. </tbody>
  424. </table>
  425. <div v-else class="alert alert-info">
  426. Aucun produit.
  427. </div>
  428. </div>
  429. </div>
  430. </div>
  431. <?php endif; ?>