Viewing file: ReportController.php (5.48 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Customer;
use App\Http\Controllers\Controller; use App\Models\Customer; use App\Models\MessageReport; use App\Models\Plan; use App\Models\Report; use App\Models\Transactions; use Carbon\Carbon; use Illuminate\Http\Request;
class ReportController extends Controller {
// Transactions Report public function transactions(Request $request){
$data['request_data']=$request->only('main_type','sub_type','date'); $data['customers']=Customer::orderByDesc('created_at')->get();
return view('customer.report.transactions', $data); }
//getAlltransactions
public function getAllTransactions(Request $request){
$reports = Transactions::orderByDesc('created_at')->where('added_by', auth('customer')->user()->type)->where('customer_id', auth('customer')->user()->id);
if($request->main_type){ $reports = $reports->where('type', $request->main_type); }
if($request->date){ $dates= explode('-', $request->date); $fromDate= isset($dates[0])?$dates[0]:Carbon::now()->subDays(3); $toDate= isset($dates[1])?$dates[1]:Carbon::now(); $reports = $reports->whereBetween('created_at',[$fromDate, $toDate]); }
// $reports=$reports->get();
return datatables()->of($reports)
->addColumn('amount', function ($q) {
return formatNumberWithCurrSymbol($q->amount); })
->addColumn('type', function ($q) {
return str_replace('_','-', $q->type); })
->addColumn('status', function ($q) { if($q->status=='paid'){ $type=' <span class="badge badge-success">Paid</span>'; }else{ $type=' <span class="badge badge-danger">Unpaid</span>'; } return $type; })
->rawColumns(['amount','status','type',])
->toJson(); }
//Message Reports public function message_report(Request $request){ $data['request_data']=$request->only('main_type','sub_type','date');
return view('customer.report.message_report', $data); }
public function getAllReports(Request $request){
$message_logs = MessageReport::orderByDesc('created_at')->where('customer_id', auth('customer')->user()->id);
if ($request->destination && $request->destination == 'sent') { $message_logs = $message_logs->whereIn('status', ['pending', 'succeed']); } else if ($request->destination) { $message_logs = $message_logs->where('status', $request->destination); }
if ($request->date) { $dates = explode('-', $request->date); $fromDateFilter = isset($dates[0]) ? $dates[0] : Carbon::now()->subDays(3); $fromDate = date("Y-m-d", strtotime($fromDateFilter)); $toDateFilter = isset($dates[1]) ? $dates[1] : Carbon::now(); $toDate = date("Y-m-d", strtotime($toDateFilter)); $message_logs = $message_logs->whereBetween('created_at', [$fromDate, $toDate]); }
return datatables()->of($message_logs)
->addColumn('profile', function ($q) { $name=$q->customer->full_name; $email=$q->customer->email;
$profile='<div><h6 class="d-block">'.$name.'</h6><b>'.$email.'</b></div>'; return $profile; }) ->addColumn('details', function ($q) { $type='';
if($q->from_type=='sms'){ $type='SMS'; }else if($q->from_type=='whatsapp'){ $type='Whatsapp'; } $type='<h6>Type:'.$type.'</h6>'; $date='<h6>Date:'.formatDate($q->created_at).'</h6>';
return '<div>'.$type.$date.'</div>'; }) ->addColumn('status', function ($q) { $status=''; if($q->status=='failed'){ $status='<span class="badge badge-danger">failed</span>'; }else{ $status='<span class="badge badge-success">Sent</span>'; } return $status; }) ->addColumn('title_sms', function ($q) {
return $q->campaign->title; }) ->addColumn('body', function ($q) {
return $q->body; }) ->addColumn('characters_count', function ($q) {
return strlen($q->body); }) ->addColumn('total', function ($q) {
$totalCount=1; $requestCharacters=$q->body; $characters=mb_strlen($requestCharacters, "UTF-8"); if (strlen($requestCharacters) != strlen(utf8_decode($requestCharacters))) { if($characters && $characters > 70){ $grandTotal=ceil($characters / 70); if($grandTotal > 1) $totalCount= $grandTotal; } }else { if($characters && $characters > 155){ $grandTotal=ceil($characters / 155); if($grandTotal > 1) $totalCount= $grandTotal; } }
return $totalCount; })
->rawColumns(['profile','details','status'])
->toJson(); }
}
|