Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

OrderReferenceResolver.php 2.5KB

3 роки тому
3 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace Lc\CaracoleBundle\Resolver\Reference;
  3. use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Model\Section\SectionModel;
  6. class OrderReferenceResolver
  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. }