<commit_before><?php

namespace App\Http\Controllers;


use App\Models\Mind;
use App\Models\Mind_Drug;
use App\Models\Drug;
use App\Models\Drug_img;
use App\Models\Customer;
use App\Models\Transaction;
use App\Models\TransactionDrug;

use App\Models\Discount;

use App\Settings;

use Illuminate\Support\Facades\Auth;

use Illuminate\Http\Request;

use DateTime;

use PDF;

use App\Helpers\ProcessText;


use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;

class HomeController extends Controller
{
    /**
     * Display the home page.
     *
     * @return Response
     */
    public function index()
    {
        $mind = Mind::where('end_time', '>',  date("Y-m-d H:i:s") )
            ->where('start_time', '<',  date("Y-m-d H:i:s") )
            ->where('status', '1' )
            ->orderBy('start_time', 'asc')
            ->limit(1)
            ->get(['id']);
        if (count($mind)) {
            $drug = Mind::whereId($mind[0]->id)->firstOrFail();

            $drugArr = array();
            if (count($drug->mind_drugs)) {
                $drugItem = array();
                foreach($drug->mind_drugs as $row) {
                    $drugItem['drug_id'] = $row->drug_id;
                    $drugItem['drug_price'] = $row->drug_price;
                    $drugItem['drug_special_price'] = $row->drug_special_price;
                    $drugItem['max_discount_qty'] = $row->max_discount_qty;
                    $drugItem['max_qty'] = $row->max_qty;
                    $drugItem['note'] = $row->note;
                    $drugItem['status'] = $row->status;
                    $drugItem['drugInfo'] = $this->getDrugInfo($row->drug_id);
                    $drugItem['drugImage'] = $this->getDrugImage($row->drug_id);
                    $drugArr[] = $drugItem;
                }
            }

            // sort
            $price = array();
            foreach ($drugArr as $key => $row)
            {
                $price[$key] = $row['drug_special_price'];
            }
            array_multisort($price, SORT_DESC, $drugArr);

            //dd($drugArr);
            //$products =  $query->paginate(15);

            $currentPage = LengthAwarePaginator::resolveCurrentPage();
            $col = new Collection($drugArr);

            // fix test pagination
            $perPage = 12;
            $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
            $drugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage,[ 'path' => LengthAwarePaginator::resolveCurrentPath()]);



            $nextMind = Mind::where('start_time', '>',  date("Y-m-d H:i:s") )
                ->where('status', '1' )
                ->orderBy('start_time', 'asc')
                ->limit(1)
                ->get();
            $isCheckMind = false;
            return view( 'front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind') );
        } else {

            $mind = Mind::where('end_time', '<',  date("Y-m-d H:i:s") )
                ->where('status', '1' )
                ->orderBy('end_time', 'desc')
                ->limit(1)
                ->get(['id']);
            if (count($mind)) {
                $drug = Mind::whereId($mind[0]->id)->firstOrFail();
                $drugArr = array();
                if (count($drug->mind_drugs)) {
                    $drugItem = array();
                    foreach ($drug->mind_drugs as $row) {
                        $drugItem['drug_id'] = $row->drug_id;
                        $drugItem['drug_price'] = $row->drug_price;
                        $drugItem['drug_special_price'] = $row->drug_special_price;
                        $drugItem['max_discount_qty'] = $row->max_discount_qty;
                        $drugItem['max_qty'] = $row->max_qty;
                        $drugItem['note'] = $row->note;
                        $drugItem['status'] = $row->status;
                        $drugItem['drugInfo'] = $this->getDrugInfo($row->drug_id);
                        $drugItem['drugImage'] = $this->getDrugImage($row->drug_id);
                        $drugArr[] = $drugItem;
                    }
                }

                $currentPage = LengthAwarePaginator::resolveCurrentPage();
                $col = new Collection($drugArr);

                // fix test pagination
                $perPage = 12;
                $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
                $drugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]);

                //$products =  $query->paginate(15);

                $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                    ->where('status', '1')
                    ->orderBy('start_time', 'asc')
                    ->limit(1)
                    ->get();

                $isCheckMind = true;
                return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
            } else{
                $isCheckMind = true;
                $drugs = array();
                $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                    ->where('status', '1')
                    ->orderBy('start_time', 'asc')
                    ->limit(1)
                    ->get();
                return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
            }
        }

    }

    //settLogo settHotline settMuaho settVanchuyen settQD settHT
    public function settLogo(Request $rq) {
        $check = Settings::where('name', 'dataLogo')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $checkContent = array_values($check)[0];
            $cat = Settings::find($checkId);
            $cat->name = 'dataLogo';
            $file_path = public_path('uploads/commons/').$checkContent;
            if ($rq->hasFile('logo')) {
                if (file_exists($file_path))
                {
                    unlink($file_path);
                }

                $f = $rq->file('logo')->getClientOriginalName();
                $filename = time().'_'.$f;
                $cat->content = $filename;
                $rq->file('logo')->move('uploads/commons/',$filename);
            }
            $cat->save();

        } else {
            $item = new Settings();
            $f = $rq->file('logo')->getClientOriginalName();
            $filename = time().'_'.$f;
            $item->name = 'dataLogo';
            $item->content = $filename;
            $rq->file('logo')->move('uploads/commons/',$filename);
            $item->save();
        }
        return redirect()->route('getsettings');
    }

    public function settHotline(Request $rq) {
        $check = Settings::where('name', 'dataHotline')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataHotline';
            $cat->content = $rq->hotline;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataHotline';
            $item->content = $rq->hotline;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settMuaho(Request $rq) {
        $check = Settings::where('name', 'dataKM')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataKM';
            $cat->content = $rq->muaho;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataKM';
            $item->content = $rq->muaho;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settVanchuyen(Request $rq) {
        $check = Settings::where('name', 'dataVC')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataVC';
            $cat->content = $rq->vanchuyen;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataVC';
            $item->content = $rq->vanchuyen;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settKMVC(Request $rq) {
        $check = Settings::where('name', 'dataKMVC')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataKMVC';
            $cat->content = $rq->kmvanchuyen;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataKMVC';
            $item->content = $rq->kmvanchuyen;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settMinDiscount(Request $rq) {
        $check = Settings::where('name', 'dataDiscount')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataDiscount';
            $cat->content = $rq->mindiscount;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataDiscount';
            $item->content = $rq->mindiscount;
            $item->save();
        }

        return redirect()->route('getsettings');
    }
    
    public function settQD(Request $rq) {
        $check = Settings::where('name', 'dataQD')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataQD';
            $cat->content = $rq->quydinh;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataQD';
            $item->content = $rq->quydinh;
            $item->save();
        }

        return redirect()->route('getsettings');
    }
    public function settHT(Request $rq) {
        $check = Settings::where('name', 'dataHT')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataHT';
            $cat->content = $rq->hotro;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataHT';
            $item->content = $rq->hotro;
            $item->save();
        }

        return redirect()->route('getsettings');
    }


    public function getsettings()
    {
        return View ('back.settings-list', $this->getDataSetting());
    }


    public function getDataSetting() {
        $data = Settings::all();
        $dataQD = Settings::where('name', 'dataQD')->get(['content'])->toArray();
        $dataHT = Settings::where('name', 'dataHT')->get(['content'])->toArray();
        $dataLogo = Settings::where('name', 'dataLogo')->get(['content'])->toArray();
        $dataKM = Settings::where('name', 'dataKM')->get(['content'])->toArray();
        $dataVC = Settings::where('name', 'dataVC')->get(['content'])->toArray();
        $dataKMVC = Settings::where('name', 'dataKMVC')->get(['content'])->toArray();
        $dataHotline = Settings::where('name', 'dataHotline')->get(['content'])->toArray();
        $dataDiscount = Settings::where('name', 'dataDiscount')->get(['content'])->toArray();
        return ['data'=>$data,
            'dataQD'=> $dataQD,
            'dataHT' => $dataHT,
            'dataLogo' => $dataLogo,
            'dataKM' => $dataKM,
            'dataVC' => $dataVC,
            'dataHotline' => $dataHotline,
            'dataKMVC'=> $dataKMVC,
            'dataDiscount'=> $dataDiscount
        ];
    }

    public function showOrder($id) {
        if (Auth::check()) $user = Auth::user()->id;
        $transctionId =  Transaction::where('user_id', $user)->where('id', $id)->first();
        $dataTransaction = Transaction::whereId($transctionId->id)->firstOrFail();
        $dataTranDrugArrs = TransactionDrug::where('transaction_id', $transctionId->id)->orderBy('drug_id', 'desc')->get();

        $currentPage = LengthAwarePaginator::resolveCurrentPage();
        $col = new Collection($dataTranDrugArrs);

        // fix test pagination
        $perPage = 15;
        $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
        $dataTranDrugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage,[ 'path' => LengthAwarePaginator::resolveCurrentPath()]);


        $drugs = Drug::orderBy('name', 'asc')->get();
        return view( 'front.orderview', compact('dataTransaction', 'dataTranDrugs', 'drugs', 'id') );

    }
    public function searchData(Request $request)
    {
        $keyword = $request->input('txtkeyword');
        $drugSearchs = \DB::table('drugs')->where('name', 'LIKE', '%' . $keyword . '%')->orWhere('code', 'LIKE', '%' . $keyword . '%')
            ->orWhere('content', 'LIKE', '%' . $keyword . '%')
            ->orWhere('activeIngredient', 'LIKE', '%' . $keyword . '%')
            ->orWhere('design', 'LIKE', '%' . $keyword . '%')
            ->orWhere('produceCompany', 'LIKE', '%' . $keyword . '%')
            ->orWhere('produceCountry', 'LIKE', '%' . $keyword . '%')
            ->orWhere('donvibuon', 'LIKE', '%' . $keyword . '%')
            ->orWhere('donvile', 'LIKE', '%' . $keyword . '%')->get();
        $drugArrSearch = array();
        foreach($drugSearchs as $row) {
            $drugArrSearch[] = $row->id;
        }

        $mind = Mind::where('end_time', '>',  date("Y-m-d H:i:s") )
            ->where('start_time', '<',  date("Y-m-d H:i:s") )
            ->where('status', '1' )
            ->orderBy('start_time', 'asc')
            ->limit(1)
            ->get(['id']);
        
        if (count($mind)) {
            $drug = Mind::whereId($mind[0]->id)->firstOrFail();

            $drugArr = array();
            if (count($drug->mind_drugs)) {
                $drugItem = array();
                foreach ($drug->mind_drugs as $row) {
                    if (in_array($row->drug_id, $drugArrSearch)) {
                        $drugItem['drug_id'] = $row->drug_id;
                        $drugItem['drug_price'] = $row->drug_price;
                        $drugItem['drug_special_price'] = $row->drug_special_price;
                        $drugItem['max_discount_qty'] = $row->max_discount_qty;
                        $drugItem['max_qty'] = $row->max_qty;
                        $drugItem['note'] = $row->note;
                        $drugItem['status'] = $row->status;
                        $drugItem['drugInfo'] = $this->getDrugInfo($row->drug_id);
                        $drugItem['drugImage'] = $this->getDrugImage($row->drug_id);
                        $drugArr[] = $drugItem;
                    }
                }
            }

            // sort
            $price = array();
            foreach ($drugArr as $key => $row) {
                $price[$key] = $row['drug_special_price'];
            }
            array_multisort($price, SORT_DESC, $drugArr);

            //dd($drugArr);
            //$products =  $query->paginate(15);

            $currentPage = LengthAwarePaginator::resolveCurrentPage();
            $col = new Collection($drugArr);

            // fix test pagination
            $perPage = 12;
            $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
            $drugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]);

            $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                ->where('status', '1')
                ->orderBy('start_time', 'asc')
                ->limit(1)
                ->get();
            $isCheckMind = false;
            return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
        }

    }

    // test pdf
    public function doPdf() {
        $data = array(
            'title' => 'Title page'
        );
        $pdf = PDF::loadView('pdf.invoice', $data);
        return $pdf->download('invoice.pdf');
    }

    public function getQuydinh(){
        $content = ProcessText::getConfig('dataQD');
        return view( 'front.static', compact('content') );
    }

    public function getHotro(){
        $content = ProcessText::getConfig('dataHT');
        return view( 'front.static', compact('content') );
    }

    public function getProfile() {
        $content = 'Noi dung profile';<commit_msg>Fix bug - search<commit_after><?php

namespace App\Http\Controllers;


use App\Models\Mind;
use App\Models\Mind_Drug;
use App\Models\Drug;
use App\Models\Drug_img;
use App\Models\Customer;
use App\Models\Transaction;
use App\Models\TransactionDrug;

use App\Models\Discount;

use App\Settings;

use Illuminate\Support\Facades\Auth;

use Illuminate\Http\Request;

use DateTime;

use PDF;

use App\Helpers\ProcessText;


use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;

class HomeController extends Controller
{
    /**
     * Display the home page.
     *
     * @return Response
     */
    public function index()
    {
        $mind = Mind::where('end_time', '>',  date("Y-m-d H:i:s") )
            ->where('start_time', '<',  date("Y-m-d H:i:s") )
            ->where('status', '1' )
            ->orderBy('start_time', 'asc')
            ->limit(1)
            ->get(['id']);
        if (count($mind)) {
            $drug = Mind::whereId($mind[0]->id)->firstOrFail();

            $drugArr = array();
            if (count($drug->mind_drugs)) {
                $drugItem = array();
                foreach($drug->mind_drugs as $row) {
                    $drugItem['drug_id'] = $row->drug_id;
                    $drugItem['drug_price'] = $row->drug_price;
                    $drugItem['drug_special_price'] = $row->drug_special_price;
                    $drugItem['max_discount_qty'] = $row->max_discount_qty;
                    $drugItem['max_qty'] = $row->max_qty;
                    $drugItem['note'] = $row->note;
                    $drugItem['status'] = $row->status;
                    $drugItem['drugInfo'] = $this->getDrugInfo($row->drug_id);
                    $drugItem['drugImage'] = $this->getDrugImage($row->drug_id);
                    $drugArr[] = $drugItem;
                }
            }

            // sort
            $price = array();
            foreach ($drugArr as $key => $row)
            {
                $price[$key] = $row['drug_special_price'];
            }
            array_multisort($price, SORT_DESC, $drugArr);

            //dd($drugArr);
            //$products =  $query->paginate(15);

            $currentPage = LengthAwarePaginator::resolveCurrentPage();
            $col = new Collection($drugArr);

            // fix test pagination
            $perPage = 12;
            $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
            $drugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage,[ 'path' => LengthAwarePaginator::resolveCurrentPath()]);



            $nextMind = Mind::where('start_time', '>',  date("Y-m-d H:i:s") )
                ->where('status', '1' )
                ->orderBy('start_time', 'asc')
                ->limit(1)
                ->get();
            $isCheckMind = false;
            return view( 'front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind') );
        } else {

            $mind = Mind::where('end_time', '<',  date("Y-m-d H:i:s") )
                ->where('status', '1' )
                ->orderBy('end_time', 'desc')
                ->limit(1)
                ->get(['id']);
            if (count($mind)) {
                $drug = Mind::whereId($mind[0]->id)->firstOrFail();
                $drugArr = array();
                if (count($drug->mind_drugs)) {
                    $drugItem = array();
                    foreach ($drug->mind_drugs as $row) {
                        $drugItem['drug_id'] = $row->drug_id;
                        $drugItem['drug_price'] = $row->drug_price;
                        $drugItem['drug_special_price'] = $row->drug_special_price;
                        $drugItem['max_discount_qty'] = $row->max_discount_qty;
                        $drugItem['max_qty'] = $row->max_qty;
                        $drugItem['note'] = $row->note;
                        $drugItem['status'] = $row->status;
                        $drugItem['drugInfo'] = $this->getDrugInfo($row->drug_id);
                        $drugItem['drugImage'] = $this->getDrugImage($row->drug_id);
                        $drugArr[] = $drugItem;
                    }
                }

                $currentPage = LengthAwarePaginator::resolveCurrentPage();
                $col = new Collection($drugArr);

                // fix test pagination
                $perPage = 12;
                $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
                $drugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]);

                //$products =  $query->paginate(15);

                $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                    ->where('status', '1')
                    ->orderBy('start_time', 'asc')
                    ->limit(1)
                    ->get();

                $isCheckMind = true;
                return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
            } else{
                $isCheckMind = true;
                $drugs = array();
                $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                    ->where('status', '1')
                    ->orderBy('start_time', 'asc')
                    ->limit(1)
                    ->get();
                return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
            }
        }

    }

    //settLogo settHotline settMuaho settVanchuyen settQD settHT
    public function settLogo(Request $rq) {
        $check = Settings::where('name', 'dataLogo')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $checkContent = array_values($check)[0];
            $cat = Settings::find($checkId);
            $cat->name = 'dataLogo';
            $file_path = public_path('uploads/commons/').$checkContent;
            if ($rq->hasFile('logo')) {
                if (file_exists($file_path))
                {
                    unlink($file_path);
                }

                $f = $rq->file('logo')->getClientOriginalName();
                $filename = time().'_'.$f;
                $cat->content = $filename;
                $rq->file('logo')->move('uploads/commons/',$filename);
            }
            $cat->save();

        } else {
            $item = new Settings();
            $f = $rq->file('logo')->getClientOriginalName();
            $filename = time().'_'.$f;
            $item->name = 'dataLogo';
            $item->content = $filename;
            $rq->file('logo')->move('uploads/commons/',$filename);
            $item->save();
        }
        return redirect()->route('getsettings');
    }

    public function settHotline(Request $rq) {
        $check = Settings::where('name', 'dataHotline')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataHotline';
            $cat->content = $rq->hotline;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataHotline';
            $item->content = $rq->hotline;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settMuaho(Request $rq) {
        $check = Settings::where('name', 'dataKM')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataKM';
            $cat->content = $rq->muaho;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataKM';
            $item->content = $rq->muaho;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settVanchuyen(Request $rq) {
        $check = Settings::where('name', 'dataVC')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataVC';
            $cat->content = $rq->vanchuyen;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataVC';
            $item->content = $rq->vanchuyen;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settKMVC(Request $rq) {
        $check = Settings::where('name', 'dataKMVC')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataKMVC';
            $cat->content = $rq->kmvanchuyen;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataKMVC';
            $item->content = $rq->kmvanchuyen;
            $item->save();
        }

        return redirect()->route('getsettings');
    }

    public function settMinDiscount(Request $rq) {
        $check = Settings::where('name', 'dataDiscount')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataDiscount';
            $cat->content = $rq->mindiscount;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataDiscount';
            $item->content = $rq->mindiscount;
            $item->save();
        }

        return redirect()->route('getsettings');
    }
    
    public function settQD(Request $rq) {
        $check = Settings::where('name', 'dataQD')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataQD';
            $cat->content = $rq->quydinh;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataQD';
            $item->content = $rq->quydinh;
            $item->save();
        }

        return redirect()->route('getsettings');
    }
    public function settHT(Request $rq) {
        $check = Settings::where('name', 'dataHT')->lists( 'content', 'id')->toArray();
        if ($check) {
            $checkId = key($check);
            $cat = Settings::find($checkId);
            $cat->name = 'dataHT';
            $cat->content = $rq->hotro;
            $cat->save();

        } else {
            $item = new Settings();
            $item->name = 'dataHT';
            $item->content = $rq->hotro;
            $item->save();
        }

        return redirect()->route('getsettings');
    }


    public function getsettings()
    {
        return View ('back.settings-list', $this->getDataSetting());
    }


    public function getDataSetting() {
        $data = Settings::all();
        $dataQD = Settings::where('name', 'dataQD')->get(['content'])->toArray();
        $dataHT = Settings::where('name', 'dataHT')->get(['content'])->toArray();
        $dataLogo = Settings::where('name', 'dataLogo')->get(['content'])->toArray();
        $dataKM = Settings::where('name', 'dataKM')->get(['content'])->toArray();
        $dataVC = Settings::where('name', 'dataVC')->get(['content'])->toArray();
        $dataKMVC = Settings::where('name', 'dataKMVC')->get(['content'])->toArray();
        $dataHotline = Settings::where('name', 'dataHotline')->get(['content'])->toArray();
        $dataDiscount = Settings::where('name', 'dataDiscount')->get(['content'])->toArray();
        return ['data'=>$data,
            'dataQD'=> $dataQD,
            'dataHT' => $dataHT,
            'dataLogo' => $dataLogo,
            'dataKM' => $dataKM,
            'dataVC' => $dataVC,
            'dataHotline' => $dataHotline,
            'dataKMVC'=> $dataKMVC,
            'dataDiscount'=> $dataDiscount
        ];
    }

    public function showOrder($id) {
        if (Auth::check()) $user = Auth::user()->id;
        $transctionId =  Transaction::where('user_id', $user)->where('id', $id)->first();
        $dataTransaction = Transaction::whereId($transctionId->id)->firstOrFail();
        $dataTranDrugArrs = TransactionDrug::where('transaction_id', $transctionId->id)->orderBy('drug_id', 'desc')->get();

        $currentPage = LengthAwarePaginator::resolveCurrentPage();
        $col = new Collection($dataTranDrugArrs);

        // fix test pagination
        $perPage = 15;
        $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
        $dataTranDrugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage,[ 'path' => LengthAwarePaginator::resolveCurrentPath()]);


        $drugs = Drug::orderBy('name', 'asc')->get();
        return view( 'front.orderview', compact('dataTransaction', 'dataTranDrugs', 'drugs', 'id') );

    }
    public function searchData(Request $request)
    {
        $keyword = $request->input('txtkeyword');
        $drugSearchs = \DB::table('drugs')->where('name', 'LIKE', '%' . $keyword . '%')->orWhere('code', 'LIKE', '%' . $keyword . '%')
            ->orWhere('content', 'LIKE', '%' . $keyword . '%')
            ->orWhere('activeIngredient', 'LIKE', '%' . $keyword . '%')
            ->orWhere('design', 'LIKE', '%' . $keyword . '%')
            ->orWhere('produceCompany', 'LIKE', '%' . $keyword . '%')
            ->orWhere('produceCountry', 'LIKE', '%' . $keyword . '%')
            ->orWhere('donvibuon', 'LIKE', '%' . $keyword . '%')
            ->orWhere('donvile', 'LIKE', '%' . $keyword . '%')->get();
        $drugArrSearch = array();
        foreach($drugSearchs as $row) {
            $drugArrSearch[] = $row->id;
        }

        $mind = Mind::where('end_time', '>',  date("Y-m-d H:i:s") )
            ->where('start_time', '<',  date("Y-m-d H:i:s") )
            ->where('status', '1' )
            ->orderBy('start_time', 'asc')
            ->limit(1)
            ->get(['id']);
        
        if (count($mind)) {
            $drug = Mind::whereId($mind[0]->id)->firstOrFail();

            $drugArr = array();
            if (count($drug->mind_drugs)) {
                $drugItem = array();
                foreach ($drug->mind_drugs as $row) {
                    if (in_array($row->drug_id, $drugArrSearch)) {
                        $drugItem['drug_id'] = $row->drug_id;
                        $drugItem['drug_price'] = $row->drug_price;
                        $drugItem['drug_special_price'] = $row->drug_special_price;
                        $drugItem['max_discount_qty'] = $row->max_discount_qty;
                        $drugItem['max_qty'] = $row->max_qty;
                        $drugItem['note'] = $row->note;
                        $drugItem['status'] = $row->status;
                        $drugItem['drugInfo'] = $this->getDrugInfo($row->drug_id);
                        $drugItem['drugImage'] = $this->getDrugImage($row->drug_id);
                        $drugArr[] = $drugItem;
                    }
                }
            }

            // sort
            $price = array();
            foreach ($drugArr as $key => $row) {
                $price[$key] = $row['drug_special_price'];
            }
            array_multisort($price, SORT_DESC, $drugArr);

            //dd($drugArr);
            //$products =  $query->paginate(15);

            $currentPage = LengthAwarePaginator::resolveCurrentPage();
            $col = new Collection($drugArr);

            // fix test pagination
            $perPage = 12;
            $currentPageSearchResults = $col->slice(($currentPage - 1) * $perPage, $perPage)->all();
            $drugs = new LengthAwarePaginator($currentPageSearchResults, count($col), $perPage, $currentPage, ['path' => LengthAwarePaginator::resolveCurrentPath()]);

            $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                ->where('status', '1')
                ->orderBy('start_time', 'asc')
                ->limit(1)
                ->get();
            $isCheckMind = false;
            return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
        } else {
            $isCheckMind = true;
            $drugs = array();
            $nextMind = Mind::where('start_time', '>', date("Y-m-d H:i:s"))
                ->where('status', '1')
                ->orderBy('start_time', 'asc')
                ->limit(1)
                ->get();
            return view('front.index', compact('mind', 'drugs', 'nextMind', 'isCheckMind'));
        }

    }

    // test pdf
    public function doPdf() {
        $data = array(
            'title' => 'Title page'
        );
        $pdf = PDF::loadView('pdf.invoice', $data);
        return $pdf->download('invoice.pdf');
    }

    public function getQuydinh(){
        $content = ProcessText::getConfig('dataQD');
        return view( 'front.static', compact('content') );
    }

    public function getHotro(){
        $content = ProcessText::getConfig('dataHT');
        return view( 'front.static', compact('content') );
    }

    public function getProfile() {
        $content = 'Noi dung profile';
{'fraction_non_alphanumeric': 0.18191619558249314, 'fraction_numerical': 0.00215630281484935, 'mean_word_length': 1.8412120208626541, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 494, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2485171', 'n_tokens_mistral': 10446, 'n_tokens_neox': 9904, 'n_words': 1676}