WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.217.62
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/src/Repository/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/src/Repository/InvoiceItemsRepository.php
<?php

namespace App\Repository;

use App\Entity\Invoice;
use App\Entity\InvoiceItems;
use App\Entity\Model;
use App\Entity\Stock;
use App\Entity\StockType;
use App\Entity\User;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use Symfony\Bridge\Doctrine\RegistryInterface;
use function Doctrine\ORM\QueryBuilder;

/**
 * @method InvoiceItems|null find($id, $lockMode = null, $lockVersion = null)
 * @method InvoiceItems|null findOneBy(array $criteria, array $orderBy = null)
 * @method InvoiceItems[]    findAll()
 * @method InvoiceItems[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class InvoiceItemsRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, InvoiceItems::class);
    }

    // /**
    //  * @return InvoiceItems[] Returns an array of InvoiceItems objects
    //  */


    public function findByUser(User $user)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Invoice','iv')
            ->andWhere('iv.CreateBy = :val')
            ->setParameter('val', $user)
            ->orderBy('i.id', 'ASC')
            ->getQuery()
            ->getResult()
        ;
    }

    public function findByContributor(User $contributor)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Stock','s')
            ->join('i.Invoice','invoice')
            ->where('invoice.Status = :status')
            ->andWhere('s.contributor = :val')
            ->setParameter('val', $contributor)
            ->setParameter('status', Invoice::PAID)
            ->orderBy('i.CreatedAt', 'DESC')
