app/Http/Controllers/TransaksiController.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)
    {
        $awal_hari = date("Y-m-d") . 'T00:00:00.000000Z';
        $cek = Transaksi::where('created_at', '>=', $awal_hari)->count();
        $kode_invoice =  'TRX/' . date("Ymd") . '/' . $cek + 1;
        $pengerjaan_terlama = max(array_map(function($value) {
            return $value['lama_pengerjaan'];
        },$request->detail_pemesanan));
        $date = date('Y-m-d H:i:s');
        $batas_waktu = date("Y-m-d H:i:s", strtotime( '+' . $pengerjaan_terlama .' days' . ' +7 hours', strtotime($date)));
        $tgl_bayar = ($request->dibayar == 'Lunas') ? date("Y-m-d H:i:s", strtotime('+7 hours', strtotime($date))) : null ;
        $status = '';
        if ($request->jemput) {
            $status = 'Penjemputan';
        }else{
            $status = 'Antrian';
        }
        $create = Transaksi::create([
            'outlet_id' =>  $request->outlet_id,
            'kode_invoice' =>  $kode_invoice,
            'member_id' => $request->member['id'],
            'tgl' =>  date("Y-m-d H:i:s", strtotime('+7 hours', strtotime($date))),
            'batas_waktu' =>  $batas_waktu,
            'tgl_bayar' => $tgl_bayar,
            'dibayar' =>  $request->dibayar,
            'biaya_tambahan' =>  $request->biaya_tambahan,
            'diskon' =>  $request->diskon,
            'pajak' => $request->pajak,
            'status' =>  $status,
            'user_id' => Auth::user()->id,
            'total' => $request->total,
            'subtotal' => $request->subtotal,
            'penjemputan' => $request->jemput,
            'pengantaran' => $request->antar,
            'lng_lat' => $request->lng_lat != null ? $request->lng_lat[0] . ',' . $request->lng_lat[1] : null,
            'jarak' => $request->jarak,
            'ongkir' => $request->ongkir,
            'dijemput' => 0,
            'diantar' => 0,
            'extra' => $request->extra
        ]);
        $transaksi_id = $create->id;
        foreach ($request->detail_pemesanan as $value) {
            $create = DetailTransaksi::create([
                'transaksi_id' => $transaksi_id,
                'paket_id' => $value['id'],
                'qty' => $value['val'],
                'keterangan' => ''
            ]);
        }
        if($create){
            return response()->json([
                'status' => true
            ]);
        }
        else{
            return response()->json([
                'status' => false
            ]);
        }
    }
public function store ( Request $ request ) { $ awal_hari = date ( " Y-m-d " ) . 'T00:00:00.000000Z' ; $ cek = Transaksi :: where ( 'created_at' , '>=' , $ awal_hari ) -> count ( ) ; $ kode_invoice = 'TRX/' . date ( " Ymd " ) . '/' . $ cek + 1 ; $ pengerjaan_terlama = max ( array_map ( function ( $ value ) { return $ value [ 'lama_pengerjaan' ] ; } , $ request -> detail_pemesanan ) ) ; $ date = date ( 'Y-m-d H:i:s' ) ; $ batas_waktu = date ( " Y-m-d H:i:s " , strtotime ( '+' . $ pengerjaan_terlama . ' days' . ' +7 hours' , strtotime ( $ date ) ) ) ; $ tgl_bayar = ( $ request -> dibayar == 'Lunas' ) ? date ( " Y-m-d H:i:s " , strtotime ( '+7 hours' , strtotime ( $ date ) ) ) : null ; $ status = '' ; if ( $ request -> jemput ) { $ status = 'Penjemputan' ; } else { $ status = 'Antrian' ; } $ create = Transaksi :: create ( [ 'outlet_id' => $ request -> outlet_id , 'kode_invoice' => $ kode_invoice , 'member_id' => $ request -> member [ 'id' ] , 'tgl' => date ( " Y-m-d H:i:s " , strtotime ( '+7 hours' , strtotime ( $ date ) ) ) , 'batas_waktu' => $ batas_waktu , 'tgl_bayar' => $ tgl_bayar , 'dibayar' => $ request -> dibayar , 'biaya_tambahan' => $ request -> biaya_tambahan , 'diskon' => $ request -> diskon , 'pajak' => $ request -> pajak , 'status' => $ status , 'user_id' => Auth :: user ( ) -> id , 'total' => $ request -> total , 'subtotal' => $ request -> subtotal , 'penjemputan' => $ request -> jemput , 'pengantaran' => $ request -> antar , 'lng_lat' => $ request -> lng_lat != null ? $ request -> lng_lat [ 0 ] . ',' . $ request -> lng_lat [ 1 ] : null , 'jarak' => $ request -> jarak , 'ongkir' => $ request -> ongkir , 'dijemput' => 0 , 'diantar' => 0 , 'extra' => $ request -> extra ] ) ; $ transaksi_id = $ create -> id ; foreach ( $ request -> detail_pemesanan as $ value ) { $ create = DetailTransaksi :: create ( [ 'transaksi_id' => $ transaksi_id , 'paket_id' => $ value [ 'id' ] , 'qty' => $ value [ 'val' ] , 'keterangan' => '' ] ) ; } if ( $ create ) { return response ( ) -> json ( [ 'status' => true ] ) ; } else { return response ( ) -> json ( [ 'status' => false ] ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .