MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/www/amanda/app/Http/Controllers/OrderTaxController.php
<?php

namespace App\Http\Controllers;

use App\Order;
use App\Order_tax;
use Auth;
use Illuminate\Http\Request;
use Carbon\Carbon;

class OrderTaxController extends Controller
{
    public function index(Request $request)
    {
        $limit = config('constants.limit');
        $search = $request->search;
        $start_date = $request->start_date;
        $end_date = $request->end_date;
        $date = [
            'start_date' => $start_date,
            'end_date' => $end_date,
        ];
       /* if($start_date!=""){
            $group_by = 'order_tax.country_code';
        }
        else{*/
            $group_by = 'order_tax.country_code';   
        // }



        $order = Order_tax::leftjoin('countries','countries.id','order_tax.country_code')
                ->where(function($q) use ($search)
                {
                    // $q->orWhere('order_tax.tax_name', 'like', '%' . $search . '%');
                    // $q->orWhere('order_tax.tax_price', 'like', '%' . $search . '%');  
                    $q->orWhere('order_tax.country_code', 'like', '%' . $search . '%');

                })
                ->where(function($q) use ($date)
                {
                    if($date['start_date']!="" && $date['end_date']!="")
                    {
                        // $q->Where('order_tax.created_at', $data['start_date']);
                        $q->where('order_tax.created_at', '>=', $date['start_date']);
                        $q->where('order_tax.created_at', '<=', $date['end_date']);
                    }
                    else if($date["start_date"]!="" && $date["end_date"]==""){
                      $q->where('order_tax.created_at', '>=', $date["start_date"]);
                    }
                    else if($date["start_date"]=="" && $date["end_date"]!=""){
                       $q->where('order_tax.created_at', '<=', $date["end_date"]);
                    }
                })
                ->select('order_tax.*','countries.code as countr_code',\DB::raw("SUM(tax_price) as total_tax_price"))
                ->groupBy($group_by)
                ->orderBy('order_tax.id','desc')
                ->paginate($limit);

        return response()->json($order,200);
    }

  

    public function store(Request $request)
    {
        $order = Order::create([
            'product_id' => $request->product_id,
            'user_id' => Auth::id(),
            'quantity' => $request->quantity,
            'address' => $request->address
        ]);

        return response()->json([
            'status' => (bool) $order,
            'data'   => $order,
            'message' => $order ? 'Order Created!' : 'Error Creating Order'
        ]);
    }


    
}