src/Repository/PaymentRepository.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Payment;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Payment|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Payment|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Payment[]    findAll()
  10.  * @method Payment[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class PaymentRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryPayment::class);
  17.     }
  18.     public function getPaymentList($startDate ''$endDate ''$client_id) {
  19.         $conn $this->getEntityManager()->getConnection();
  20.         $query "SELECT p.*, DATE_FORMAT(p.created_at, '%Y-%m-%d') paymentAt,
  21.                 ord.json_fields, ord.order_type, cl.*, c.name as customer
  22.                 FROM payment p 
  23.                 LEFT JOIN orders ord ON ord.order_id = p.order_id 
  24.                 LEFT JOIN customer c ON c.customer_id = ord.customer_id
  25.                 LEFT JOIN client cl ON cl.client_id = ord.client_id  WHERE p.client_id = $client_id";
  26.         if($startDate && $startDate){
  27.             $query .= " AND (date(p.created_at) BETWEEN '$startDate' AND '$endDate' )";
  28.         }
  29.         return $conn->fetchAllAssociative($query);
  30.        // $res = $this->getEntityManager ()->getConnection ()->prepare ( $query );        
  31.        // $res->execute ();
  32.         
  33.        // return $res->fetchAll();
  34.     }    
  35.     public function getPaymentCashList($startDate ''$endDate ''$client_id) {
  36.         $conn $this->getEntityManager()->getConnection();
  37.         $query "SELECT o.* , os.is_final, c.name AS customer FROM orders o
  38.                 LEFT JOIN customer c ON c.customer_id = o.customer_id
  39.                 LEFT JOIN order_status os ON os.order_status_id = o.order_status_id
  40.                 LEFT JOIN payment_method pm ON pm.payment_method_id = o.payment_method_id
  41.                 WHERE o.client_id = '$client_id' AND os.is_final = 1 AND pm.is_cash = 1";
  42.         if($startDate && $startDate){
  43.             $query .= " AND (date(o.created_at) BETWEEN '$startDate' AND '$endDate' )";
  44.         }
  45.         
  46.         return $conn->fetchAllAssociative($query);
  47.         //$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );        
  48.         //$res->execute ();
  49.         
  50.         //return $res->fetchAll();
  51.     }    
  52.     
  53.     
  54.     public function getPaymentTotals($startDate ''$endDate ''$client_id) {
  55.         $conn $this->getEntityManager()->getConnection();
  56.         $query "SELECT SUM(p.amount) montoTotal, count(1) cantTotal
  57.                     FROM payment p
  58.                     WHERE p.result = 1 AND p.client_id = '$client_id'
  59.                     ";
  60.         if($startDate && $startDate){
  61.             $query .= " AND date(p.created_at) BETWEEN '$startDate' AND '$endDate' ";
  62.         }
  63.         return $conn->fetchAssociative($query);
  64.     
  65.           //          $res = $this->getEntityManager ()->getConnection ()->prepare ( $query );        
  66.             //            $res->execute ();
  67.         
  68.         //return $res->fetch();
  69.     }
  70.     public function getPaymentCashTotals($startDate ''$endDate ''$client_id) {
  71.         $conn $this->getEntityManager()->getConnection();
  72.         $query "SELECT COUNT(*) AS cantTotal, SUM(REPLACE(o.total, ',', '')) AS montoTotal FROM orders o
  73.                 LEFT JOIN customer c ON c.customer_id = o.customer_id
  74.                 LEFT JOIN order_status os ON os.order_status_id = o.order_status_id
  75.                 LEFT JOIN payment_method pm ON pm.payment_method_id = o.payment_method_id
  76.                 WHERE o.client_id = '12' AND os.is_final = 1 AND pm.is_cash = 1
  77.                     ";
  78.         if($startDate && $startDate){
  79.             $query .= " AND (date(o.created_at) BETWEEN '$startDate' AND '$endDate' )";
  80.         }
  81.         return $conn->fetchAssociative($query);
  82.         
  83.                     //$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );        
  84.                     //    $res->execute ();
  85.         
  86.         //return $res->fetch();
  87.     }
  88.     public function getPaymentRejectedTotals($startDate ''$endDate ''$client_id) {
  89.         $conn $this->getEntityManager()->getConnection();
  90.         $query "SELECT SUM(p.amount) montoTotal, count(1) cantTotal
  91.                     FROM payment p
  92.                     WHERE p.result = 0 AND p.client_id = '$client_id'
  93.                     ";
  94.         if($startDate && $startDate){
  95.             $query .= " AND date(p.created_at) BETWEEN '$startDate' AND '$endDate' ";
  96.         }
  97.         return $conn->fetchAssociative($query);
  98.                     //$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );        
  99.                      //   $res->execute ();
  100.         
  101.         //return $res->fetch();
  102.     }
  103.     
  104.     public function getPaymentQtyClients($startDate ''$endDate '') {
  105.         $conn $this->getEntityManager()->getConnection();
  106.         $query "SELECT COUNT(DISTINCT(c.client_id)) cantClients FROM payment p
  107.                 LEFT JOIN orders o ON o.order_id =p.order_id
  108.                 LEFT JOIN client c ON c.client_id = o.client_id
  109.                 WHERE p.result = 1 ";
  110.         if($startDate && $startDate){
  111.             $query .= " AND date(p.created_at) BETWEEN '$startDate' AND '$endDate' ";
  112.         }
  113.         return $conn->fetchAssociative($query);
  114.         //$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );        
  115.         //$res->execute ();
  116.         
  117.         //return $res->fetch();
  118.     }
  119. }