app/Http/Controllers/PhieuNhapHangController.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)
    {
        $phieunhap = new phieuNhapHang();
        $phieunhap->maphieunhap = "PN".strtoupper(uniqid());
        $phieunhap->id_nhacungcap = $request->id_nhacungcap;
        $tongtien = 0;
        $pnh = session()->get('pnh');
        echo "<pre>"; print_r($pnh);
        echo "-----------------------------------------<br>";
        print_r($request->all());
        exit();
        $phieunhap->tongtien = $tongtien;
        $phieunhap->save();
        foreach ($pnh as $id => $item):
            $ctpn = new chiTietPhieuNhapHang();
            $ctpn->id_phieunhaphang = $phieunhap->maphieunhap;
            $ctpn->id_sanpham = $id;
            Cộng dồn số lượng sp
            $sanpham= sanPham::findOrFail($id);
            $sanpham->soluongton += $item['quantity'];
            $sanpham->save();
            $ctpn->soluong = $item['quantity'];
            $ctpn->gianhap = $item['price'];
            $tongtien += $item['quantity']*$item['price'];
            $ctpn->save();
        endforeach;
        $phieunhap->tongtien = $tongtien;
        $phieunhap->save();
        $request->session()->flush();
        return back()->with('success', 'Lưu phiếu nhập thành công!');
    }
public function store ( Request $ request ) { $ phieunhap = new phieuNhapHang ( ) ; $ phieunhap -> maphieunhap = " PN " . strtoupper ( uniqid ( ) ) ; $ phieunhap -> id_nhacungcap = $ request -> id_nhacungcap ; $ tongtien = 0 ; $ pnh = session ( ) -> get ( 'pnh' ) ; $ phieunhap -> tongtien = $ tongtien ; $ phieunhap -> save ( ) ; foreach ( $ pnh as $ id => $ item ) : $ ctpn = new chiTietPhieuNhapHang ( ) ; $ ctpn -> id_phieunhaphang = $ phieunhap -> maphieunhap ; $ ctpn -> id_sanpham = $ id ; $ sanpham = sanPham :: findOrFail ( $ id ) ; $ sanpham -> soluongton += $ item [ 'quantity' ] ; $ sanpham -> save ( ) ; $ ctpn -> soluong = $ item [ 'quantity' ] ; $ ctpn -> gianhap = $ item [ 'price' ] ; $ tongtien += $ item [ 'quantity' ] * $ item [ 'price' ] ; $ ctpn -> save ( ) ; endforeach ; $ phieunhap -> tongtien = $ tongtien ; $ phieunhap -> save ( ) ; $ request -> session ( ) -> flush ( ) ; return back ( ) -> with ( 'success' , 'Lưu phiếu nhập thành công!'); }
Store a newly created resource in storage.
Store a newly created resource in storage .
// //        echo "<pre>"; print_r($pnh); //        echo "-----------------------------------------<br>"; //        print_r($request->all()); //        exit(); //Cộng dồn số lượng sp //