679 line
49KB

  1. <?php
  2. /**
  3. Copyright distrib (2018)
  4. contact@opendistrib.net
  5. Ce logiciel est un programme informatique servant à aider les producteurs
  6. à distribuer leur production en circuits courts.
  7. Ce logiciel est régi par la licence CeCILL soumise au droit français et
  8. respectant les principes de diffusion des logiciels libres. Vous pouvez
  9. utiliser, modifier et/ou redistribuer ce programme sous les conditions
  10. de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  11. sur le site "http://www.cecill.info".
  12. En contrepartie de l'accessibilité au code source et des droits de copie,
  13. de modification et de redistribution accordés par cette licence, il n'est
  14. offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
  15. seule une responsabilité restreinte pèse sur l'auteur du programme, le
  16. titulaire des de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
  17. droits patrimoniaux et les concédants successifs.
  18. A cet égard l'attention de l'utilisateur est attirée sur les risques
  19. associés au chargement, à l'utilisation, à la modification et/ou au
  20. développement et à la reproduction du logiciel par l'utilisateur étant
  21. donné sa spécificité de logiciel libre, qui peut le rendre complexe à
  22. manipuler et qui le réserve donc à des développeurs et des professionnels
  23. avertis possédant des connaissances informatiques approfondies. Les
  24. utilisateurs sont donc invités à charger et tester l'adéquation du
  25. logiciel à leurs besoins dans des conditions permettant d'assurer la
  26. sécurité de leurs systèmes et ou de leurs données et, plus généralement,
  27. à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
  28. Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
  29. pris connaissance de la licence CeCILL, et que vous en avez accepté les
  30. termes.
  31. */
  32. \backend\assets\VuejsDistributionIndexAsset::register($this);
  33. $this->setTitle('Distributions') ;
  34. $this->setPageTitle('Distributions') ;
  35. ?>
  36. <div id="app-distribution-index" class="app-vuejs">
  37. <?php if(strlen($date)): ?>
  38. <span id="distribution-date"><?= $date; ?></span>
  39. <?php endif; ?>
  40. <div id="loading" v-if="showLoading">
  41. <img src="<?= Yii::$app->urlManagerBackend->getBaseUrl(); ?>/img/loader.gif" alt="Chargement ..." />
  42. </div>
  43. <div id="wrapper-app-distribution-index" :class="'wrapper-app-vuejs '+(loading ? '' : 'loaded')">
  44. <div class="col-md-4">
  45. <div id="calendar">
  46. <v-date-picker
  47. is-inline
  48. is-expanded
  49. v-model="date"
  50. popover-visibility="hidden"
  51. firstDayOfWeek="1"
  52. :mode="calendar.mode"
  53. :formats="calendar.formats"
  54. :theme-styles="calendar.themeStyles"
  55. :attributes="calendar.attrs"
  56. @dayclick='dayClicked'>
  57. ></v-date-picker>
  58. </div>
  59. <div class="clr"></div>
  60. </div>
  61. <div class="col-md-8">
  62. <div v-if="date">
  63. <div id="infos-top">
  64. <div class="col-md-12">
  65. <div class="info-box" id="info-box-distribution">
  66. <span :class="'info-box-icon '+(distribution.active ? 'bg-green' : 'bg-red')"><i :class="'fa '+(distribution.active ? 'fa-check' : 'fa-remove')"></i></span>
  67. <div class="info-box-content">
  68. <span class="info-box-text">
  69. <h4>Distribution du <strong>{{ dateFormat }}</strong></h4>
  70. <a @click="activeWeekDistribution" data-active="0" class="btn btn-default btn-active-week" v-if="oneDistributionWeekActive">Désactiver cette semaine</a>
  71. <a @click="activeWeekDistribution" data-active="1" class="btn btn-default btn-active-week" v-else>Activer cette semaine</a>
  72. <a @click="activeDistribution" data-active="0" class="btn btn-default" v-if="distribution.active">Désactiver ce jour</a>
  73. <a @click="activeDistribution" data-active="1" class="btn btn-default" v-else>Activer ce jour</a>
  74. </span>
  75. </div>
  76. </div>
  77. </div>
  78. <!-- produits -->
  79. <div class="col-md-6">
  80. <div class="info-box col-md-4">
  81. <span class="info-box-icon bg-yellow"><i class="fa fa-clone"></i></span>
  82. <div class="info-box-content">
  83. <span class="info-box-text">
  84. {{ countActiveProducts }} Produits<br /><br />
  85. <button class="btn btn-default" @click="showModalProducts = true">Configurer</button>
  86. </span>
  87. </div>
  88. </div>
  89. </div>
  90. <modal v-if="showModalProducts" id="modal-products" @close="showModalProducts = false">
  91. <h3 slot="header">Produits</h3>
  92. <div slot="body">
  93. <table class="table table-condensed table-bordered table-hover">
  94. <thead>
  95. <tr>
  96. <td>Actif</td>
  97. <td>Nom</td>
  98. <td class="quantity-ordered">Commandé</td>
  99. <td class="quantity-max">Maximum</td>
  100. </tr>
  101. </thead>
  102. <tbody>
  103. <tr v-for="product in products">
  104. <td>
  105. <button class="btn btn-success" v-if="product.productDistribution[0].active == 1"><span class="glyphicon glyphicon-ok"></span></button>
  106. <button class="btn btn-default" v-else data-active-product="1" :data-id-product="product.id" @click="productActiveClick"><span class="glyphicon glyphicon-ok"></span></button>
  107. <button class="btn btn-danger" v-if="product.productDistribution[0].active == 0"><span class="glyphicon glyphicon-remove"></span></button>
  108. <button class="btn btn-default" v-else data-active-product="0" :data-id-product="product.id" @click="productActiveClick"><span class="glyphicon glyphicon-remove"></span></button>
  109. </td>
  110. <td>{{ product.name }}</td>
  111. <td class="quantity-ordered">{{ product.quantity_ordered ? product.quantity_ordered + ' '+ ((product.unit == 'piece') ? ' p.' : ' '+(product.unit == 'g' || product.unit == 'kg') ? 'kg' : 'litre(s)') : '&empty;' }}</td>
  112. <td class="quantity-max">
  113. <div class="input-group">
  114. <input type="text" class="form-control quantity-max" placeholder="&infin;" :data-id-product="product.id" v-model="product.productDistribution[0].quantity_max" @keyup="productQuantityMaxChange" />
  115. <span class="input-group-addon">{{ (product.unit == 'piece') ? 'p.' : ' '+((product.unit == 'g' || product.unit == 'kg') ? 'kg' : 'litre(s)') }}</span>
  116. </div>
  117. </td>
  118. </tr>
  119. </tbody>
  120. </table>
  121. </div>
  122. <div slot="footer">
  123. <div class="actions-form">
  124. <button class="modal-default-button btn btn-default" @click="closeModalProducts">Fermer</button>
  125. </div>
  126. </div>
  127. </modal>
  128. <div class="col-md-6">
  129. <div class="info-box col-md-4">
  130. <span class="info-box-icon bg-yellow"><i class="fa fa-map-marker"></i></span>
  131. <div class="info-box-content">
  132. <span class="info-box-text">
  133. {{ countActivePointsSale }} Points de vente<br /><br />
  134. <button class="btn btn-default" @click="showModalPointsSale = true">Configurer</button>
  135. </span>
  136. </div>
  137. </div>
  138. </div>
  139. <modal v-if="showModalPointsSale" id="modal-points-sale" @close="showModalPointsSale = false">
  140. <h3 slot="header">Points de vente</h3>
  141. <div slot="body">
  142. <table class="table table-condensed table-bordered table-hover">
  143. <thead>
  144. <tr>
  145. <td>Actif</td>
  146. <td>Nom</td>
  147. </tr>
  148. </thead>
  149. <tbody>
  150. <tr v-for="pointSale in pointsSale">
  151. <td>
  152. <button class="btn btn-success" v-if="pointSale.pointSaleDistribution[0].delivery == 1"><span class="glyphicon glyphicon-ok"></span></button>
  153. <button class="btn btn-default" v-else data-delivery-point-sale="1" :data-id-point-sale="pointSale.id" @click="pointSaleActiveClick"><span class="glyphicon glyphicon-ok"></span></button>
  154. <button class="btn btn-danger" v-if="pointSale.pointSaleDistribution[0].delivery == 0"><span class="glyphicon glyphicon-remove"></span></button>
  155. <button class="btn btn-default" v-else data-delivery-point-sale="0" :data-id-point-sale="pointSale.id" @click="pointSaleActiveClick"><span class="glyphicon glyphicon-remove"></span></button>
  156. </td>
  157. <td>{{ pointSale.name }}</td>
  158. </tr>
  159. </tbody>
  160. </table>
  161. </div>
  162. </modal>
  163. <div class="col-md-6">
  164. <div id="summary-ca-weight" class="info-box col-md-4">
  165. <span class="info-box-icon bg-yellow"><i class="fa fa-euro"></i></span>
  166. <div class="info-box-content">
  167. <span class="info-box-text">CA (TTC)</span>
  168. <span class="info-box-number">{{ distribution.revenues }} <span class="normal" v-if="distribution.potential_revenues != '0,00 €'">/ {{ distribution.potential_revenues }}</span></span>
  169. <span class="info-box-text">Poids</span>
  170. <span class="info-box-number">{{ distribution.weight }} kg <span class="normal" v-if="distribution.potential_weight > 0">/ {{ distribution.potential_weight }} kg</span></span>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="col-md-6">
  175. <div class="info-box col-md-4">
  176. <span class="info-box-icon bg-yellow"><i class="fa fa-download"></i></span>
  177. <div class="info-box-content">
  178. <span class="info-box-text">
  179. {{ countOrders }} Commande<span v-if="countOrders > 1">s</span><br />
  180. <a :href="distribution.url_report" class="btn btn-xs btn-default" v-if="countOrders > 0">Liste (PDF)</a>
  181. <a :href="distribution.url_report+'&type=csv'" class="btn btn-xs btn-default" v-if="countOrders > 0">Tableau (CSV)</a>
  182. <br v-if="producer.option_display_export_grid && countOrders > 0" />
  183. <a :href="distribution.url_report_grid" class="btn btn-xs btn-default" v-if="producer.option_display_export_grid && countOrders > 0">Grille (PDF)</a>
  184. </span>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="callout callout-info" v-else>
  191. <h4><i class="fa fa-info"></i> Pour commencer</h4>
  192. <p>Veuillez choisir une date de distribution.</p>
  193. </div>
  194. </div>
  195. <div class="clr"></div>
  196. <div id="orders" class="panel panel-default" v-if="date">
  197. <div class="panel-heading">
  198. <h3 class="panel-title">Commandes <label class="label label-success" v-if="orders.length">{{ orders.length }}</label><label class="label label-danger" v-else>0</label></h3>
  199. <div class="buttons">
  200. </div>
  201. </div>
  202. <div class="panel-body">
  203. <order-form
  204. v-if="showModalFormOrderCreate"
  205. :date="date"
  206. :order="orderCreate"
  207. :points-sale="pointsSale"
  208. :means-payment="meansPayment"
  209. :users="users"
  210. :products="products"
  211. :producer="producer"
  212. @close="showModalFormOrderCreate = false"
  213. @ordercreatedupdated="orderCreatedUpdated"
  214. @updateproductorderprices="updateProductOrderPrices"
  215. ></order-form>
  216. <div id="wrapper-nav-points-sale">
  217. <ul id="nav-points-sale">
  218. <li data-id-point-sale="0" data-id-point-sale="0" v-if="countActivePointsSale > 1" @click="pointSaleClick">
  219. <a class="btn btn-default btn-primary" v-if="idActivePointSale == 0">Tous <span class="label label-default">{{ orders.length }}</span> <span class="glyphicon glyphicon-triangle-bottom"></span></a>
  220. <a class="btn btn-default" v-else>Tous <span class="label label-default">{{ orders.length }}</span><span class="glyphicon glyphicon-triangle-bottom"></span></a>
  221. </li>
  222. <li v-for="pointSale in pointsSale" :data-id-point-sale="pointSale.id" v-if="pointSale.pointSaleDistribution[0].delivery == 1" @click="pointSaleClick">
  223. <a class="btn btn-default btn-primary" v-if="idActivePointSale == pointSale.id">{{ pointSale.name }} <span class="label label-default">{{ countOrdersByPointSale[pointSale.id] }}</span><span class="glyphicon glyphicon-triangle-bottom"></span></a>
  224. <a class="btn btn-default" v-else>{{ pointSale.name }} <span class="label label-default">{{ countOrdersByPointSale[pointSale.id] }}</span><span class="glyphicon glyphicon-triangle-bottom"></span></a>
  225. </li>
  226. </ul>
  227. <div class="clr"></div>
  228. </div>
  229. <div id="buttons-top-orders">
  230. <div class="right">
  231. <div class="dropdown">
  232. <button class="btn btn-default btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  233. <span class="glyphicon glyphicon-file"></span> Documents
  234. <span class="caret"></span>
  235. </button>
  236. <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
  237. <li><a v-if="idActivePointSale > 0" @click="generateDeliveryNote" href="javascript:void(0);" >Générer un bon de livraison pour ce point de vente</a></li>
  238. <li><a @click="generateDeliveryNoteEachUser" href="javascript:void(0);">Générer un bon de livraison pour chaque client</a></li>
  239. <li><a @click="validateDeliveryNotes" href="javascript:void(0);">Valider les bons de livraisons</a></li>
  240. </ul>
  241. </div>
  242. <button id="btn-add-subscriptions" @click="addSubscriptions" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-plus"></span> Importer les abonnements</button>
  243. <template v-if="producer.tiller == true">
  244. <button v-if="tillerIsSynchro" id="btn-tiller" class="btn btn-success btn-xs" disabled><span class="glyphicon glyphicon-refresh"></span> Synchronisé avec Tiller</button>
  245. <button v-else id="btn-tiller" class="btn btn-xs btn-default" @click="synchroTiller"><span class="glyphicon glyphicon-refresh"></span> Synchroniser avec Tiller</button>
  246. </template>
  247. <button v-if="producer.credit" id="btn-pay-orders" class="btn btn-default btn-xs" @click="payOrders"><span class="glyphicon glyphicon-euro"></span> Payer les commandes</button>
  248. <button id="btn-add-order" @click="openModalFormOrderCreate" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-plus"></span> Ajouter une commande</button>
  249. </div>
  250. <div class="left">
  251. <a v-if="false && deliveryNoteExist(idActivePointSale)" :href="UrlManager.getBaseUrl()+'delivery-note/update?id='+deliveryNotes[idActivePointSale].id" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-file"></span> Bon de livraison</a>
  252. </div>
  253. <div class="clr"></div>
  254. </div>
  255. <div class="alert alert-danger" v-if="missingSubscriptions && missingSubscriptions.length > 0">
  256. {{ missingSubscriptions.length }} abonnement<template v-if="missingSubscriptions.length > 1">s</template> manquant<template v-if="missingSubscriptions.length > 1">s</template> :
  257. <ul>
  258. <li v-for="subscription in missingSubscriptions">{{ subscription.username }}</li>
  259. </ul>
  260. </div>
  261. <div class="alert alert-danger" v-if="distribution && !distribution.active && orders && orders.length > 0">
  262. Attention, ce jour de distribution n'est pas activé et vous avez quand même des commandes enregistrées.
  263. </div>
  264. <table class="table table-condensed table-bordered table-hover" v-if="countOrdersByPointSale[idActivePointSale] > 0 || (idActivePointSale == 0 && orders.length > 0)">
  265. <thead>
  266. <tr>
  267. <th class="column-checkbox" v-if="idActivePointSale > 0">
  268. <input type="checkbox" v-model="checkboxSelectAllOrders" @change="selectAllOrdersEvent" />
  269. </th>
  270. <th class="column-origin">Origine</th>
  271. <th class="column-state">État</th>
  272. <th class="column-user">Utilisateur</th>
  273. <th class="column-point-sale" v-if="idActivePointSale == 0">Point de vente</th>
  274. <th class="column-amount">Montant</th>
  275. <th class="column-state-payment">Paiement</th>
  276. <th class="column-payment"></th>
  277. <th class="column-tiller" v-if="producer.tiller">Tiller</th>
  278. <th class="column-actions"></th>
  279. <th class="column-delivery-note"></th>
  280. </tr>
  281. </thead>
  282. <tbody>
  283. <template v-for="(order, key, index) in orders" v-if="idActivePointSale == 0 || idActivePointSale == order.id_point_sale">
  284. <tr>
  285. <td class="column-checkbox" v-if="idActivePointSale > 0">
  286. <input type="checkbox" v-model="order.selected" />
  287. </td>
  288. <td class="column-origin">
  289. <label class="label label-success" v-if="order.origin == 'user'">client</label>
  290. <label class="label label-default" v-else-if="order.origin == 'auto'">auto</label>
  291. <label class="label label-warning" v-else>admin</label>
  292. </td>
  293. <td class="column-state">
  294. <span class="label label-danger" v-if="order.date_delete"><span class="glyphicon glyphicon-trash"></span></span>
  295. <span class="label label-warning" v-if="order.date_update"><span class="glyphicon glyphicon-pencil"></span></span>
  296. <span class="label label-success" v-if="!order.date_update && !order.date_delete"><span class="glyphicon glyphicon-check"></span></span>
  297. </td>
  298. <td class="column-user">
  299. <span v-if="order.user">
  300. <template v-if="order.user.name_legal_person && order.user.name_legal_person.length">
  301. {{ order.user.name_legal_person }}
  302. </template>
  303. <template v-else>
  304. {{ order.user.lastname+' '+order.user.name }}
  305. </template>
  306. </span>
  307. <span v-else>{{ order.username }}</span>
  308. <span v-if="order.comment && order.comment.length > 0" class="glyphicon glyphicon-comment"></span>
  309. <span v-if="order.delivery_home && order.delivery_address && order.delivery_address.length > 0" class="glyphicon glyphicon-home"></span>
  310. </td>
  311. <td class="column-point-sale" v-if="idActivePointSale == 0">
  312. {{ order.pointSale.name }}
  313. </td>
  314. <td class="column-amount">{{ order.amount.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+'&nbsp;€' }}</td>
  315. <td class="column-state-payment">
  316. <div class="input-group">
  317. <span class="label label-success input-group-addon" v-if="order.amount_paid == order.amount">payé</span>
  318. <span class="label label-default input-group-addon" v-else-if="order.amount_paid == 0">non réglé</span>
  319. <span class="label label-default input-group-addon" v-else-if="order.amount_paid > order.amount">surplus</span>
  320. <span class="label label-warning input-group-addon" v-else-if="order.amount_paid < order.amount">reste à payer</span>
  321. <span class="glyphicon glyphicon-time" title="Paiement automatique" v-if="order.auto_payment && producer.credit && (order.amount_paid == 0 || order.amount_paid < order.amount)"></span>
  322. </div>
  323. </td>
  324. <td class="column-payment" v-if="producer.credit">
  325. <div class="btn-group" v-if="order.user && !order.date_delete">
  326. <button class="btn btn-xs btn-default" v-if="order.amount_paid == order.amount" @click="orderPaymentClick" :data-id-order="order.id" data-type="refund" :data-amount="order.amount">
  327. <span class="glyphicon glyphicon-euro"></span> Rembourser
  328. </button>
  329. <button class="btn btn-xs btn-default" v-else-if="order.amount_paid == 0" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" :data-amount="order.amount">
  330. <span class="glyphicon glyphicon-euro"></span> Payer
  331. </button>
  332. <button class="btn btn-xs btn-default" v-else-if="order.amount_paid < order.amount" @click="orderPaymentClick" :data-id-order="order.id" data-type="payment" :data-amount="order.amount_remaining">
  333. <span class="glyphicon glyphicon-euro"></span> Payer
  334. </button>
  335. <button class="btn btn-xs btn-default" v-else-if="order.amount_paid > order.amount" @click="orderPaymentClick" :data-id-order="order.id" data-type="refund" :data-amount="order.amount_surplus">
  336. <span class="glyphicon glyphicon-euro"></span> Rembourser
  337. </button>
  338. <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  339. <span class="caret"></span>
  340. <span class="sr-only">Toggle Dropdown</span>
  341. </button>
  342. <ul class="dropdown-menu">
  343. <li><a href="javascript:void(0);" @click="orderPaymentModalClick" :data-id-order="order.id">Historique</a></li>
  344. </ul>
  345. </div>
  346. </td>
  347. <td v-if="producer.tiller" class="tiller column-tiller">
  348. <input v-if="order.tiller_synchronization == true" type="checkbox" checked="checked" :id="'checkbox-tiller-synchronization-'+order.id" :data-id-order="order.id" @change="changeSynchroTiller" />
  349. <input v-else type="checkbox" :id="'checkbox-tiller-synchronization-'+order.id" :data-id-order="order.id" @change="changeSynchroTiller" />
  350. <label :for="'checkbox-tiller-synchronization-'+order.id">Tiller</label>
  351. </td>
  352. <td class="column-actions">
  353. <span v-if="order.oneProductUnactivated" class="glyphicon glyphicon-warning-sign" title="Contient un produit non activé"></span>
  354. <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  355. Action <span class="caret"></span>
  356. </button>
  357. <ul class="dropdown-menu">
  358. <li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="orderViewClick"><span :class="'glyphicon ' + ((showViewProduct && idOrderView == order.id) ? 'glyphicon-eye-close' : 'glyphicon-eye-open')"></span> Voir</a></li>
  359. <li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="updateOrderClick"><span class="glyphicon glyphicon-pencil"></span> Modifier</a></li>
  360. <li><a href="javascript:void(0);" class="" :data-id-order="order.id" @click="deleteOrderClick"><span class="glyphicon glyphicon-trash"></span> Supprimer</a></li>
  361. <li v-if="order.id_subscription > 0"><a class="" :href="baseUrl+'/subscription/update?id='+order.id_subscription"><span class="glyphicon glyphicon-repeat"></span> Modifier l'abonnement associé</a></li>
  362. <li v-else><a class="add-subscription" :href="baseUrl+'/subscription/create?idOrder='+order.id"><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-repeat"></span>Créer un abonnement sur cette base</a></li>
  363. </ul>
  364. <order-form
  365. v-if="showModalFormOrderUpdate && idOrderUpdate == order.id"
  366. :date="date"
  367. :id-point-sale="idActivePointSale"
  368. :points-sale="pointsSale"
  369. :means-payment="meansPayment"
  370. :users="users"
  371. :products="products"
  372. :order="ordersUpdate[key]"
  373. :producer="producer"
  374. @close="showModalFormOrderUpdate = false"
  375. @ordercreatedupdated="orderCreatedUpdated"
  376. @updateproductorderprices="updateProductOrderPrices"
  377. ></order-form>
  378. <modal v-if="showModalPayment && idOrderPayment == order.id" class="modal-payment" @close="showModalPayment = false">
  379. <h3 slot="header">
  380. Commande du <strong>{{ dateFormat }}</strong> &gt;
  381. <strong><span v-if="order.user">{{ order.user.name +' '+order.user.lastname }}</span>
  382. <span v-else>{{ order.username }}</span></strong>
  383. </h3>
  384. <div slot="body">
  385. <div class="col-md-4">
  386. <div class="info-box">
  387. <span :class="'info-box-icon ' +((order.amount_paid == order.amount) ? 'bg-green' : 'bg-red')"><i class="fa fa-check"></i></span>
  388. <div class="info-box-content">
  389. <span class="info-box-text">Montant</span>
  390. <span class="info-box-number">{{ order.amount.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}</span>
  391. <span class="info-box-text">
  392. Statut<br />
  393. <span class="label label-success" v-if="order.amount_paid == order.amount">payé</span>
  394. <span class="label label-default" v-else-if="order.amount_paid == 0">non réglé</span>
  395. <span class="label label-default" v-else-if="order.amount_paid > order.amount">surplus</span>
  396. <span class="label label-warning" v-else-if="order.amount_paid < order.amount">reste à payer</span>
  397. </span>
  398. </div>
  399. </div>
  400. <div class="info-box">
  401. <span :class="'info-box-icon ' +((order.user.credit > 0) ? 'bg-green' : 'bg-red')"><i class="fa fa-user"></i></span>
  402. <div class="info-box-content">
  403. <span class="info-box-text">Crédit utilisateur</span>
  404. <span class="info-box-number">{{ order.user.credit.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}</span>
  405. </div>
  406. </div>
  407. <button v-if="order.amount_paid == order.amount"
  408. class="btn btn-default"
  409. :data-amount="order.amount"
  410. data-type="refund"
  411. @click="orderPaymentClick" >
  412. <span class="glyphicon glyphicon-chevron-right"></span>
  413. Rembourser {{ order.amount.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}
  414. </button>
  415. <button v-else-if="order.amount_paid == 0"
  416. class="btn btn-default"
  417. :data-amount="order.amount"
  418. data-type="payment"
  419. @click="orderPaymentClick">
  420. <span class="glyphicon glyphicon-chevron-right"></span>
  421. Payer {{ order.amount.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}
  422. </button>
  423. <button v-else-if="order.amount_paid > order.amount"
  424. class="btn btn-default"
  425. :data-amount="order.amount_surplus"
  426. data-type="refund"
  427. @click="orderPaymentClick">
  428. <span class="glyphicon glyphicon-chevron-right"></span>
  429. Rembourser {{ order.amount_surplus.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}
  430. </button>
  431. <button v-else-if="order.amount_paid < order.amount"
  432. class="btn btn-default"
  433. :data-amount="order.amount_remaining"
  434. data-type="payment"
  435. @click="orderPaymentClick">
  436. <span class="glyphicon glyphicon-chevron-right"></span>
  437. Payer le restant {{ order.amount_remaining.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+' €' }}
  438. </button>
  439. </div>
  440. <div class="col-md-8">
  441. <h4>Historique paiement</h4>
  442. <table class="table table-condensed table-bordered table-hover">
  443. <thead>
  444. <tr>
  445. <td>Date</td>
  446. <td>Utilisateur</td>
  447. <td>Action</td>
  448. <td>- Débit</td>
  449. <td>+ Crédit</td>
  450. </tr>
  451. </thead>
  452. <tbody>
  453. <tr v-for="creditHistory in order.creditHistory">
  454. <td>{{ creditHistory.date }}</td>
  455. <td>{{ creditHistory.user_action }}</td>
  456. <td v-html="creditHistory.wording"></td>
  457. <td v-html="creditHistory.debit"></td>
  458. <td v-html="creditHistory.credit"></td>
  459. </tr>
  460. </tbody>
  461. </table>
  462. </div>
  463. </div>
  464. </modal>
  465. </td>
  466. <td class="column-delivery-note">
  467. <a v-if="order.id_delivery_note" class="btn btn-default btn-xs" :href="UrlManager.getBaseUrl()+'delivery-note/update?id='+order.id_delivery_note">
  468. <span class="glyphicon glyphicon-file"></span> BL #{{ order.id_delivery_note }}
  469. </a>
  470. </td>
  471. </tr>
  472. <tr class="view" v-if="showViewProduct && idOrderView == order.id">
  473. <td colspan="6">
  474. <strong><span class="glyphicon glyphicon-menu-right"></span> Produits</strong>
  475. <ul>
  476. <li v-for="product in products" v-if="order.productOrder[product.id].quantity > 0">
  477. {{ product.name }} : {{ order.productOrder[product.id].quantity }} {{ order.productOrder[product.id].unit == 'piece' ? ' pièce(s)' : ' '+order.productOrder[product.id].unit }} <span v-if="product.productDistribution[0].active == 0" class="glyphicon glyphicon-warning-sign" title="Ce produit n'est pas activé"></span>
  478. </li>
  479. </ul>
  480. <div v-if="order.comment && order.comment.length > 0" class="comment">
  481. <strong><span class="glyphicon glyphicon-menu-right"></span> Commentaire</strong><br />
  482. {{ order.comment }}
  483. </div>
  484. <div v-if="order.delivery_home && order.delivery_address && order.delivery_address.length > 0" class="delivery">
  485. <strong><span class="glyphicon glyphicon-menu-right"></span> Livraison à domicile</strong><br />
  486. {{ order.delivery_address }}
  487. </div>
  488. </td>
  489. </tr>
  490. </template>
  491. <tr v-if="idActivePointSale > 0">
  492. <td colspan="4"><strong>Total (TTC)</strong></td>
  493. <td><strong>{{ totalActivePointSale() }}</strong></td>
  494. <td colspan="3"></td>
  495. </tr>
  496. </tbody>
  497. </table>
  498. <div class="alert alert-warning" v-else>
  499. Aucune commande
  500. </div>
  501. </div>
  502. </div>
  503. </div>
  504. </div>
  505. <!-- template for the order-form component -->
  506. <script type="text/x-template" id="order-form-template">
  507. <modal class="modal-form-order" @close="$emit('close')">
  508. <h3 slot="header">Ajouter une commande</h3>
  509. <div slot="body">
  510. <div class="callout callout-warning" v-if="errors.length">
  511. <ul>
  512. <li v-for="error in errors">{{ error }}</li>
  513. </ul>
  514. </div>
  515. <div class="col-md-4">
  516. <div class="form-group">
  517. <a v-if="producer.credit && order.id_user > 0 && user.id_user == order.id_user" class="btn btn-xs btn-primary btn-credit" :href="baseUrl+'/user/credit?id='+user.id_user" v-for="user in users">{{ parseFloat(user.credit).toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")+'&nbsp;€' }}</a>
  518. <label class="control-label" for="select-id-user">
  519. Utilisateur
  520. </label>
  521. <select class="form-control" v-model="order.id_user" @change="userChange">
  522. <option value="0">--</option>
  523. <option v-for="user in users" :value="user.id_user">
  524. <template v-if="user.name_legal_person && user.name_legal_person.length">
  525. Personne morale / {{ user.name_legal_person }}
  526. </template>
  527. <template v-else>
  528. {{ user.lastname +' '+ user.name }}
  529. </template>
  530. </option>
  531. </select>
  532. <input v-model="order.username" type="text" class="form-control" placeholder="Ou saisissez ici le nom de l'utilisateur" />
  533. </div>
  534. <div class="form-group">
  535. <label class="control-label" for="select-id-point-sale">Point de vente</label>
  536. <select class="form-control" id="select-id-point-sale" v-model="order.id_point_sale" @change="pointSaleChange">
  537. <option value="0">--</option>
  538. <option v-for="pointSale in pointsSale" v-if="pointSale.pointSaleDistribution[0].delivery == 1" :value="pointSale.id"">{{ pointSale.name }}</option>
  539. </select>
  540. </div>
  541. <div class="form-group">
  542. <label class="control-label" for="select-mean-payment">Moyen de paiement</label>
  543. <select class="form-control" id="select-mean-payment" v-model="order.mean_payment">
  544. <option value="0">--</option>
  545. <option v-for="(wordingMeanPayment, keyMeanPayment) in meansPayment" :value="keyMeanPayment">{{ wordingMeanPayment }}</option>
  546. </select>
  547. </div>
  548. <div class="form-group">
  549. <label class="control-label" for="textarea-comment">Commentaire</label>
  550. <textarea class="form-control" id="textarea-comment" v-model="order.comment"></textarea>
  551. </div>
  552. </div>
  553. <div class="col-md-8">
  554. <label class="control-label">Produits</label>
  555. <table class="table table-condensed table-bordered table-hover table-products">
  556. <thead>
  557. <tr>
  558. <th></th>
  559. <th>Nom</th>
  560. <th>Prix unitaire</th>
  561. <th>Quantité</th>
  562. <th>Reste</th>
  563. </tr>
  564. </thead>
  565. <tbody>
  566. <tr v-for="product in products" :class="(order.productOrder[product.id] > 0) ? 'product-ordered' : ''">
  567. <td>
  568. <span class="label label-success" v-if="product.productDistribution[0].active == 1">Actif</span>
  569. <span class="label label-danger" v-else>Inactif</span>
  570. </td>
  571. <td>{{ product.name }}</td>
  572. <td class="price">
  573. <div class="input-group">
  574. <input type="text" v-model="order.productOrder[product.id].price" class="form-control" @change="productPriceChange" :data-id-product="product.id" />
  575. <span class="input-group-addon" id="basic-addon2">€ TTC</span>
  576. </div>
  577. </td>
  578. <td class="quantity">
  579. <div class="input-group">
  580. <span class="input-group-btn">
  581. <button class="btn btn-default btn-moins" type="button" @click="productQuantityClick(product.id, order.productOrder[product.id].unit == 'piece' ? -1 : -parseFloat(product.step))"><span class="glyphicon glyphicon-minus"></span></button>
  582. </span>
  583. <input type="text" v-model="order.productOrder[product.id].quantity" class="form-control" />
  584. <span class="input-group-addon">{{ order.productOrder[product.id].unit == 'piece' ? 'p.' : order.productOrder[product.id].unit }}</span>
  585. <span class="input-group-btn">
  586. <button class="btn btn-default btn-plus" type="button" @click="productQuantityClick(product.id, order.productOrder[product.id].unit == 'piece' ? 1 : parseFloat(product.step))"><span class="glyphicon glyphicon-plus"></span></button>
  587. </span>
  588. </div>
  589. </td>
  590. <td class="quantity-remaining infinite" v-if="product.quantity_remaining === null || order.productOrder[product.id].unit != product.unit">&infin;</td>
  591. <td class="quantity-remaining negative" v-else-if="product.quantity_remaining <= 0">{{ product.quantity_remaining }} {{ order.productOrder[product.id].unit == 'piece' ? ' p.' : ' '+(order.productOrder[product.id].unit == 'g' || order.productOrder[product.id].unit == 'kg') ? 'kg' : 'litre(s)' }}</td>
  592. <td class="quantity-remaining has-quantity" v-else>{{ product.quantity_remaining }} {{ order.productOrder[product.id].unit == 'piece' ? ' p.' : ' '+(order.productOrder[product.id].unit == 'g' || order.productOrder[product.id].unit == 'kg') ? 'kg' : 'litre(s)' }}</td>
  593. </tr>
  594. </tbody>
  595. </table>
  596. </div>
  597. </div>
  598. <div slot="footer">
  599. <div class="actions-form">
  600. <button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-if="!order.id && order.id_user > 0" data-process-credit="1">Créer et payer</button>
  601. <button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id && order.id_user > 0" data-process-credit="1">Modifier et payer</button>
  602. <button class="modal-default-button btn btn-primary" @click="submitFormUpdate" v-if="order.id">Modifier</button>
  603. <button class="modal-default-button btn btn-primary" @click="submitFormCreate" v-else>Créer</button>
  604. <button class="modal-default-button btn btn-default" @click="$emit('close')">Annuler</button>
  605. </div>
  606. </div>
  607. </modal>
  608. </script>
  609. <!-- template for the modal component -->
  610. <script type="text/x-template" id="modal-template">
  611. <transition name="modal">
  612. <div class="modal-mask">
  613. <div class="modal-wrapper">
  614. <div class="modal-container">
  615. <div class="modal-header">
  616. <slot name="header"></slot>
  617. </div>
  618. <div class="modal-body">
  619. <slot name="body"></slot>
  620. </div>
  621. <div class="modal-footer">
  622. <slot name="footer">
  623. <button class="modal-default-button btn btn-default" @click="$emit('close')">Fermer</button>
  624. </slot>
  625. </div>
  626. </div>
  627. </div>
  628. </div>
  629. </transition>
  630. </script>