|
- <?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): string
- {
- switch ($orderShop->getSection()->getCycleType()) {
- case SectionModel::CYCLE_TYPE_DAY:
- return $this->buildReferenceCycleDay($orderShop);
- case SectionModel::CYCLE_TYPE_WEEK:
- return $this->buildReferenceCycleWeek($orderShop);
- case SectionModel::CYCLE_TYPE_MONTH:
- return $this->buildReferenceCycleMonth($orderShop);
- case SectionModel::CYCLE_TYPE_YEAR:
- return $this->buildReferenceCycleYear($orderShop);
- }
-
- 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): string
- {
- return $this->getPrefixReference($orderShop) .
- 'S' . $orderShop->getDistribution()->getCycleNumber() .
- 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
- 'A' . $this->formatYear($orderShop->getDistribution()->getYear());
- }
-
- public function buildReferenceCycleMonth(OrderShopInterface $orderShop): string {
- return $this->getPrefixReference($orderShop) .
- 'M' . $orderShop->getDistribution()->getCycleNumber() .
- 'C' . $this->numberPad($orderShop->getCycleId(), 4) .
- 'A' . $this->formatYear($orderShop->getDistribution()->getYear());
- }
-
- public function buildReferenceCycleYear(OrderShopInterface $orderShop): string
- {
- return $this->getPrefixReference($orderShop) .
- 'C' . $this->numberPad($orderShop->getCycleId(), 5) .
- 'A' . $this->formatYear($orderShop->getDistribution()->getYear());
- }
-
- public function getPrefixReference(OrderShopInterface $orderShop): string
- {
- return ''.$this->settingSolver->getSettingValue(
- $orderShop->getSection(),
- SectionSettingDefinition::SETTING_REFERENCE_PREFIX
- );
- }
-
- protected function numberPad($number, $length): string
- {
- return str_pad($number, $length, "0", STR_PAD_LEFT);
- }
-
- protected function formatYear(int $year):int{
- return substr($year, -2);
- }
-
- }
-
-
-
|