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.

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