Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

81 lines
2.0KB

  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\Repository\MerchantStoreTrait;
  6. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  7. use Lc\CaracoleBundle\Repository\AbstractStore;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class DocumentStore extends AbstractStore
  10. {
  11. use SectionStoreTrait;
  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. $query->orderBy('id');
  21. return $query;
  22. }
  23. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  24. {
  25. $query->filterIsOnlineAndOffline();
  26. if(isset($this->section) && $this->section) {
  27. $query->filterBySection($this->section);
  28. }
  29. if(isset($this->merchant) && $this->merchant) {
  30. $query->filterByMerchantViaSection($this->merchant);
  31. }
  32. return $query;
  33. }
  34. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  35. {
  36. return $query;
  37. }
  38. public function getOneLatestByType(string $documentType, $query = null): DocumentInterface
  39. {
  40. $query = $this->createDefaultQuery($query);
  41. $query
  42. ->filterByType($documentType)
  43. ->orderBy('createdAt', 'DESC');
  44. return $query->findOne();
  45. }
  46. // findLastInvoice
  47. public function getOneLastInvoice($query = null)
  48. {
  49. $query = $this->createDefaultQuery($query);
  50. $query
  51. ->orderBy('createdAt', 'DESC');
  52. return $query->findOne();
  53. }
  54. public function getByBuyerAddress(Address $buyerAddress, $query = null)
  55. {
  56. $query = $this->createDefaultQuery($query);
  57. $query->filterByBuyerAddress($buyerAddress);
  58. return $query->find();
  59. }
  60. }