You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\File;
  3. use App\Entity\Address\Address;
  4. use Lc\CaracoleBundle\Model\File\DocumentInterface;
  5. use Lc\CaracoleBundle\Model\File\DocumentModel;
  6. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  7. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  8. use Lc\CaracoleBundle\Repository\AbstractStore;
  9. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  10. class DocumentStore extends AbstractStore
  11. {
  12. use MerchantStoreTrait;
  13. protected DocumentRepositoryQuery $query;
  14. public function __construct(DocumentRepositoryQuery $query)
  15. {
  16. $this->query = $query;
  17. }
  18. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  19. {
  20. return $query;
  21. }
  22. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  23. {
  24. $query->filterIsOnlineAndOffline();
  25. if(isset($this->merchant) && $this->merchant) {
  26. $query->filterByMerchant($this->merchant);
  27. }
  28. return $query;
  29. }
  30. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  31. {
  32. return $query;
  33. }
  34. public function getOneByReference(string $reference = null, string $type = null, $query = null)
  35. {
  36. $query = $this->createDefaultQuery($query);
  37. $query
  38. ->filterByReference($reference)
  39. ->orderBy('createdAt', 'ASC')
  40. ->innerJoin('.orderShops', 'orderShops')
  41. ;
  42. if(!is_null($type)) {
  43. $query->filterByType($type);
  44. }
  45. return $query->findOne();
  46. }
  47. public function getOneLatestByType(string $documentType, $query = null): ?DocumentInterface
  48. {
  49. $query = $this->createDefaultQuery($query);
  50. $query
  51. ->filterIsReferenceNotNull()
  52. ->filterByType($documentType)
  53. ->orderBy('createdAt', 'DESC');
  54. return $query->findOne();
  55. }
  56. // findLastInvoice
  57. public function getOneLastInvoice($query = null)
  58. {
  59. $query = $this->createDefaultQuery($query);
  60. $query
  61. ->orderBy('createdAt', 'DESC');
  62. return $query->findOne();
  63. }
  64. public function getByBuyerAddress(Address $buyerAddress, $query = null)
  65. {
  66. $query = $this->createDefaultQuery($query);
  67. $query->filterByBuyerAddress($buyerAddress);
  68. return $query->find();
  69. }
  70. }