Bridge/Doctrine/ORM/Repository/OrderRepository.php
private function getOutstandingExpiredDueQueryBuilder()
    {
        $qb = $this->createQueryBuilder('o');
        $ex = $qb->expr();

        $qb
            ->join('o.paymentTerm', 't')
            ->where($ex->andX(
                $ex->eq('o.sample', ':not_sample'),                    // Not sample
                $ex->lt('o.paidTotal', 'o.grandTotal'),                // Paid total lower than grand total
                $ex->notIn('o.invoiceState', ':canceled_or_refunded'), // Not canceled/refunded
                $qb->expr()->lte('o.outstandingDate', ':today'),       // Payment limit date lower than today
                $this->getDueClauses()                                 // Terms triggered
            ))
            ->addOrderBy('o.outstandingDate', 'ASC')
            ->setParameter('not_sample', false)
            ->setParameter('today', (new \DateTime())->setTime(23, 59, 59), Type::DATETIME)
            ->setParameter('canceled_or_refunded', [InvoiceStates::STATE_CANCELED, InvoiceStates::STATE_CREDITED]);

        $this->setDueParameters($qb);

        return $qb;
    }
private function getOutstandingExpiredDueQueryBuilder()
    {
        $qb = $this->createQueryBuilder('o');
        $ex = $qb->expr();

        $qb
            ->join('o.paymentTerm', 't')
            ->where($ex->andX(
                $ex->eq('o.sample', ':not_sample'),                    // Not sample
                $ex->lt('o.paidTotal', 'o.grandTotal'),                // Paid total lower than grand total
                $ex->notIn('o.invoiceState', ':canceled_or_refunded'), // Not canceled/refunded
                $qb->expr()->lte('o.outstandingDate', ':today'),       // Payment limit date lower than today
                $this->getDueClauses()                                 // Terms triggered
            ))
            ->addOrderBy('o.outstandingDate', 'ASC')
            ->setParameter('not_sample', false)
            ->setParameter('today', (new \DateTime())->setTime(23, 59, 59), Type::DATETIME)
            ->setParameter('canceled_or_refunded', [InvoiceStates::STATE_CANCELED, InvoiceStates::STATE_CREDITED]);

        $this->setDueParameters($qb);

        return $qb;
    }
Returns the outstanding expired due query builder.

@return QueryBuilder