Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

OrderReferenceGenerator.php 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Lc\CaracoleBundle\Generator;
  3. use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Model\Section\SectionModel;
  6. use Lc\SovBundle\Solver\Setting\SettingSolver;
  7. class OrderReferenceGenerator
  8. {
  9. protected SettingSolver $settingSolver;
  10. public function __construct(SettingSolver $settingSolver)
  11. {
  12. $this->settingSolver = $settingSolver;
  13. }
  14. public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string
  15. {
  16. switch ($orderShop->getSection()->getCycle()) {
  17. case SectionModel::CYCLE_TYPE_DAY:
  18. return $this->buildReferenceCycleDay($orderShop);
  19. case SectionModel::CYCLE_TYPE_WEEK:
  20. return $this->buildReferenceCycleWeek($orderShop, $distributionDate);
  21. case SectionModel::CYCLE_TYPE_MONTH:
  22. return $this->buildReferenceCycleMonth($orderShop, $distributionDate);
  23. case SectionModel::CYCLE_TYPE_YEAR:
  24. return $this->buildReferenceCycleYear($orderShop, $distributionDate);
  25. }
  26. return 'C' . $orderShop->getId();
  27. }
  28. public function buildReferenceCycleDay(OrderShopInterface $orderShop): string
  29. {
  30. return $this->getPrefixReference($orderShop) .
  31. 'C' . $this->numberPad($orderShop->getCycleId(), 3);
  32. }
  33. public function buildReferenceCycleWeek(OrderShopInterface $orderShop, \DateTime $distributionDate): string
  34. {
  35. return $this->getPrefixReference($orderShop) .
  36. 'S' . $distributionDate->format('W') .
  37. 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
  38. 'A' . $distributionDate->format('y');
  39. }
  40. public function buildReferenceCycleMonth(OrderShopInterface $orderShop, \DateTime $distributionDate): string
  41. {
  42. return $this->getPrefixReference($orderShop) .
  43. 'M' . $distributionDate->format('m') .
  44. 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
  45. 'A' . $distributionDate->format('y');
  46. }
  47. public function buildReferenceCycleYear(OrderShopInterface $orderShop, \DateTime $distributionDate): string
  48. {
  49. return $this->getPrefixReference($orderShop) .
  50. 'C' . $this->numberPad($orderShop->getCycleId(), 5) .
  51. 'A' . $distributionDate->format('y');
  52. }
  53. public function getPrefixReference(OrderShopInterface $orderShop): string
  54. {
  55. return $this->settingSolver->getSettingValue($orderShop->getSection(), SectionSettingDefinition::SETTING_REFERENCE_PREFIX);
  56. }
  57. public function numberPad($number, $length): string
  58. {
  59. return str_pad($number, $length, "0", STR_PAD_LEFT);
  60. }
  61. }