<?php
namespace App\Repository;
use App\Entity\Payment;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Payment|null find($id, $lockMode = null, $lockVersion = null)
* @method Payment|null findOneBy(array $criteria, array $orderBy = null)
* @method Payment[] findAll()
* @method Payment[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PaymentRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Payment::class);
}
public function getPaymentList($startDate = '', $endDate = '', $client_id) {
$conn = $this->getEntityManager()->getConnection();
$query = "SELECT p.*, DATE_FORMAT(p.created_at, '%Y-%m-%d') paymentAt,
ord.json_fields, ord.order_type, cl.*, c.name as customer
FROM payment p
LEFT JOIN orders ord ON ord.order_id = p.order_id
LEFT JOIN customer c ON c.customer_id = ord.customer_id
LEFT JOIN client cl ON cl.client_id = ord.client_id WHERE p.client_id = $client_id";
if($startDate && $startDate){
$query .= " AND (date(p.created_at) BETWEEN '$startDate' AND '$endDate' )";
}
return $conn->fetchAllAssociative($query);
// $res = $this->getEntityManager ()->getConnection ()->prepare ( $query );
// $res->execute ();
// return $res->fetchAll();
}
public function getPaymentCashList($startDate = '', $endDate = '', $client_id) {
$conn = $this->getEntityManager()->getConnection();
$query = "SELECT o.* , os.is_final, c.name AS customer FROM orders o
LEFT JOIN customer c ON c.customer_id = o.customer_id
LEFT JOIN order_status os ON os.order_status_id = o.order_status_id
LEFT JOIN payment_method pm ON pm.payment_method_id = o.payment_method_id
WHERE o.client_id = '$client_id' AND os.is_final = 1 AND pm.is_cash = 1";
if($startDate && $startDate){
$query .= " AND (date(o.created_at) BETWEEN '$startDate' AND '$endDate' )";
}
return $conn->fetchAllAssociative($query);
//$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );
//$res->execute ();
//return $res->fetchAll();
}
public function getPaymentTotals($startDate = '', $endDate = '', $client_id) {
$conn = $this->getEntityManager()->getConnection();
$query = "SELECT SUM(p.amount) montoTotal, count(1) cantTotal
FROM payment p
WHERE p.result = 1 AND p.client_id = '$client_id'
";
if($startDate && $startDate){
$query .= " AND date(p.created_at) BETWEEN '$startDate' AND '$endDate' ";
}
return $conn->fetchAssociative($query);
// $res = $this->getEntityManager ()->getConnection ()->prepare ( $query );
// $res->execute ();
//return $res->fetch();
}
public function getPaymentCashTotals($startDate = '', $endDate = '', $client_id) {
$conn = $this->getEntityManager()->getConnection();
$query = "SELECT COUNT(*) AS cantTotal, SUM(REPLACE(o.total, ',', '')) AS montoTotal FROM orders o
LEFT JOIN customer c ON c.customer_id = o.customer_id
LEFT JOIN order_status os ON os.order_status_id = o.order_status_id
LEFT JOIN payment_method pm ON pm.payment_method_id = o.payment_method_id
WHERE o.client_id = '12' AND os.is_final = 1 AND pm.is_cash = 1
";
if($startDate && $startDate){
$query .= " AND (date(o.created_at) BETWEEN '$startDate' AND '$endDate' )";
}
return $conn->fetchAssociative($query);
//$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );
// $res->execute ();
//return $res->fetch();
}
public function getPaymentRejectedTotals($startDate = '', $endDate = '', $client_id) {
$conn = $this->getEntityManager()->getConnection();
$query = "SELECT SUM(p.amount) montoTotal, count(1) cantTotal
FROM payment p
WHERE p.result = 0 AND p.client_id = '$client_id'
";
if($startDate && $startDate){
$query .= " AND date(p.created_at) BETWEEN '$startDate' AND '$endDate' ";
}
return $conn->fetchAssociative($query);
//$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );
// $res->execute ();
//return $res->fetch();
}
public function getPaymentQtyClients($startDate = '', $endDate = '') {
$conn = $this->getEntityManager()->getConnection();
$query = "SELECT COUNT(DISTINCT(c.client_id)) cantClients FROM payment p
LEFT JOIN orders o ON o.order_id =p.order_id
LEFT JOIN client c ON c.client_id = o.client_id
WHERE p.result = 1 ";
if($startDate && $startDate){
$query .= " AND date(p.created_at) BETWEEN '$startDate' AND '$endDate' ";
}
return $conn->fetchAssociative($query);
//$res = $this->getEntityManager ()->getConnection ()->prepare ( $query );
//$res->execute ();
//return $res->fetch();
}
}