unioil-mobile-api/app/Services/RegistrationService.php

61 lines
1.5 KiB
PHP

<?php
namespace App\Services;
use App\Contracts\RegistationResourceInterface;
use App\Contracts\RegistrationResourceInterface;
use App\LoyaltyCard;
use Illuminate\Support\Facades\DB;
use Response;
use Schema;
use Hash;
use App\Libraries\ListHelper;
use Illuminate\Http\Request;
use App\MobileAnalytics;
use App\Helpers\HttpStatusCode;
use App\Helpers\CurrentUserHelper;
use App\Libraries\UuidHelper;
class RegistrationService implements RegistrationResourceInterface
{
public $list;
public function report_registration($params, $export = false)
{
$pagination = ListHelper::validatePagination($params['page_size'],$params['page']);
$this->list = LoyaltyCard::query()->select(
'created_at','created_at as date',
DB::raw("COUNT(CASE WHEN is_validated = '1' THEN 1 END) as activated"),
DB::raw("COUNT(CASE WHEN created_at <> '' THEN 1 END) as registered")
);
if($params['date_start'] != null && $params['date_end'] != null)
{
$this->list->whereDate('created_at', '>=', $params['date_start'])
->whereDate('created_at', '<=', $params['date_end']);
}
$this->list->groupBy(DB::raw('DATE(created_at)'));
$sorting = $params['sorting'];
if(count($sorting) > 0)
{
$this->list = $this->list->orderBy($sorting['field'],$sorting['sort_order']);
}
if($export)
return $this->list->get();
else
return $this->list->paginate($params['page_size']);
}
}