app/Http/Controllers/AdminBookingController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $thai_month_arr = array(
            "1" => "มกราคม",
            "2" => "กุมภาพันธ์",
            "3" => "มีนาคม",
            "4" => "เมษายน",
            "5" => "พฤษภาคม",
            "6" => "มิถุนายน",
            "7" => "กรกฎาคม",
            "8" => "สิงหาคม",
            "9" => "กันยายน",
            "10" => "ตุลาคม",
            "11" => "พฤศจิกายน",
            "12" => "ธันวาคม"
        );
        $rules = array(
            'products' => 'required',
            'date' => 'required',
            'productName' => 'required',
            'number' => 'required|integer',
        );
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails())  return redirect('/monthly')->withErrors($validator);
        $user = $request->session()->get('member');
        if ($user == null)  return redirect('/monthly')->withErrors("can not define user.");
        $products = $request->input('products');
        $month = $request->input('date');
        $sql = "SELECT * FROM calendar where date_format(opened_at , '%Y-%m') = date_format('". $month ."' , '%Y-%m') and code = '" . $request->input('code') . "' ";
        $sql .= " order by opened_at";
        $rows = \DB::select($sql);
        $total_price = 0 ;
        foreach ($rows as $key => $row) {
            $row->price = $row->price_type2 * $request->input('number');
            $row->thaidate = $this->thai_date($row->opened_at);
            $total_price += $row->price;
        }
        $quotation = ['products' => $products
            , 'rows' => $rows
            , 'date' => $month
            , 'thai_date' => $thai_month_arr[date("n", strtotime($month))] . ' ' . (date("Y", strtotime($month)) + 543)
            , 'productName' => $request->input('productName')
            , 'total_price' =>  $total_price
        ];
        $request->session()->put('quotation', $quotation);
        $params = $request->session()->get('quotation');
        return view('adminbooking.quotation', ['rows' => $params['rows']
            , 'products' => $params['products']
            , 'productName' => $params['productName']
            , 'thai_date' => $params['thai_date']
            , 'total_price' => $params['total_price']
        ]);
    }
public function store ( Request $ request ) { $ thai_month_arr = array ( " 1 " => " มกราคม", " 2 " => " กุมภาพันธ์", " 3 " => " มีนาคม", " 4 " => " เมษายน", " 5 " => " พฤษภาคม", " 6 " => " มิถุนายน", " 7 " => " กรกฎาคม", " 8 " => " สิงหาคม", " 9 " => " กันยายน", " 10 " => " ตุลาคม", " 11 " => " พฤศจิกายน", " 12 " => " ธันวาคม" ) ; $ rules = array ( 'products' => 'required' , 'date' => 'required' , 'productName' => 'required' , 'number' => 'required|integer' , ) ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) return redirect ( '/monthly' ) -> withErrors ( $ validator ) ; $ user = $ request -> session ( ) -> get ( 'member' ) ; if ( $ user == null ) return redirect ( '/monthly' ) -> withErrors ( " can not define user. " ) ; $ products = $ request -> input ( 'products' ) ; $ month = $ request -> input ( 'date' ) ; $ sql = " SELECT * FROM calendar where date_format(opened_at , '%Y-%m') = date_format(' " . $ month . " ' , '%Y-%m') and code = ' " . $ request -> input ( 'code' ) . " '  " ; $ sql .= "  order by opened_at " ; $ rows = \ DB :: select ( $ sql ) ; $ total_price = 0 ; foreach ( $ rows as $ key => $ row ) { $ row -> price = $ row -> price_type2 * $ request -> input ( 'number' ) ; $ row -> thaidate = $ this -> thai_date ( $ row -> opened_at ) ; $ total_price += $ row -> price ; } $ quotation = [ 'products' => $ products , 'rows' => $ rows , 'date' => $ month , 'thai_date' => $ thai_month_arr [ date ( " n " , strtotime ( $ month ) ) ] . ' ' . ( date ( " Y " , strtotime ( $ month ) ) + 543 ) , 'productName' => $ request -> input ( 'productName' ) , 'total_price' => $ total_price ] ; $ request -> session ( ) -> put ( 'quotation' , $ quotation ) ; $ params = $ request -> session ( ) -> get ( 'quotation' ) ; return view ( 'adminbooking.quotation' , [ 'rows' => $ params [ 'rows' ] , 'products' => $ params [ 'products' ] , 'productName' => $ params [ 'productName' ] , 'thai_date' => $ params [ 'thai_date' ] , 'total_price' => $ params [ 'total_price' ] ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .