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.

80 Zeilen
2.8KB

  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, \DateTimeInterface $distributionDate = null): string
  15. {
  16. switch ($orderShop->getSection()->getCycleType()) {
  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, \DateTimeInterface $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(
  41. OrderShopInterface $orderShop,
  42. \DateTimeInterface $distributionDate
  43. ): string {
  44. return $this->getPrefixReference($orderShop) .
  45. 'M' . $distributionDate->format('m') .
  46. 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
  47. 'A' . $distributionDate->format('y');
  48. }
  49. public function buildReferenceCycleYear(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate): string
  50. {
  51. return $this->getPrefixReference($orderShop) .
  52. 'C' . $this->numberPad($orderShop->getCycleId(), 5) .
  53. 'A' . $distributionDate->format('y');
  54. }
  55. public function getPrefixReference(OrderShopInterface $orderShop): string
  56. {
  57. return ''.$this->settingSolver->getSettingValue(
  58. $orderShop->getSection(),
  59. SectionSettingDefinition::SETTING_REFERENCE_PREFIX
  60. );
  61. }
  62. public function numberPad($number, $length): string
  63. {
  64. return str_pad($number, $length, "0", STR_PAD_LEFT);
  65. }
  66. }