//            ->setMaxResults(5)
            ->getQuery()
            ->getResult()
        ;
    }
    public function findContributorEarningByType(User $contributor, StockType $stockType)
    {
            return $this->createQueryBuilder('i')
                ->select('SUM(i.Amount) as amount, COUNT(i.id) as sales')
                ->join('i.Stock', 's')
                ->join('i.Invoice', 'invoice')
                ->join('s.type', 'stockType')
                ->where('invoice.Status = :status')
                ->andWhere('s.contributor = :val')
                ->andWhere('stockType = :type')
                ->setParameter('val', $contributor)
                ->setParameter('status', Invoice::PAID)
                ->setParameter('type', $stockType)
                ->groupBy('stockType.id')
                ->getQuery()
                ->getResult();
    }
    public function findContributorBest(User $user)
    {
        $q= $this->createQueryBuilder('i');

        $q->select(['i.Stock', 'i.Amount'])
            ->addSelect('SUM(i.Amount) AS HIDDEN stat_sum_realised')
            ->groupBy('i.Stock');

        $q->orderBy('stat_sum_realised', 'DESC');
        $result=$q    ->getQuery()
            ->getResult();
    }

    public function findContributorTotal(User $user)
    {
        return $this->createQueryBuilder('i')
            ->select('SUM(i.Amount)')
            ->join('i.Invoice', 'invoice')
            ->join('i.Stock','s')
            ->andWhere('s.contributor = :val')
            ->andWhere('invoice.Status = :status')
            ->setParameter('status', Invoice::PAID)
            ->setParameter('val', $user)
            ->getQuery()
            ->getSingleScalarResult()
        ;
    }
    public function findContributorSales(User $user)
    {
        return $this->createQueryBuilder('i')
            ->select('COUNT(i.Amount)')
            ->join('i.Stock','s')
            ->andWhere('s.contributor = :val')
            ->setParameter('val', $user)
            ->getQuery()
            ->getSingleScalarResult()
        ;
    }

    public function findSalesForMonth($date, User $user)
    {
        try {
            $date = new DateTime($date);
            //dump($date);die;
        } catch (\Exception $e) {
            //dump($e->getMessage());die;
        }

        return $this->createQueryBuilder('i')
            ->where('i.CreatedAt BETWEEN :start AND :end')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('inv.Status = :val')
            //->andWhere('s.Published = :stock_status ')
            ->setParameter('start', $date->format('Y-m-d'))
            ->setParameter('end', $date->format('Y-m-t'))
            ->setParameter('val', Invoice::PAID)
            ->setParameter('contributor', $user)
            ->orderBy('i.CreatedAt', 'DESC')
            //->setParameter('stock_status', Stock::PUBLISHED_STOCK)
            ->getQuery()
            ->getResult();
    }

    public function findSalesByLicanse($licence, User $user)
    {
        return $this->createQueryBuilder('i')
            ->where('i.LicenceType LIKE :license')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('inv.Status = :val')
            //->andWhere('s.Published = :stock_status ')
            ->setParameter('val', Invoice::PAID)
            ->setParameter('contributor', $user)
            ->setParameter('license', "%".$licence."%")
            ->orderBy('i.CreatedAt', 'DESC')
            //->setParameter('stock_status', Stock::PUBLISHED_STOCK)
            ->getQuery()
            ->getResult();
    }

    public function findSalesBetweenDates($start, $end, User $user)
    {
        try{
            $st = new DateTime($start);
            $en = new DateTime($end);

            // replace time() with the time stamp you want to add one day to
            $startDate = $en->getTimestamp();
            $en = date('Y-m-d H:i:s', strtotime('+1 day', $startDate));
        }catch (\Exception $e){
            //
        }

        return $this->createQueryBuilder('i')
            ->where('i.CreatedAt BETWEEN :start AND :end')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('inv.Status = :status')
            ->setParameter('contributor', $user)
            ->setParameter('status', Invoice::PAID)
            ->setParameter('start', $st)
            ->setParameter('end', $en)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findSalesByStockType(StockType $stockType, User $user)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Stock', 's')
            ->join('i.Invoice', 'inv')
            ->where('s.type = :type')
            ->andWhere('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->setParameter('type', $stockType)
            ->setParameter('contributor', $user)
            ->setParameter('status', Invoice::PAID)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findContributorPaidInvoices(User $user)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->setParameter('status', Invoice::PAID )
            ->setParameter('contributor', $user)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findModelsWithSoldItems(User $contributor)
    {
        $qb = $this->createQueryBuilder('i')
            ->innerJoin('i.Invoice', 'inv')
            ->innerJoin('i.Stock', 's')
            ->innerJoin('s.stockReleases', 'stock_releases')
            ->innerJoin('stock_releases.TheRelease', 'the_release')
            ->innerJoin('the_release.model', 'model')
            ->select('model.id as model_id')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->setParameter('status', Invoice::PAID )
            ->setParameter('contributor', $contributor)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
        return $qb;
    }

    public function findContributorPaidInvoicesForMonth(User $user, $date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('i.CreatedAt BETWEEN :start AND :end')
            ->setParameter('status', Invoice::PAID )
            ->setParameter('contributor', $user)
            ->setParameter("start", $date->format("Y-m-d"))
            ->setParameter("end", $date->format("Y-m-t"))
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findContributorPaidInvoicesInMonthModel(User $contributor, Model $model, $date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->innerJoin('s.stockReleases', 'stockReleases')
            ->innerJoin('stockReleases.TheRelease', 'therelease')
            ->innerJoin('therelease.model', 'model')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('i.CreatedAt BETWEEN :start AND :end')
            ->andWhere('model = :model')
            ->setParameter('status', Invoice::PAID )
            ->setParameter('contributor', $contributor)
            ->setParameter("start", $date->format("Y-m-d"))
            ->setParameter("end", $date->format("Y-m-t"))
            ->setParameter("model", $model)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findModelSales(Model $model)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Stock', 's')
            ->join('i.Invoice', 'inv')
            ->innerJoin('s.stockReleases', 'stockReleases')
            ->innerJoin('stockReleases.TheRelease', 'therelease')
            ->innerJoin('therelease.model', 'model')
            ->where('inv.Status = :status')
            ->andWhere('model = :model')
            ->setParameter('model', $model)
            ->setParameter('status', Invoice::PAID)
            ->getQuery()
            ->getResult();
    }

    public function findContributorSoldStockById(Stock $stock)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->where('inv.Status = :inv_status')
            ->andWhere('i.Stock = :stock')
            ->setParameter('inv_status',Invoice::PAID)
            ->setParameter('stock', $stock)
            ->getQuery()
            ->getResult();
    }

    //ADMIN: SALES HISTORY
    public function fetchSalesHistory()
    {
        return $this->createQueryBuilder('i')
            ->innerJoin('i.Invoice', 'inv')
            ->where('inv.Status = :status')
            ->setParameter('status', Invoice::PAID)
            ->orderBy('i.CreatedAt','DESC')
            ->getQuery()
            ->getResult();
    }

    public function fetchSalesForStock(Stock $stock)
    {
        return $this->createQueryBuilder('i')
            ->innerJoin('i.Invoice', 'inv')
            ->innerJoin('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('i.Stock = :stock')
            ->setParameter('status', Invoice::PAID)
            ->setParameter('stock', $stock)
            ->orderBy('i.CreatedAt','DESC')
            ->getQuery()
            ->getResult();
    }

    public function findSalesBetweenDatesAdmin($start, $end)
    {

        try{
            $st = new DateTime($start);
            $en = new DateTime($end);

            // replace time() with the time stamp you want to add one day to
            $startDate = $en->getTimestamp();
            $en = date('Y-m-d H:i:s', strtotime('+1 day', $startDate));
        }catch (\Exception $e){
            //
        }

        return $this->createQueryBuilder('i')
            ->where('i.CreatedAt BETWEEN :start AND :end')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->andWhere('inv.Status = :status')
            ->setParameter('start', $st)
            ->setParameter('end', $en)
            ->setParameter('status', Invoice::PAID)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findPaidInvoicesForMonth($date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('i.CreatedAt BETWEEN :start AND :end')
            ->andWhere('inv.Status = :status')
            ->setParameter("start", $date->format("Y-m-d"))
            ->setParameter("end", $date->format("Y-m-t"))
            ->setParameter("status", Invoice::PAID)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findSalesByLicanseAdmin($licence)
    {
        return $this->createQueryBuilder('i')
            ->where('i.LicenceType LIKE :license')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->andWhere('inv.Status = :val')
            ->setParameter('val', Invoice::PAID)
            ->setParameter('license', "%".$licence."%")
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findSalesByStockTypeAdmin(StockType $stockType)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Stock', 's')
            ->join('i.Invoice', 'inv')
            ->where('s.type = :type')
            ->andWhere('inv.Status = :status')
            ->setParameter('type', $stockType)
            ->setParameter('status', Invoice::PAID)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }


    //ADMIN PAYOUTS
    public function findAdminPendingInvoices()
    {
        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
//            ->andWhere('s.contributor = :contributor')
            ->setParameter('status', "pending" )
//            ->setParameter('contributor', $user)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findAdminPaidInvoices()
    {
        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
//            ->andWhere('s.contributor = :contributor')
            ->setParameter('status', Invoice::PAID )
//            ->setParameter('contributor', $user)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findAdminTotalPaidInvoices()
    {
        try {
            return $this->createQueryBuilder('i')
                ->select('SUM(i.Amount)')
                ->join('i.Invoice', 'inv')
                ->where('inv.Status = :status')
                ->setParameter('status', Invoice::PAID)
                ->getQuery()
                ->getSingleScalarResult();
        } catch (NoResultException $e) {
            return 0;
        } catch (NonUniqueResultException $e) {
            return 0;
        }
    }

    public function findContributorUnPaidInvoicesForMonthAdmin(User $user, $date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('i.CreatedAt BETWEEN :start AND :end')
            ->setParameter('status', "pending" )
            ->setParameter('contributor', $user)
            ->setParameter("start", $date->format("Y-m-d"))
            ->setParameter("end", $date->format("Y-m-t"))
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findContributorPaidInvoicesForMonthAdmin(User $user, $date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->andWhere('i.CreatedAt BETWEEN :start AND :end')
            ->setParameter('status', Invoice::PAID )
            ->setParameter('contributor', $user)
            ->setParameter("start", $date->format("Y-m-d"))
            ->setParameter("end", $date->format("Y-m-t"))
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }
    public function findContributorPaidInvoicesForAdmin(User $user)
    {
        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('s.contributor = :contributor')
            ->setParameter('status', Invoice::PAID )
            ->setParameter('contributor', $user)
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }
    public function findPaidInvoicesForMonthAdmin($date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }
        return $this->createQueryBuilder('i')
            ->join('i.Invoice', 'inv')
            ->join('i.Stock', 's')
            ->where('inv.Status = :status')
            ->andWhere('i.CreatedAt BETWEEN :start AND :end')
            ->setParameter('status', Invoice::PAID )
            ->setParameter("start", $date->format("Y-m-d"))
            ->setParameter("end", $date->format("Y-m-t"))
            ->orderBy('i.CreatedAt', 'DESC')
            ->getQuery()
            ->getResult();
    }

    public function findContributorTotalPaidInvoicesForMonthAdmin(User $user, $date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        try {
            return $this->createQueryBuilder('i')
                ->select('SUM(i.Amount)')
                ->join('i.Invoice', 'inv')
                ->join('i.Stock', 's')
                ->where('inv.Status = :status')
                ->andWhere('s.contributor = :contributor')
                ->andWhere('i.CreatedAt BETWEEN :start AND :end')
                ->setParameter('status', Invoice::PAID)
                ->setParameter('contributor', $user)
                ->setParameter("start", $date->format("Y-m-d"))
                ->setParameter("end", $date->format("Y-m-t"))
                ->getQuery()
                ->getSingleScalarResult();
        } catch (NoResultException $e) {
            return 0;
        } catch (NonUniqueResultException $e) {
            return 0;
        }
    }
    public function findContributorSoldInMonthAdmin($date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }
            return $this->createQueryBuilder('i')
                ->select('c.id as contributor_id')
                ->join('i.Invoice', 'inv')
                ->join('i.Stock', 's')
                ->innerJoin('s.contributor', 'c')
                ->where('inv.Status = :status')
                ->andWhere('i.CreatedAt BETWEEN :start AND :end')
                ->setParameter('status', Invoice::PAID)
                ->setParameter("start", $date->format("Y-m-d"))
                ->setParameter("end", $date->format("Y-m-t"))
                ->getQuery()
                ->getResult();
    }
    public function findContributorTotalPaidInvoicesAdmin(User $user)
    {
        try {
            return $this->createQueryBuilder('i')
                ->select('SUM(i.Amount)')
                ->join('i.Invoice', 'inv')
                ->join('i.Stock', 's')
                ->where('inv.Status = :status')
                ->andWhere('s.contributor = :contributor')
                ->setParameter('status', Invoice::PAID)
                ->setParameter('contributor', $user)
                ->getQuery()
                ->getSingleScalarResult();
        } catch (NoResultException $e) {
            return 0;
        } catch (NonUniqueResultException $e) {
            return 0;
        }
    }
    public function findTotalPaidInvoicesForMonthAdmin($date)
    {
        try {
            $date = new DateTime($date);
        } catch (\Exception $e) {
            //
        }

        try {
            return $this->createQueryBuilder('i')
                ->select('SUM(i.Amount)')
                ->join('i.Invoice', 'inv')
                ->join('i.Stock', 's')
                ->where('inv.Status = :status')
                ->andWhere('i.CreatedAt BETWEEN :start AND :end')
                ->setParameter('status', Invoice::PAID)
                ->setParameter("start", $date->format("Y-m-d"))
                ->setParameter("end", $date->format("Y-m-t"))
                ->getQuery()
                ->getSingleScalarResult();
        } catch (NoResultException $e) {
            return 0;
        } catch (NonUniqueResultException $e) {
            return 0;
        }
    }

    public function fetchContributorsWithSoldItems()
    {
        $qb = $this->createQueryBuilder('i')
            ->innerJoin('i.Stock', 's')
            ->join('i.Invoice', 'inv')
            ->innerJoin('s.contributor', 'c')
            ->select('c.id as contributor_id')
            ->addSelect('c.FirstName as firstName')
            ->addSelect('c.LastName as lastName')
            ->groupBy('c.id')
            ->getQuery()
            ->getResult();
        return $qb;
    }

    /////////////ADMIN DASHBOARD/////////
    public function findSoldItemsByStockType(StockType $stockType)
    {
        $qb = $this->createQueryBuilder('i')
            ->select('SUM(i.Amount) as total_amount, COUNT(i.id) as sales_count')
            ->innerJoin('i.Stock', 'stock')
            ->innerJoin('i.Invoice', 'invoice')
            ->innerJoin('stock.type','stockType')
            ->where('stock.type = :type')
            ->andWhere('invoice.Status = :paid')
            ->setParameter('paid', Invoice::PAID)
            ->setParameter('type',$stockType)
            ->groupBy('stockType.title')
            ->getQuery();
        return $qb->getResult();
    }
    ////////////////////////////////////
    ///
    /// contributor///////////////////
    public function findSoldItemsByStockTypeContributor(StockType $stockType, User $user)
    {
        $qb = $this->createQueryBuilder('i')
            ->select('SUM(i.Amount) as total_amount, COUNT(i.id) as sales_count')
            ->join('i.Stock', 'stock')
            ->join('i.Invoice', 'invoice')
            ->innerJoin('stock.type','stockType')
            ->where('stock.type = :type')
            ->andWhere('stock.contributor =:user')
            ->andWhere('invoice.Status = :status')
            ->setParameter('type',$stockType)
            ->setParameter('user', $user)
            ->setParameter('status', Invoice::PAID)
            ->groupBy('stockType.title')
            ->getQuery();
        return $qb->getResult();
    }


    /*
    public function findOneBySomeField($value): ?InvoiceItems
    {
        return $this->createQueryBuilder('i')
            ->andWhere('i.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
    */
}

Youez - 2016 - github.com/yon3zu
LinuXploit