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.

68 Zeilen
2.5KB

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