|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
-
- namespace Lc\CaracoleBundle\Resolver\Reference;
-
- use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Section\SectionModel;
-
- class OrderReferenceResolver
- {
-
- public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string
- {
- switch ($orderShop->getSection()->getCycle()) {
- case SectionModel::CYCLE_DAY:
- return $this->buildReferenceCycleDay($orderShop);
- case SectionModel::CYCLE_WEEK:
- return $this->buildReferenceCycleWeek($orderShop, $distributionDate);
- case SectionModel::CYCLE_MONTH:
- return $this->buildReferenceCycleMonth($orderShop, $distributionDate);
- case SectionModel::CYCLE_YEAR:
- return $this->buildReferenceCycleYear($orderShop, $distributionDate);
- }
-
- return 'C' . $orderShop->getId();
- }
-
- public function buildReferenceCycleDay(OrderShopInterface $orderShop): string
- {
- return $this->getPrefixReference($orderShop) .
- 'C' . $this->numberPad($orderShop->getCycleId(), 3);
- }
-
- public function buildReferenceCycleWeek(OrderShopInterface $orderShop, \DateTime $distributionDate): string
- {
- return $this->getPrefixReference($orderShop) .
- 'S' . $distributionDate->format('W') .
- 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
- 'A' . $distributionDate->format('y');
- }
-
- public function buildReferenceCycleMonth(OrderShopInterface $orderShop, \DateTime $distributionDate): string
- {
- return $this->getPrefixReference($orderShop) .
- 'M' . $distributionDate->format('m') .
- 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
- 'A' . $distributionDate->format('y');
- }
-
- public function buildReferenceCycleYear(OrderShopInterface $orderShop, \DateTime $distributionDate): string
- {
- return $this->getPrefixReference($orderShop) .
- 'C' . $this->numberPad($orderShop->getCycleId(), 5) .
- 'A' . $distributionDate->format('y');
- }
-
- public function getPrefixReference(OrderShopInterface $orderShop): string
- {
- return $orderShop->getSection()->getSettingValue(SectionSettingDefinition::SETTING_REFERENCE_PREFIX);;
- }
-
- public function numberPad($number, $length): string
- {
- return str_pad($number, $length, "0", STR_PAD_LEFT);
- }
-
- }
|