選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Order.php 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  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. namespace common\models;
  38. use Yii;
  39. use yii\helpers\Html;
  40. use common\models\Producer;
  41. use common\components\ActiveRecordCommon;
  42. /**
  43. * This is the model class for table "order".
  44. *
  45. * @property integer $id
  46. * @property integer $id_user
  47. * @property string $date
  48. * @property string $date_update
  49. * @property integer $id_point_sale
  50. * @property integer $id_distribution
  51. * @property boolean $auto_payment
  52. * @property integer $id_subscription
  53. */
  54. class Order extends ActiveRecordCommon
  55. {
  56. var $amount = 0;
  57. var $paid_amount = 0;
  58. var $weight = 0;
  59. const ORIGIN_AUTO = 'auto';
  60. const ORIGIN_USER = 'user';
  61. const ORIGIN_ADMIN = 'admin';
  62. const PAYMENT_PAID = 'paid';
  63. const PAYMENT_UNPAID = 'unpaid';
  64. const PAYMENT_SURPLUS = 'surplus';
  65. const AMOUNT_TOTAL = 'total';
  66. const AMOUNT_PAID = 'paid';
  67. const AMOUNT_REMAINING = 'remaining';
  68. const AMOUNT_SURPLUS = 'surplus';
  69. const STATE_OPEN = 'open';
  70. const STATE_PREPARATION = 'preparation';
  71. const STATE_DELIVERED = 'delivered';
  72. /**
  73. * @inheritdoc
  74. */
  75. public static function tableName()
  76. {
  77. return 'order';
  78. }
  79. /**
  80. * @inheritdoc
  81. */
  82. public function rules()
  83. {
  84. return [
  85. [['id_user', 'date'], 'required', 'message' => ''],
  86. [['id_user', 'id_point_sale', 'id_distribution', 'id_subscription', 'id_invoice', 'id_quotation', 'id_delivery_note'], 'integer'],
  87. [['auto_payment', 'tiller_synchronization'], 'boolean'],
  88. [['date', 'date_update', 'comment', 'comment_point_sale', 'mean_payment'], 'safe']
  89. ];
  90. }
  91. /**
  92. * @inheritdoc
  93. */
  94. public function attributeLabels()
  95. {
  96. return [
  97. 'id' => 'ID',
  98. 'id_user' => 'Id User',
  99. 'date' => 'Date',
  100. 'date_update' => 'Date de modification',
  101. 'id_point_sale' => 'Point de vente',
  102. 'id_distribution' => 'Date de distribution',
  103. 'id_subscription' => 'Abonnement',
  104. 'id_invoice' => 'Facture',
  105. 'id_quotation' => 'Devis',
  106. 'id_delivery_note' => 'Bon de livraison'
  107. ];
  108. }
  109. /*
  110. * Relations
  111. */
  112. public function getUser()
  113. {
  114. return $this->hasOne(User::className(), ['id' => 'id_user']);
  115. }
  116. public function getProductOrder()
  117. {
  118. return $this->hasMany(ProductOrder::className(), ['id_order' => 'id'])
  119. ->with('product');
  120. }
  121. public function getDistribution()
  122. {
  123. return $this->hasOne(Distribution::className(), ['id' => 'id_distribution'])
  124. ->with('producer');
  125. }
  126. public function getPointSale()
  127. {
  128. return $this->hasOne(PointSale::className(), ['id' => 'id_point_sale'])
  129. ->with('userPointSale');
  130. }
  131. public function getCreditHistory()
  132. {
  133. return $this->hasMany(CreditHistory::className(), ['id_order' => 'id']);
  134. }
  135. public function getSubscription()
  136. {
  137. return $this->hasOne(Subscription::className(), ['id' => 'id_subscription'])
  138. ->with('productSubscription');
  139. }
  140. public function getOrderOrderStatus()
  141. {
  142. return $this->hasMany(OrderOrderStatus::className(), ['id_order' => 'id'])->with('orderStatus');
  143. }
  144. public function getInvoice()
  145. {
  146. return $this->hasOne(Invoice::className(), ['id' => 'id_invoice']);
  147. }
  148. public function getQuotation()
  149. {
  150. return $this->hasOne(Quotation::className(), ['id' => 'id_quotation']);
  151. }
  152. public function getDeliveryNote()
  153. {
  154. return $this->hasOne(DeliveryNote::className(), ['id' => 'id_delivery_note']);
  155. }
  156. /**
  157. * Retourne les options de base nécessaires à la fonction de recherche.
  158. *
  159. * @return array
  160. */
  161. public static function defaultOptionsSearch()
  162. {
  163. return [
  164. 'with' => ['productOrder', 'productOrder.product', 'creditHistory', 'creditHistory.userAction', 'pointSale'],
  165. 'join_with' => ['distribution', 'user', 'user.userProducer'],
  166. 'orderby' => 'order.date ASC',
  167. 'attribute_id_producer' => 'distribution.id_producer'
  168. ];
  169. }
  170. /**
  171. * Initialise le montant total, le montant déjà payé et le poids de la
  172. * commande.
  173. */
  174. public function init()
  175. {
  176. $this->initAmount();
  177. $this->initPaidAmount();
  178. return $this;
  179. }
  180. /**
  181. * Initialise le montant de la commande.
  182. *
  183. */
  184. public function initAmount()
  185. {
  186. $this->amount = 0 ;
  187. $this->weight = 0 ;
  188. if (isset($this->productOrder)) {
  189. foreach ($this->productOrder as $productOrder) {
  190. $this->amount += $productOrder->price * $productOrder->quantity;
  191. if ($productOrder->unit == 'piece') {
  192. if (isset($productOrder->product)) {
  193. $this->weight += ($productOrder->quantity * $productOrder->product->weight) / 1000;
  194. }
  195. } else {
  196. $this->weight += $productOrder->quantity;
  197. }
  198. }
  199. }
  200. }
  201. /**
  202. * Initialise le montant payé de la commande et le retourne.
  203. *
  204. * @return float
  205. */
  206. public function initPaidAmount()
  207. {
  208. if (isset($this->creditHistory)) {
  209. $history = $this->creditHistory;
  210. } else {
  211. $history = CreditHistory::find()
  212. ->where(['id_order' => $this->id])
  213. ->all();
  214. }
  215. $this->paid_amount = 0;
  216. if (count($history)) {
  217. foreach ($history as $ch) {
  218. if ($ch->type == CreditHistory::TYPE_PAYMENT) {
  219. $this->paid_amount += $ch->amount;
  220. } elseif ($ch->type == CreditHistory::TYPE_REFUND) {
  221. $this->paid_amount -= $ch->amount;
  222. }
  223. }
  224. }
  225. }
  226. public function delete()
  227. {
  228. // remboursement si l'utilisateur a payé pour cette commande
  229. $amountPaid = $this->getAmount(Order::AMOUNT_PAID);
  230. if ($amountPaid > 0.01) {
  231. $this->saveCreditHistory(
  232. CreditHistory::TYPE_REFUND,
  233. $amountPaid,
  234. GlobalParam::getCurrentProducerId(),
  235. $this->id_user,
  236. User::getCurrentId()
  237. );
  238. }
  239. // delete
  240. if (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_DELETE ||
  241. (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS && strlen($this->date_delete))) {
  242. ProductOrder::deleteAll(['id_order' => $this->id]);
  243. return parent::delete();
  244. } // status 'delete'
  245. elseif (Producer::getConfig('option_behavior_cancel_order') == Producer::BEHAVIOR_DELETE_ORDER_STATUS) {
  246. $this->date_delete = date('Y-m-d H:i:s');
  247. return $this->save();
  248. }
  249. }
  250. /**
  251. * Retourne le montant de la commande (total, payé, restant, ou en surplus).
  252. *
  253. * @param boolean $format
  254. * @return float
  255. */
  256. public function getAmount($type = self::AMOUNT_TOTAL, $format = false)
  257. {
  258. switch ($type) {
  259. case self::AMOUNT_TOTAL :
  260. $amount = $this->amount;
  261. break;
  262. case self::AMOUNT_PAID :
  263. $this->initPaidAmount();
  264. $amount = $this->paid_amount;
  265. break;
  266. case self::AMOUNT_REMAINING :
  267. $amount = $this->getAmount(self::AMOUNT_TOTAL)
  268. - $this->getAmount(self::AMOUNT_PAID);
  269. break;
  270. case self::AMOUNT_SURPLUS :
  271. $amount = $this->getAmount(self::AMOUNT_PAID)
  272. - $this->getAmount(self::AMOUNT_TOTAL);
  273. break;
  274. }
  275. if ($format) {
  276. return number_format($amount, 2) . ' €';
  277. } else {
  278. return $amount;
  279. }
  280. }
  281. /**
  282. * Retourne les informations relatives à la commande au format JSON.
  283. *
  284. * @return string
  285. */
  286. public function getDataJson()
  287. {
  288. $order = Order::searchOne(['order.id' => $this->id]);
  289. $jsonOrder = [];
  290. if ($order) {
  291. $jsonOrder = [
  292. 'products' => [],
  293. 'amount' => $order->amount,
  294. 'str_amount' => $order->getAmount(self::AMOUNT_TOTAL, true),
  295. 'paid_amount' => $order->getAmount(self::AMOUNT_PAID),
  296. 'comment' => $order->comment,
  297. ];
  298. foreach ($order->productOrder as $productOrder) {
  299. $jsonOrder['products'][$productOrder->id_product] = $productOrder->quantity;
  300. }
  301. }
  302. return json_encode($jsonOrder);
  303. }
  304. /**
  305. * Enregistre un modèle de type CreditHistory.
  306. *
  307. * @param string $type
  308. * @param float $montant
  309. * @param integer $idProducer
  310. * @param integer $idUser
  311. * @param integer $idUserAction
  312. */
  313. public function saveCreditHistory($type, $amount, $idProducer, $idUser, $idUserAction)
  314. {
  315. $creditHistory = new CreditHistory;
  316. $creditHistory->id_user = $this->id_user;
  317. $creditHistory->id_order = $this->id;
  318. $creditHistory->amount = $amount;
  319. $creditHistory->type = $type;
  320. $creditHistory->id_producer = $idProducer;
  321. $creditHistory->id_user_action = $idUserAction;
  322. $creditHistory->populateRelation('order', $this);
  323. $creditHistory->populateRelation('user', User::find()->where(['id' => $this->id_user])->one());
  324. $creditHistory->save();
  325. }
  326. /**
  327. * Ajuste le crédit pour que la commande soit payée.
  328. *
  329. * @return boolean
  330. */
  331. public function processCredit()
  332. {
  333. if ($this->id_user) {
  334. $paymentStatus = $this->getPaymentStatus();
  335. if ($paymentStatus == self::PAYMENT_PAID) {
  336. return true;
  337. } elseif ($paymentStatus == self::PAYMENT_SURPLUS) {
  338. $type = CreditHistory::TYPE_REFUND;
  339. $amount = $this->getAmount(self::AMOUNT_SURPLUS);
  340. } elseif ($paymentStatus == self::PAYMENT_UNPAID) {
  341. $type = CreditHistory::TYPE_PAYMENT;
  342. $amount = $this->getAmount(self::AMOUNT_REMAINING);
  343. }
  344. $this->saveCreditHistory(
  345. $type,
  346. $amount,
  347. GlobalParam::getCurrentProducerId(),
  348. $this->id_user,
  349. User::getCurrentId()
  350. );
  351. }
  352. }
  353. /**
  354. * Retourne le statut de paiement de la commande (payée, surplus, ou impayée).
  355. *
  356. * @return string
  357. */
  358. public function getPaymentStatus()
  359. {
  360. // payé
  361. if ($this->getAmount() - $this->getAmount(self::AMOUNT_PAID) < 0.01 &&
  362. $this->getAmount() - $this->getAmount(self::AMOUNT_PAID) > -0.01) {
  363. return self::PAYMENT_PAID;
  364. } // à rembourser
  365. elseif ($this->getAmount() - $this->getAmount(self::AMOUNT_PAID) <= -0.01) {
  366. return self::PAYMENT_SURPLUS;
  367. } // reste à payer
  368. elseif ($this->getAmount() - $this->getAmount(self::AMOUNT_PAID) >= 0.01) {
  369. return self::PAYMENT_UNPAID;
  370. }
  371. }
  372. /**
  373. * Retourne le résumé du panier au format HTML.
  374. *
  375. * @return string
  376. */
  377. public function getCartSummary()
  378. {
  379. if (!isset($this->productOrder)) {
  380. $this->productOrder = productOrder::find()->where(['id_order' => $this->id])->all();
  381. }
  382. $html = '';
  383. $count = count($this->productOrder);
  384. $i = 0;
  385. foreach ($this->productOrder as $p) {
  386. if (isset($p->product)) {
  387. $html .= Html::encode($p->product->name) . ' (' . $p->quantity . '&nbsp;' . Product::strUnit($p->unit, 'wording_short', true) . ')';
  388. if (++$i != $count) {
  389. $html .= '<br />';
  390. }
  391. }
  392. }
  393. return $html;
  394. }
  395. /**
  396. * Retourne le résumé du point de vente lié à la commande au format HTML.
  397. *
  398. * @return string
  399. */
  400. public function getPointSaleSummary()
  401. {
  402. $html = '';
  403. if (isset($this->pointSale)) {
  404. $html .= '<span class="name-point-sale">' .
  405. Html::encode($this->pointSale->name) .
  406. '</span>' .
  407. '<br /><span class="locality">'
  408. . Html::encode($this->pointSale->locality)
  409. . '</span>';
  410. if (strlen($this->comment_point_sale)) {
  411. $html .= '<div class="comment"><span>'
  412. . Html::encode($this->comment_point_sale)
  413. . '</span></div>';
  414. }
  415. } else {
  416. $html .= 'Point de vente supprimé';
  417. }
  418. return $html;
  419. }
  420. /**
  421. * Retourne le résumé du paiement (montant, statut).
  422. *
  423. * @return string
  424. */
  425. public function getAmountSummary()
  426. {
  427. $html = '';
  428. $html .= $this->getAmount(self::AMOUNT_TOTAL, true) . '<br />';
  429. if ($this->paid_amount) {
  430. if ($this->getPaymentStatus() == Order::PAYMENT_PAID) {
  431. $html .= '<span class="label label-success">Payée</span>';
  432. } elseif ($this->getPaymentStatus() == Order::PAYMENT_UNPAID) {
  433. $html .= '<span class="label label-danger">Non payée</span><br />
  434. Reste <strong>' . $this->getAmount(Order::AMOUNT_REMAINING, true) . '</strong> à payer';
  435. } elseif ($this->getPaymentStatus() == Order::PAYMENT_SURPLUS) {
  436. $html .= '<span class="label label-success">Payée</span>';
  437. }
  438. } else {
  439. $html .= '<span class="label label-default">Non réglé</span>';
  440. }
  441. return $html;
  442. }
  443. /**
  444. * Retourne une chaine de caractère décrivant l'utilisateur lié à la commande.
  445. *
  446. * @return string
  447. */
  448. public function getStrUser()
  449. {
  450. if (isset($this->user)) {
  451. return Html::encode($this->user->lastname . ' ' . $this->user->name);
  452. } elseif (strlen($this->username)) {
  453. return Html::encode($this->username);
  454. } else {
  455. return 'Client introuvable';
  456. }
  457. }
  458. /**
  459. * Retourne l'état de la commande (livrée, modifiable ou en préparation)
  460. *
  461. * @return string
  462. */
  463. public function getState()
  464. {
  465. $orderDelay = Producer::getConfig(
  466. 'order_delay',
  467. $this->distribution->id_producer
  468. );
  469. $orderDeadline = Producer::getConfig(
  470. 'order_deadline',
  471. $this->distribution->id_producer
  472. );
  473. $orderDate = strtotime($this->distribution->date);
  474. $today = strtotime(date('Y-m-d'));
  475. $todayHour = date('G');
  476. $nbDays = (int)(($orderDate - $today) / (24 * 60 * 60));
  477. if ($nbDays <= 0) {
  478. return self::STATE_DELIVERED;
  479. } elseif ($nbDays >= $orderDelay &&
  480. ($nbDays != $orderDelay ||
  481. ($nbDays == $orderDelay && $todayHour < $orderDeadline))) {
  482. return self::STATE_OPEN;
  483. }
  484. return self::STATE_PREPARATION;
  485. }
  486. /**
  487. * Retourne l'origine de la commande (client, automatique ou admin) sous forme
  488. * texte ou HTML.
  489. *
  490. * @param boolean $with_label
  491. * @return string
  492. */
  493. public function getStrOrigin($withLabel = false)
  494. {
  495. $classLabel = '';
  496. $str = '';
  497. if ($this->origin == self::ORIGIN_USER) {
  498. $classLabel = 'success';
  499. $str = 'Client';
  500. } elseif ($this->origin == self::ORIGIN_AUTO) {
  501. $classLabel = 'default';
  502. $str = 'Auto';
  503. } elseif ($this->origin == self::ORIGIN_ADMIN) {
  504. $classLabel = 'warning';
  505. $str = 'Vous';
  506. }
  507. if ($withLabel) {
  508. return '<span class="label label-' . $classLabel . '">'
  509. . $str . '</span>';
  510. } else {
  511. return $str;
  512. }
  513. }
  514. /**
  515. * Retourne l'historique de la commande (ajoutée, modifiée, supprimée) au
  516. * format HTML.
  517. *
  518. * @return string
  519. */
  520. public function getStrHistory()
  521. {
  522. $arr = [
  523. 'class' => 'create',
  524. 'glyphicon' => 'plus',
  525. 'str' => 'Ajoutée',
  526. 'date' => $this->date
  527. ];
  528. if (!is_null($this->date_update)) {
  529. $arr = [
  530. 'class' => 'update',
  531. 'glyphicon' => 'pencil',
  532. 'str' => 'Modifiée',
  533. 'date' => $this->date_update
  534. ];
  535. }
  536. if (!is_null($this->date_delete)) {
  537. $arr = [
  538. 'class' => 'delete',
  539. 'glyphicon' => 'remove',
  540. 'str' => 'Annulée',
  541. 'date' => $this->date_delete
  542. ];
  543. }
  544. $html = '<div class="small"><span class="' . $arr['class'] . '">'
  545. . '<span class="glyphicon glyphicon-' . $arr['glyphicon'] . '"></span> '
  546. . $arr['str'] . '</span> le <strong>'
  547. . date('d/m/Y à G\hi', strtotime($arr['date'])) . '</strong></div>';
  548. return $html;
  549. }
  550. /**
  551. * Retourne une classe identifiant l'historique de la commande (ajoutée,
  552. * modifiée, supprimée).
  553. *
  554. * @return string
  555. */
  556. public function getClassHistory()
  557. {
  558. if (!is_null($this->date_delete)) {
  559. return 'commande-delete';
  560. }
  561. if (!is_null($this->date_update)) {
  562. return 'commande-update';
  563. }
  564. return 'commande-create';
  565. }
  566. /**
  567. * Retourne la quantité d'un produit donné de plusieurs commandes.
  568. *
  569. * @param integer $idProduct
  570. * @param array $orders
  571. * @param boolean $ignoreCancel
  572. *
  573. * @return integer
  574. */
  575. public static function getProductQuantity($idProduct, $orders, $ignoreCancel = false, $unit = null)
  576. {
  577. $quantity = 0;
  578. if (isset($orders) && is_array($orders) && count($orders)) {
  579. foreach ($orders as $c) {
  580. if (is_null($c->date_delete) || $ignoreCancel) {
  581. foreach ($c->productOrder as $po) {
  582. if ($po->id_product == $idProduct &&
  583. ((is_null($unit) && $po->product->unit == $po->unit) || (!is_null($unit) && strlen($unit) && $po->unit == $unit))) {
  584. $quantity += $po->quantity;
  585. }
  586. }
  587. }
  588. }
  589. }
  590. return $quantity;
  591. }
  592. /**
  593. * Recherche et initialise des commandes.
  594. *
  595. * @param array $params
  596. * @param array $conditions
  597. * @param string $orderby
  598. * @param integer $limit
  599. * @return array
  600. */
  601. public static function searchBy($params = [], $options = [])
  602. {
  603. $orders = parent::searchBy($params, $options);
  604. /*
  605. * Initialisation des commandes
  606. */
  607. if (is_array($orders)) {
  608. if (count($orders)) {
  609. foreach ($orders as $order) {
  610. if (is_a($order, 'common\models\Order')) {
  611. $order->init();
  612. }
  613. }
  614. return $orders;
  615. }
  616. } else {
  617. $order = $orders;
  618. if (is_a($order, 'common\models\Order')) {
  619. return $order->init();
  620. } // count
  621. else {
  622. return $order;
  623. }
  624. }
  625. return false;
  626. }
  627. /**
  628. * Retourne le nombre de produits commandés
  629. *
  630. * @return integer
  631. */
  632. public function countProducts()
  633. {
  634. $count = 0;
  635. if ($this->productOrder && is_array($this->productOrder)) {
  636. foreach ($this->productOrder as $productOrder) {
  637. if ($productOrder->unit == 'piece') {
  638. $count++;
  639. } else {
  640. $count += $productOrder->quantity;
  641. }
  642. }
  643. }
  644. return $count;
  645. }
  646. /**
  647. * Retourne un bloc html présentant une date.
  648. *
  649. * @return string
  650. */
  651. public function getBlockDate()
  652. {
  653. return '<div class="block-date">
  654. <div class="day">' . strftime('%A', strtotime($this->distribution->date)) . '</div>
  655. <div class="num">' . date('d', strtotime($this->distribution->date)) . '</div>
  656. <div class="month">' . strftime('%B', strtotime($this->distribution->date)) . '</div>
  657. </div>';
  658. }
  659. }