<?php | |||||
namespace Lc\CaracoleBundle\Builder\File; | |||||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Resolver\Reference\DocumentReferenceResolver; | |||||
class DocumentBuilder | |||||
{ | |||||
protected DocumentReferenceResolver $documentReferenceResolver; | |||||
public function __construct(DocumentReferenceResolver $documentReferenceResolver) | |||||
{ | |||||
$this->documentReferenceResolver = $documentReferenceResolver; | |||||
} | |||||
public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) | |||||
{ | |||||
$merchantAddress = $orderShop->getMerchant()->getAddress(); | |||||
$buyerAddress = $orderShop->getInvoiceAddress(); | |||||
$document->setReference($this->documentReferenceResolver->buildReference($orderShop->getMerchant())) ; | |||||
$document->setMerchantAddress($merchantAddress); | |||||
$document->setBuyerAddress($buyerAddress); | |||||
$document->setMerchantAddressText($merchantAddress->getSummary()); | |||||
$document->setBuyerAddressText($buyerAddress->getSummary()); | |||||
$document->addOrderShop($orderShop); | |||||
$document->setCreatedBy($orderShop->getUser()); | |||||
return $document; | |||||
} | |||||
} |
namespace Lc\CaracoleBundle\Builder\Order; | namespace Lc\CaracoleBundle\Builder\Order; | ||||
use App\Entity\Order\OrderProductReductionCatalog; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | |||||
use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; | use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent; | ||||
use Lc\CaracoleBundle\Factory\File\DocumentFactory; | |||||
use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; | use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory; | use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; | use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusHistoryModel; | |||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | use Lc\CaracoleBundle\Model\User\VisitorInterface; | ||||
use Lc\CaracoleBundle\Repository\Order\OrderProductStore; | use Lc\CaracoleBundle\Repository\Order\OrderProductStore; | ||||
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; | |||||
use Lc\CaracoleBundle\Repository\Order\OrderStatusStore; | use Lc\CaracoleBundle\Repository\Order\OrderStatusStore; | ||||
use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; | use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore; | ||||
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | ||||
protected ProductFamilyStore $productFamilyStore; | protected ProductFamilyStore $productFamilyStore; | ||||
protected PriceResolver $priceResolver; | protected PriceResolver $priceResolver; | ||||
protected OrderProductBuilder $orderProductBuilder; | protected OrderProductBuilder $orderProductBuilder; | ||||
protected DocumentBuilder $documentBuilder; | |||||
public function __construct( | public function __construct( | ||||
EntityManagerInterface $entityManager, | EntityManagerInterface $entityManager, | ||||
OrderShopStore $orderShopStore, | |||||
OrderStatusStore $orderStatusStore, | OrderStatusStore $orderStatusStore, | ||||
OrderProductStore $orderProductStore, | OrderProductStore $orderProductStore, | ||||
ProductFamilyStore $productFamilyStore, | ProductFamilyStore $productFamilyStore, | ||||
OrderProductBuilder $orderProductBuilder, | OrderProductBuilder $orderProductBuilder, | ||||
DocumentBuilder $documentBuilder, | |||||
PriceResolver $priceResolver | PriceResolver $priceResolver | ||||
) { | ) { | ||||
$this->entityManager = $entityManager; | $this->entityManager = $entityManager; | ||||
$this->orderShopStore = $orderShopStore; | |||||
$this->orderStatusStore = $orderStatusStore; | $this->orderStatusStore = $orderStatusStore; | ||||
$this->orderProductStore = $orderProductStore; | $this->orderProductStore = $orderProductStore; | ||||
$this->productFamilyStore = $productFamilyStore; | $this->productFamilyStore = $productFamilyStore; | ||||
$this->orderProductBuilder = $orderProductBuilder; | $this->orderProductBuilder = $orderProductBuilder; | ||||
$this->documentBuilder = $documentBuilder; | |||||
$this->priceResolver = $priceResolver; | $this->priceResolver = $priceResolver; | ||||
} | } | ||||
public function create( | public function create( | ||||
MerchantInterface $merchant, | |||||
SectionInterface $section, | SectionInterface $section, | ||||
UserInterface $user = null, | UserInterface $user = null, | ||||
VisitorInterface $visitor = null | VisitorInterface $visitor = null | ||||
) { | ) { | ||||
$orderShopFactory = new OrderShopFactory(); | $orderShopFactory = new OrderShopFactory(); | ||||
$orderShop = $orderShopFactory->create($merchant, $section, $user, $visitor); | |||||
$orderShop = $orderShopFactory->create($section, $user, $visitor); | |||||
$this->changeOrderStatus($orderShop, OrderStatusModel::ALIAS_CART); | $this->changeOrderStatus($orderShop, OrderStatusModel::ALIAS_CART); | ||||
return $orderShop; | return $orderShop; | ||||
} | } | ||||
public function createIfNotExist( | |||||
SectionInterface $section, | |||||
UserInterface $user = null, | |||||
VisitorInterface $visitor = null | |||||
) { | |||||
$cart = $this->orderShopStore->getCartBy( | |||||
[ | |||||
'section' => $section, | |||||
'user' => $user, | |||||
'visitor' => $visitor | |||||
] | |||||
); | |||||
if (!$cart) { | |||||
$cart = $this->create($section, $user, $visitor); | |||||
} | |||||
return $cart; | |||||
} | |||||
public function changeOrderStatus(OrderShopInterface $orderShop, string $alias) | public function changeOrderStatus(OrderShopInterface $orderShop, string $alias) | ||||
{ | { | ||||
$orderStatus = $this->orderStatusStore->getRepositoryQuery()->findOneByAlias($alias); | $orderStatus = $this->orderStatusStore->getRepositoryQuery()->findOneByAlias($alias); | ||||
return $orderShop; | return $orderShop; | ||||
} | } | ||||
public function createDocumentInvoice(OrderShopInterface $orderShop) | |||||
{ | |||||
$documentFactory = new DocumentFactory(); | |||||
$document = $documentFactory->create(DocumentModel::TYPE_INVOICE); | |||||
$this->documentBuilder->initFromOrderShop($orderShop); | |||||
return $document; | |||||
} | |||||
} | } |
use App\Entity\File\Document; | use App\Entity\File\Document; | ||||
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | |||||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | use Lc\CaracoleBundle\Model\File\DocumentInterface; | ||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
class DocumentFactory extends AbstractFactory | class DocumentFactory extends AbstractFactory | ||||
{ | { | ||||
use MerchantFactoryTrait; | use MerchantFactoryTrait; | ||||
public function create(): DocumentInterface | |||||
public function create(string $type): DocumentInterface | |||||
{ | { | ||||
$document = new Document(); | $document = new Document(); | ||||
$document->setMerchant($this->merchant); | $document->setMerchant($this->merchant); | ||||
$document->setType($type); | |||||
$document->setTitle(''); | |||||
$document->setStatus(1); | |||||
return $document; | return $document; | ||||
} | } |
} | } | ||||
public function create( | public function create( | ||||
MerchantInterface $merchant, | |||||
SectionInterface $section, | SectionInterface $section, | ||||
UserInterface $user = null, | UserInterface $user = null, | ||||
VisitorInterface $visitor = null | VisitorInterface $visitor = null | ||||
$orderShop = new OrderShop(); | $orderShop = new OrderShop(); | ||||
$orderShop->setMerchant($merchant); | |||||
$orderShop->setSection($section); | $orderShop->setSection($section); | ||||
$orderShopBelongTo = false; | $orderShopBelongTo = false; |
namespace Lc\CaracoleBundle\Repository\File; | namespace Lc\CaracoleBundle\Repository\File; | ||||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class DocumentStore extends AbstractStore | class DocumentStore extends AbstractStore | ||||
{ | { | ||||
use MerchantStoreTrait; | |||||
protected DocumentRepositoryQuery $query; | protected DocumentRepositoryQuery $query; | ||||
public function __construct(DocumentRepositoryQuery $query) | public function __construct(DocumentRepositoryQuery $query) | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function getOneLatestByType(string $documentType) | |||||
{ | |||||
// @TODO : à écrire | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Order; | namespace Lc\CaracoleBundle\Repository\Order; | ||||
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; | |||||
use Lc\CaracoleBundle\Factory\File\DocumentFactory; | |||||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | ||||
use Lc\CaracoleBundle\Resolver\Reference\DocumentReferenceResolver; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class OrderShopStore extends AbstractStore | class OrderShopStore extends AbstractStore | ||||
{ | { | ||||
protected OrderShopRepositoryQuery $query; | protected OrderShopRepositoryQuery $query; | ||||
protected PriceResolver $priceResolver; | protected PriceResolver $priceResolver; | ||||
protected DocumentReferenceResolver $documentReferenceResolver; | |||||
protected DocumentBuilder $documentBuilder; | |||||
public function __construct( | public function __construct( | ||||
OrderShopRepositoryQuery $query, | OrderShopRepositoryQuery $query, | ||||
PriceResolver $priceResolver | |||||
PriceResolver $priceResolver, | |||||
DocumentReferenceResolver $documentReferenceResolver, | |||||
DocumentBuilder $documentBuilder | |||||
) { | ) { | ||||
$this->query = $query; | $this->query = $query; | ||||
$this->priceResolver = $priceResolver; | $this->priceResolver = $priceResolver; | ||||
$this->documentReferenceResolver = $documentReferenceResolver; | |||||
$this->documentBuilder = $documentBuilder; | |||||
} | } | ||||
public function getDatas(OrderShopInterface $orderShop = null): array | public function getDatas(OrderShopInterface $orderShop = null): array | ||||
{ | { | ||||
return $this->getTotalRemainingToBePaid($orderShop) > 0; | return $this->getTotalRemainingToBePaid($orderShop) > 0; | ||||
} | } | ||||
public function getCartByUserOrCreateIt($user) | |||||
{ | |||||
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); | |||||
if ($newOrderShop === null) { | |||||
$newOrderShop = $this->createOrderShop( | |||||
array( | |||||
'user' => $user, | |||||
'merchant' => $this->merchantUtils->getMerchantUser() | |||||
) | |||||
); | |||||
} | |||||
return $newOrderShop; | |||||
} | |||||
public function isCartAllowToBeOrder(OrderShopInterface $orderShop) | |||||
{ | |||||
return true; | |||||
} | |||||
/* | |||||
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null) | |||||
{ | |||||
$paramsSearchOrderShop = []; | |||||
$user = $this->security->getUser(); | |||||
$visitor = $this->userUtils->getVisitorCurrent(); | |||||
$orderShop = null; | |||||
$orderShopUser = null; | |||||
$orderShopVisitor = null; | |||||
if ($user) { | |||||
$orderShopUser = $this->orderShopRepo->findCartCurrent( | |||||
[ | |||||
'user' => $user | |||||
] | |||||
); | |||||
} | |||||
if ($visitor) { | |||||
$orderShopVisitor = $this->orderShopRepo->findCartCurrent( | |||||
[ | |||||
'visitor' => $visitor | |||||
] | |||||
); | |||||
} | |||||
if ($orderShopUser || $orderShopVisitor) { | |||||
// merge | |||||
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor | |||||
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts()) | |||||
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) { | |||||
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor); | |||||
$this->utils->addFlash( | |||||
'success', | |||||
"Votre panier visiteur vient d'être fusionné avec votre panier client." | |||||
); | |||||
} else { | |||||
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor; | |||||
} | |||||
// set user | |||||
if ($orderShop && $user && !$orderShop->getUser()) { | |||||
$orderShop->setUser($user); | |||||
$orderShop->setVisitor(null); | |||||
$this->em->persist($orderShop); | |||||
$this->em->flush(); | |||||
} | |||||
} | |||||
return $orderShop; | |||||
}*/ | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Resolver\Reference; | |||||
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; | |||||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionModel; | |||||
use Lc\CaracoleBundle\Repository\File\DocumentStore; | |||||
class DocumentReferenceResolver | |||||
{ | |||||
protected DocumentStore $documentStore; | |||||
public function __construct(DocumentStore $documentStore) | |||||
{ | |||||
$this->documentStore = $documentStore; | |||||
} | |||||
public function buildReference(MerchantInterface $merchant, string $documentType) | |||||
{ | |||||
$prefix = ''; | |||||
if ($documentType == DocumentModel::TYPE_DELIVERY_NOTE) { | |||||
$prefix = 'BL'; | |||||
} elseif ($documentType == DocumentModel::TYPE_PURCHASE_ORDER) { | |||||
$prefix = 'BC'; | |||||
} elseif ($documentType == DocumentModel::TYPE_INVOICE) { | |||||
$prefix = 'FA'; | |||||
} elseif ($documentType == DocumentModel::TYPE_QUOTATION) { | |||||
$prefix = 'DE'; | |||||
} | |||||
$oneDocumentExist = $this->documentStore | |||||
->setMerchant($merchant) | |||||
->getOneLatestByType($documentType) ; | |||||
if ($oneDocumentExist) { | |||||
$reference = $oneDocumentExist->getReference(); | |||||
$pattern = '#([A-Z]+)?([0-9]+)#'; | |||||
preg_match($pattern, $reference, $matches, PREG_OFFSET_CAPTURE); | |||||
$sizeNumReference = strlen($matches[2][0]); | |||||
$numReference = ((int)$matches[2][0]) + 1; | |||||
$numReference = str_pad($numReference, $sizeNumReference, '0', STR_PAD_LEFT); | |||||
return $prefix . $numReference; | |||||
} else { | |||||
return $prefix . '00001'; | |||||
} | |||||
} | |||||
} |
<?php | <?php | ||||
namespace Lc\CaracoleBundle\ReferenceBuilder; | |||||
namespace Lc\CaracoleBundle\Resolver\Reference; | |||||
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; | use Lc\CaracoleBundle\Definition\SectionSettingDefinition; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Section\SectionModel; | use Lc\CaracoleBundle\Model\Section\SectionModel; | ||||
class OrderReferenceBuilder | |||||
class OrderReferenceResolver | |||||
{ | { | ||||
public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string | public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string |