IMMREX7

aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Student/
File Up :
aku nok ndi : /home/spdtg/www/schoolmis/app/Http/Controllers/Student/CanteenController.php

<?php

namespace App\Http\Controllers\Student;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use Session;
use App\Http\Billdesk;
use Carbon\Carbon;
use \App\Http\TransactionResponseBean;
use Auth;
use PDF;

class CanteenController extends StudentController {

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request) {
        $student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
        $school = \App\School::where('idSchool', '=', $student->idSchool)->first();
        $classes = \App\ClassM::select('idClass','className')->where('idSchool', '=', $student->idSchool)->get();
        $className =  \App\ClassM::where('idClass', '=', $student->idClass)->first()->className;

        $isBookAllowed = "Y";
        $maxBuy = 3;
        $now = Carbon::now();
        $cart =  DB::table('order_cart_food')->where('idStudent','=', Session::get('idStudent'))->pluck('qty','idProduct')->toArray();
        $idFood = DB::table('food_stock')->whereDate('food_date',$now->format('Y-m-d'))->get()->pluck('idFood')->toArray();
        $products =  \App\Food::select('id as idProduct','item_name as productName','pic as productImage','price as salePrice','idSchool','max_buy as max')
        ->where('idSchool', '=', $student->idSchool)
        ->where('idFinancialYear', '=', $student->idFinancialYear)->whereIn('id',$idFood);

        if($request->search != null){
            $products = $products->where('item_name', 'LIKE', $request->search.'%');
        }else{
            $products = $products->where('item_name', 'LIKE', $className.'%');
        }
        $products = $products->get();

        if(count($products) == 0){
            $products =  \App\Food::select('id as idProduct','item_name as productName','pic as productImage','price as salePrice','idSchool','max_buy as max')
            ->where('idSchool', '=', $student->idSchool)
            ->where('idFinancialYear', '=', $student->idFinancialYear)->whereIn('id',$idFood)->get();
            return view('students.foods', compact('student','products','classes','isBookAllowed','maxBuy','school','cart'));
        }
        else
            return view('students.foods', compact('student','products','classes','isBookAllowed','maxBuy','school','cart'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request) {
        //
        
        $student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
        if($request->has('removeItem') && $request->removeItem != null){
            DB::table('order_cart_food')->where('idStudent','=', Session::get('idStudent'))->where('idCart',base64_decode($request->removeItem))->delete();
        }
        $school = \App\School::where('idSchool', '=', $student->idSchool)->first();
        $cart = DB::table('order_cart_food')->where('idStudent','=', Session::get('idStudent'))->get();
        $mode = "eazebuzz";

        return view('students.checkout-canteen', compact('student','school','cart','mode'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request) {
        
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id) {
        //
        $student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
        $school = \App\School::where('idSchool', '=', $student->idSchool)->first();
        $transaction = \App\FoodTransaction::where('idTransaction', '=', $id)->first();
        $pdf = PDF::loadView('schools.transaction.print_receipt_food', ['margin_top' => 20], compact('transaction', 'school', 'student'));
        return $pdf->stream('feereceipt.pdf');
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id) {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id) {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id) {
        //
    }

    public function showPurchases(){
        $transactions =  \App\FoodTransaction::join('students', 'food_transaction.idStudent', '=', 'students.idStudent')
        ->join('classes', 'students.idClass', '=', 'classes.idClass')
        ->join('sections', 'students.idSection', '=', 'sections.idSection')
        ->where('food_transaction.idStudent', '=', Session::get('idStudent'))
        ->where(function($query) {
            $query->whereNull('status');
            $query->orWhere('status', '=', 'In-Process');
            $query->orWhere('status', '=', 'Cleared');
            $query->orWhere('status', '=', 'Success');
        })
        ->select('ecNo', 'food_transaction.idTransaction', 'food_transaction.idFinancialYear','is_received', 'students.idClass', 'students.idStudent', 'students.idSection', 'firstName', 'middleName', 'contactPersonMobile', 'lastName', 'className', 'sectionName', 'father_fname', 'father_mobile', 'father_lname', 'receiptNo', 'paymentMode', 'totalPaid', 'discount', 'paymentDate');
        $transactions = $transactions->get();

        return view('students.food_mhws',compact('transactions'));
    }

    public function addCart(Request $request){
        $student = \App\AdmEntry::where('idStudent', '=', Session::get('idStudent'))->first();
        $qty = 0;
        $cart = DB::table('order_cart_food')->where('idStudent','=', Session::get('idStudent'))->where('idProduct','=',$request->idProduct)->first();
        if($cart == null && $request->action == "minus"){
            $response = array(
                "qty" => $qty,
                "result" => 0
            );
            return json_encode($response);
        }else
        if($cart == null && $request->action == "add"){
            $qty = 1;
            $values = array(
                'idSchool' => $student->idSchool,
                'idStudent' => Session::get('idStudent'), 
                'idProduct' => $request->idProduct,
                'qty' => $qty);
            DB::table('order_cart_food')->insert($values);
        }else{
            $qty = $cart->qty;
            if($request->action == "add"){
                $qty = $qty + 1;
                if($qty < 4){
                    $values = array(
                        'qty' => $qty);
                    DB::table('order_cart_food')->where('idCart','=', $cart->idCart)->update($values);
                }
            }else {
                $qty = $qty - 1;
                if($qty > 0)
                {
                    $values = array(
                        'qty' => $qty);
                    DB::table('order_cart_food')->where('idCart','=', $cart->idCart)->update($values);
                }else DB::table('order_cart_food')->where('idCart','=', $cart->idCart)->delete();
            }
        }
        $response = array(
            "qty" => $qty,
            "count" => DB::table('order_cart_food')->where('idStudent','=', Session::get('idStudent'))->selectRaw('SUM(qty) as qty')->first()->qty,
            "result" => 1
        );
        return json_encode($response);
    }
}

Copyright © 2021 - 2025 IMMREX7