settingSolver = $settingSolver; } public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string { switch ($orderShop->getSection()->getCycle()) { 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, \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 $this->settingSolver->getSettingValue($orderShop->getSection(), SectionSettingDefinition::SETTING_REFERENCE_PREFIX); } public function numberPad($number, $length): string { return str_pad($number, $length, "0", STR_PAD_LEFT); } }