|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
-
- namespace Lc\CaracoleBundle\Generator;
-
- use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
- use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
- use Lc\CaracoleBundle\Model\Section\SectionModel;
- use Lc\SovBundle\Solver\Setting\SettingSolver;
-
- class OrderReferenceGenerator
- {
- protected SettingSolver $settingSolver;
-
- public function __construct(SettingSolver $settingSolver)
- {
- $this->settingSolver = $settingSolver;
- }
-
- public function buildReference(OrderShopInterface $orderShop, \DateTimeInterface $distributionDate = null): string
- {
- switch ($orderShop->getSection()->getCycleType()) {
- case SectionModel::CYCLE_TYPE_DAY:
- return $this->buildReferenceCycleDay($orderShop);
- case SectionModel::CYCLE_TYPE_WEEK:
- return $this->buildReferenceCycleWeek($orderShop, $distributionDate);
- case SectionModel::CYCLE_TYPE_MONTH:
- return $this->buildReferenceCycleMonth($orderShop, $distributionDate);
- case SectionModel::CYCLE_TYPE_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, \DateTimeInterface $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,
- \DateTimeInterface $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, \DateTimeInterface $distributionDate): string
- {
- return $this->getPrefixReference($orderShop) .
- 'C' . $this->numberPad($orderShop->getCycleId(), 5) .
- 'A' . $distributionDate->format('y');
- }
-
- public function getPrefixReference(OrderShopInterface $orderShop): string
- {
- return ''.$this->settingSolver->getSettingValue(
- $orderShop->getSection(),
- SectionSettingDefinition::SETTING_REFERENCE_PREFIX
- );
- }
-
- public function numberPad($number, $length): string
- {
- return str_pad($number, $length, "0", STR_PAD_LEFT);
- }
-
- }
|