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.

537 lines
28KB

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