<?php

namespace App\Http\Controllers;

use App\Cawangan;
use App\Tunai;
use App\Gadai;
use App\AddTunai;
use App\Audit;
use App\RequestTeller;
use App\Denominasi;
use App\Vault;
use Auth0\SDK\API\Management\Users;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class TunaiController extends Controller
{



    public function listTunai($kodcaw)
    {
        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $tunai=Tunai::on($cawangan['mysql'])->where([['kodcaw','=',$kodcaw],['tarikh','=',$current->toDateString()]])->orderBy('tarikh','desc')->get();
        return response()->json($tunai);

    }


    public function countgadaidantebus($kodcaw)
    {
        $current = Carbon::now();
        $current = new Carbon();

        $array_GT = [];

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $gadaicount=Gadai::on($cawangan['mysql'])->where([['sttebus','=',''],['t_gadai','=',$current->toDateString()]])->count();
        $gadaijumlah=Gadai::on($cawangan['mysql'])->where([['sttebus','=',''],['t_gadai','=',$current->toDateString()]])->sum('pinjaman');

        $tebuscount=Gadai::on($cawangan['mysql'])->where([['sttebus','=','T'],['t_gadai','=',$current->toDateString()]])->count();
        $tebusjumlah=Gadai::on($cawangan['mysql'])->where([['sttebus','=','T'],['t_gadai','=',$current->toDateString()]])->sum('pinjaman');

        array_push($array_GT,['gcount' => $gadaicount, 'gjumlah' => $gadaijumlah, 'tcount' => $tebuscount, 'tjumlah' => $tebusjumlah]);

        return response()->json($array_GT);
    }


    public function sumBakiTunai($kodcaw)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $tunai=Tunai::on($cawangan['mysql'])->where('tarikh','=',$current->toDateString())->sum('baki');

        return response()->json($tunai);

    }

    public function UpdateTunai($kodcaw, Request $request)
    {
        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $updatetunai=Tunai::on($cawangan['mysql'])->where( [['tarikh','=', $current->toDateString()],['kodlaluan','=', $request->kodlaluan] ])->
        update(array(
             'tambah'=>$request->tambah,
              'kurang'=>$request->kurang,
              'baki'=>$request->bakiakhir
        ));

        return response()->json($updatetunai, 200);
    }

    public function UpdateTunaiGadaianTebus($kodcaw, Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $updatetunai = Tunai::on($cawangan['mysql'])->where( [['tarikh','=', $current->toDateString()],['kodlaluan','=', $request->kodlaluan] ])->
        update(array(
             'keluar'=>$request->keluar,
              'masuk'=>$request->masuk,
              'baki'=>$request->bakiakhir
        ));

        return response()->json($updatetunai, 200);


    }




    public function DaftarTunai($kodcaw, Request $request)
    {


        $current = Carbon::now();
        $current = new Carbon();



        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $tunai=Tunai::on($cawangan['mysql'])->create([

           'tarikh' => $current->toDateString(),
           'kodcaw'=> $request->kodcaw,
           'kodlaluan'=>$request->teller,
           'bakiawal'=>$request->bakiawal,
           'masuk'=>$request->masuk,
           'yuran'=>$request->yuran,
           'keluar'=>$request->keluar,
           'baki'=>$request->baki,
           'tambah'=>$request->tambah,
           'kurang'=>$request->kurang

      ]);

      return response()->json($tunai,201);

    }

    public function getCurrentTunai($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $tunai=Tunai::on($cawangan['mysql'])
        ->where([['kodcaw','=',$kodcaw],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->kodlaluan]])
        ->orderBy('tarikh','desc')
        ->first();
        return response()->json($tunai)
                            ->withHeaders([
                                'Pragma' => 'no-cache',
                                'Cache-Control' => 'no-store',
                                'Expires' => 'Mon, 01 Jan 1990 00:00:00 GMT',
                            ]);

        $audit = new Audit();
        $audit->users = $request->teller;
        $audit->actions = "test";
        $audit->new_data = $tunai;
        $audit->kodcaw = $kodcaw;
        $audit->created_at = $current;
        $audit->updated_at = $current;
        $audit->save();

        return response()->json();

    }

    public function getTunaiByTarikh(Request $request)
    {
        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();

        $tunai = Tunai::on($cawangan['mysql'])
        ->where([['kodcaw','=',$request->kodcaw],
                 ['tarikh','=',$request->tarikh],
                 ['kodlaluan','=',$request->kodlaluan]
                ])
        ->orderBy('tarikh','desc')
        ->first();

        return response()->json($tunai);
    }

    public function getTunaiPast($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $tunai=Tunai::on($cawangan['mysql'])
        ->where([['kodcaw','=',$kodcaw],['tarikh','<',$current->toDateString()],['kodlaluan','=',$request->kodlaluan]])
        ->orderBy('tarikh','desc')
        ->get();

        return response()->json($tunai);

    }

    public function getLatestTunai($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $tunai=Tunai::on($cawangan['mysql'])
        ->where([['kodcaw','=',$kodcaw],['tarikh','<',$current->toDateString()],['kodlaluan','=',$request->kodlaluan]])
        ->orderBy('tarikh','desc')
        ->get();
        return response()->json($tunai);

    }

     ///API FARIS


    public function create($kodcaw,Request $request)
    {
        $current = Carbon::now();
        $current = new Carbon();
        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        //Same Note e.g P1 and S1
        $same_note = AddTunai::on($cawangan['mysql'])
            ->where('kodlaluan', $request->kodlaluan)
            ->where('nota',$request->nota)
            ->where('tarikh',$current->toDateString())->first();

        if($same_note){
            Log::error('Error: same-note :' . $kodcaw . ': Name :' . $request->kodlaluan);
            return 'same-note';
        }

        //Time Interval
        $latestRecord = AddTunai::on($cawangan['mysql'])->where('kodlaluan', $request->kodlaluan)->latest()->first();
        if($latestRecord){
            $time = Carbon::parse($latestRecord->created_at);
            $time_end = $time->copy()->addMinutes(1);
          
            if($current->between($time,$time_end)){
                Log::error('Error: within 1 minute :' . $kodcaw . ': Name :' . $request->kodlaluan);
                return 'within 1 minute';
            }
        }

        $addtunai=AddTunai::on($cawangan['mysql'])->create([

            'tarikh' => $current->toDateString(),
            'kodcaw'=> $request->kodcaw,
            'kodlaluan'=>$request->kodlaluan,
            'tambah'=>$request->tambah,
            'kurang'=>$request->kurang,
            'nota'=>$request->nota,
            'created_at'=>$current
        ]);

        return response()->json($addtunai,201);

    }

    public function getAddTunai($kodcaw)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $addtunai=AddTunai::on($cawangan['mysql'])->where([['kodcaw','=',$kodcaw],['tarikh','=',$current->toDateString()]])->get();
        return response()->json($addtunai);
    }

    public function getAddTunaiDate($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $addtunai=AddTunai::on($cawangan['mysql'])->where([['kodcaw','=',$kodcaw],['tarikh','=',$request->tarikh]])->get();
        return response()->json($addtunai);
    }


    public function getAddTunaibyKodlaluan($kodcaw,Request $request)
    {
        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
        $addtunai=AddTunai::on($cawangan['mysql'])->where([['kodcaw','=',$kodcaw],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->kodlaluan]])->get();
        return response()->json($addtunai);
    }

    public function getAddTunaibyKodlaluanLatest($kodcaw,Request $request)
    {
        $current = Carbon::now();
        $current = new Carbon();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        if($request->jenisnota == 'pendahuluan')
        {
            $addtunai=AddTunai::on($cawangan['mysql'])
            ->where([['kodcaw','=',$kodcaw],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->kodlaluan],['tambah','<>',0]])
            ->orderBy('recno','desc')
            ->first();

        }else if($request->jenisnota == 'serahan'){

            $addtunai=AddTunai::on($cawangan['mysql'])
            ->where([['kodcaw','=',$kodcaw],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->kodlaluan],['kurang','<>',0]])
            ->orderBy('recno','desc')
            ->first();

        }

        return response()->json($addtunai);
    }

    public function updateRequestTellerDeno($kodcaw,Request $request){

        $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$kodcaw],['kodlaluan','=',$request->kodlaluan],['update','=',0]])->update(array(
            'update' => 1,
            'bd1' => $request->bd1,
            'bd5' => $request->bd5,
            'bd10' => $request->bd10,
            'bd20' => $request->bd20,
            'bd50' => $request->bd50,
            'bd100' => $request->bd100,
            'txtring1' => $request->txtring1,
            'txtring5' => $request->txtring5,
            'txtring10' => $request->txtring10,
            'txtring20' => $request->txtring20,
            'txtring50' => $request->txtring50,
            'txtring100' => $request->txtring100,
            'txtring1000' => $request->txtring1000,
            'txtsen1' => $request->txtsen1,
            'txtsen5' => $request->txtsen5,
            'txtsen10' => $request->txtsen10,
            'txtsen20' => $request->txtsen20,
            'txtsen50' => $request->txtsen50,
         ) );

        return response()->json($requestteller);
    }

    public function getRequestTeller($kodcaw)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $requestteller=RequestTeller::on('mysql7')->where([['kodcaw','=',$kodcaw],['update','=',0],['tarikh','=',$current->toDateString()]])->get();
        return response()->json($requestteller);
    }

    public function getRequestTellerLaporanSerahan($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $requestteller=RequestTeller::on('mysql7')->where([['kodcaw','=',$kodcaw],['update','=',1],['serahan','>',0],['kodlaluan','=',$request->teller],['tarikh','=',$current->toDateString()]])->get();

        return response()->json($requestteller);
    }

    public function getRequestTellerByRecno($kodcaw,Request $request){
        $current = Carbon::now();
        $current = new Carbon();

        $requestteller=RequestTeller::on('mysql7')->where([['kodcaw','=',$kodcaw],['update','=',1],['recno','=',$request->recno],['kodlaluan','=',$request->teller]])->get();

        return response()->json($requestteller);
    }

    public function getRequestTellerLaporanSerahanBerkala($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $requestteller=RequestTeller::on('mysql7')
                        ->where([['kodcaw','=',$kodcaw],['update','=',1],['serahan','>',0],['kodlaluan','=',$request->teller],['tarikh','=',$current->toDateString()]])
                        ->orderBy('recno','desc')
                        ->first();

        return response()->json($requestteller);
    }

    public function getRequestTellerByDate($kodcaw,Request $request)
    {

        $current = Carbon::now();
        $current = new Carbon();

        $requestteller=RequestTeller::on('mysql7')->where([['kodcaw','=',$kodcaw],['update','=',0],['tarikh','<=',$request->hingga],['tarikh','>=',$request->mula]])->get();
        return response()->json($requestteller);
    }

    public function updateRequestTeller($kodcaw,Request $request)
    {
        $harini = Carbon::now();

        $audit = new Audit();
        $audit->users = isset($request->khazanah) ? $request->khazanah : '' ;
        $audit->norujukan = null;
        $audit->actions = ($request->jenis == 'pendahuluan') ? "Pendahuluan Peti Besi" : "Serahan Peti Besi";
        $audit->kodcaw = $kodcaw;
        $audit->created_at = $harini;
        $audit->updated_at = $harini;
        $audit->save();

        $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$kodcaw],['kodlaluan','=',$request->kodlaluan],['update','=',0]])->update(array(

            'update' => 1

         ) );
    }

    public function batalRequestTeller($kodcaw,Request $request)
    {
        $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$kodcaw],['kodlaluan','=',$request->kodlaluan],['update','=',0]])->update(array(
            'update' => 2
         ));
    }

    public function createRequestTeller($kodcaw,Request $request)
    {


        $current = Carbon::now();
        $current = new Carbon();

        // dd($current->toTimeString());

        // strtotime($current->toTimeString());

        $reqteller=RequestTeller::on('mysql7')->create([

             'tarikh' => $current->toDateString(),
             'masa' => $current->toTimeString(),
             'kodcaw' => $kodcaw,
             'kodlaluan' => $request->kodlaluan,
             'modal' => $request->modal,
             'serahan' => $request->serahan,
             'bd1' => $request->bd1,
             'bd5' => $request->bd5,
             'bd10' => $request->bd10,
             'bd20' => $request->bd20,
             'bd50' => $request->bd50,
             'bd100' => $request->bd100,
             'txtring1' => $request->txtring1,
             'txtring5' => $request->txtring5,
             'txtring10' => $request->txtring10,
             'txtring20' => $request->txtring20,
             'txtring50' => $request->txtring50,
             'txtring100' => $request->txtring100,
             'txtring1000' => $request->txtring1000,
             'txtsen1' => $request->txtsen1,
             'txtsen5' => $request->txtsen5,
             'txtsen10' => $request->txtsen10,
             'txtsen20' => $request->txtsen20,
             'txtsen50' => $request->txtsen50,
             'update' => '0'
        ]);

        $audit = new Audit();
        $audit->users = $request->kodlaluan;
        $audit->actions = ($request->modal == 0) ? "Serahan Modal" : "Pendahuluan Modal";
        $audit->new_data = $reqteller;
        $audit->kodcaw = $kodcaw;
        $audit->created_at = $current;
        $audit->updated_at = $current;
        $audit->save();


        return response()->json($reqteller,200);
    }

    public function getTunaiSemalam($kodcaw)
    {
        $current = new Carbon();
        $current = Carbon::now();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $getdate = Tunai::on($cawangan['mysql'])
            ->select('tarikh')
            ->where('tarikh', '<', $current->toDateString())
            ->orderBy('recno','desc')
            ->first();

        $tunai=Tunai::on($cawangan['mysql'])
            ->where([['kodcaw','=',$kodcaw],['tarikh','=', $getdate['tarikh']],['baki','<>',0]])
            ->GroupBy('kodlaluan')
            ->get();

        return response()->json($tunai);
    }

    public function GetTellerWork($kodcaw)
    {
        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $teller = Tunai::on($cawangan['mysql'])
                    ->select('kodlaluan')
                    ->whereRaw('LENGTH(kodlaluan) > 10')
                    ->orWhere('kodlaluan','=','LELONG')
                    ->distinct()
                    ->get();

        return response()->json($teller);
    }

    public function initiateTunai(Request $request){

        $current = new Carbon();
        $current = Carbon::now();

        if($request->zone == 'all'){
            $cawangan_all = Cawangan::on('mysql7')->get();
        }else{
            $cawangan_all = Cawangan::on('mysql7')->where('zone',$request->zone)->get();
        }

        foreach($cawangan_all as $index=>$cawangan){
            $getdate = Tunai::on($cawangan['mysql'])
                ->select('tarikh')
                ->where('tarikh', '<', $current->toDateString())
                ->orderBy('recno','desc')
                ->first();

            $tunai=Tunai::on($cawangan['mysql'])
                ->where([['kodcaw','=',$cawangan['kodcaw']],['tarikh','=', $getdate['tarikh']],['baki','<>',0]])
                ->GroupBy('kodlaluan')
                ->get();

            if($tunai)
            {
                foreach($tunai as $index=>$tunsem){

                    $latesttunai=Tunai::on($cawangan['mysql'])
                        ->where([['kodcaw','=',$cawangan['kodcaw']],['tarikh','<',$current->toDateString()],['kodlaluan','=',$tunsem['kodlaluan']]])
                        ->orderBy('tarikh','desc')
                        ->first();
                    if($latesttunai)
                    {
                        $tunai=Tunai::on($cawangan['mysql'])->create([
                            'tarikh' => $current->toDateString(),
                            'kodcaw'=> $cawangan['kodcaw'],
                            'kodlaluan'=>$tunsem['kodlaluan'],
                            'bakiawal'=>$tunsem['baki'],
                            'masuk'=>0.00,
                            'yuran'=>0.00,
                            'keluar'=>0.00,
                            'baki'=>$tunsem['baki'],
                            'tambah'=>0.00,
                            'kurang'=>0.00
                        ]);
                    }
                }

                //Denominasi
                $denominasi=Denominasi::on($cawangan['mysql'])->where('tarikh','=',$current->toDateString())->limit(1)->get();

                if(sizeof($denominasi) == 0)
                {
                    $deno = Denominasi::on($cawangan['mysql'])->orderby('tarikh','desc')->first();

                    if($deno)
                    {
                        $savedeno = Denominasi::on($cawangan['mysql'])->create([

                            'tarikh' => $current->toDateString(),
                            'bd1' => $deno['bd1'],
                            'b1' => $deno['b1'],
                            'bd5' => $deno['bd5'],
                            'b5' => $deno['b5'],
                            'bd10' => $deno['bd10'],
                            'b10' => $deno['b10'],
                            'bd20' => $deno['bd20'],
                            'b20' => $deno['b20'],
                            'bd50' => $deno['bd50'],
                            'b50' => $deno['b50'],
                            'bd100' => $deno['bd100'],
                            'b100' => $deno['b100'],
                            'txtring1' => $deno['txtring1'],
                            'k1' => $deno['k1'],
                            'txtring5' => $deno['txtring5'],
                            'k5' => $deno['k5'],
                            'txtsen1' => $deno['txtsen1'],
                            'k01' => $deno['k01'],
                            'txtsen5' => $deno['txtsen5'],
                            'k05' => $deno['k05'],
                            'txtsen10' => $deno['txtsen10'],
                            'k010' => $deno['k010'],
                            'txtsen20' => $deno['txtsen20'],
                            'k020' => $deno['k020'],
                            'txtsen50' => $deno['txtsen50'],
                            'k050' => $deno['k050'],
                            'txtring10' => $deno['txtring10'],
                            'k10' => $deno['k10'],
                            'txtring20' => $deno['txtring20'],
                            'k20' => $deno['k20'],
                            'txtring50' => $deno['txtring50'],
                            'k50' => $deno['k50'],
                            'txtring100' => $deno['txtring100'],
                            'k100' => $deno['k100'],
                            'txtring1000' => $deno['txtring1000'],
                            'k1000' => $deno['k1000'],
                            'jumlahbundle' => $deno['jumlahbundle'],
                            'txtjumlah' => $deno['txtjumlah'],
                            'lebihan' => $deno['lebihan'],
                            'nota' => $deno['nota'],
                            'jumlahkeping' => $deno['jumlahkeping']
                        ]);
                    }else{
                        $savedeno = Denominasi::on($cawangan['mysql'])->create([

                            'tarikh' => $current->toDateString(),
                            'bd1' => 0,
                            'b1' => 0,
                            'bd5' => 0,
                            'b5' => 0,
                            'bd10' => 0,
                            'b10' => 0,
                            'bd20' => 0,
                            'b20' => 0,
                            'bd50' => 0,
                            'b50' => 0,
                            'bd100' => 0,
                            'b100' => 0,
                            'txtring1' => 0,
                            'k1' => 0,
                            'txtring5' => 0,
                            'k5' => 0,
                            'txtsen1' => 0,
                            'k01' => 0,
                            'txtsen5' => 0,
                            'k05' => 0,
                            'txtsen10' => 0,
                            'k010' => 0,
                            'txtsen20' => 0,
                            'k020' => 0,
                            'txtsen50' => 0,
                            'k050' => 0,
                            'txtring10' => 0,
                            'k10' => 0,
                            'txtring20' => 0,
                            'k20' => 0,
                            'txtring50' => 0,
                            'k50' => 0,
                            'txtring100' => 0,
                            'k100' => 0,
                            'txtring1000' => 0,
                            'k1000' => 0,
                            'jumlahbundle' => 0,
                            'txtjumlah' => 0,
                            'lebihan' => 0,
                            'nota' => 0,
                            'jumlahkeping' => 0
                        ]);
                    }
                }

                //Peti Besi Cawangan
                $getVault=Vault::on($cawangan['mysql'])
                    ->where('kodcaw','=',$cawangan['kodcaw'])
                    ->where('tarikh','=',$current->toDateString())
                    ->orderby('tarikh','desc')->limit(1)->get();

                if(sizeof($getVault) == 0)
                {
                    $vault = Vault::on($cawangan['mysql'])->orderby('tarikh','desc')->first();

                    if($vault)
                    {
                        $vaultcreate = Vault::on($cawangan['mysql'])->create([
                            'kodcaw'=>$cawangan['kodcaw'],
                            'tarikh'=> $current->toDateString(),
                            'bakiawal' => $vault['bakiakhir'],
                            'keluar' => 0,
                            'masuk' => 0,
                            'bakiakhir' => $vault['bakiakhir'],
                            'bakieod' => $vault['bakiakhir'],
                            'pendahuluan' => 0,
                            'serahan' => 0,
                            '1sen' => $vault['1sen'],
                            '5sen' => $vault['5sen'],
                            '10sen' => $vault['10sen'],
                            '20sen' => $vault['20sen'],
                            '50sen' => $vault['50sen'],
                            'rm1' => $vault['rm1'],
                            'rm2' => $vault['rm2'],
                            'rm5' => $vault['rm5'],
                            'rm10' => $vault['rm10'],
                            'rm50' => $vault['rm50'],
                            'rm100' => $vault['rm100'],
                            'rm1000' => $vault['rm1000'],
                            'totpanjar' => 0
                        ]);
                    }else{
                        $vaultcreate = Vault::on($cawangan['mysql'])->create([
                            'kodcaw'=>$request->kodcaw,
                            'tarikh'=> $current->toDateString(),
                            'bakiawal' => 0,
                            'keluar' => 0,
                            'masuk' => 0,
                            'bakiakhir' => 0,
                            'bakieod' => 0,
                            'pendahuluan' => 0,
                            'serahan' => 0,
                            '1sen' => 0,
                            '5sen' => 0,
                            '10sen' => 0,
                            '20sen' => 0,
                            '50sen' => 0,
                            'rm1' => 0,
                            'rm2' => 0,
                            'rm5' => 0,
                            'rm10' => 0,
                            'rm50' => 0,
                            'rm100' => 0,
                            'rm1000' => 0,
                            'totpanjar' => 0
                        ]);
                    }
                }

            }
        }
    }

    public function CheckProsesReqTeller(Request $request){
        $current = new Carbon();
        $current = Carbon::now();

        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$request->kodcaw)->first();

        $requestteller=RequestTeller::on('mysql7')
                    ->where([
                        ['kodcaw','=',$request->kodcaw],
                        ['kodlaluan','=',$request->kodlaluan],
                        ['update','=',0],
                        ['tarikh','=',$current->toDateString()]
                        ])
                    ->get();

        return response()->json($requestteller);
    }

    public function getAccStatement($kodcaw, Request $request){
        $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();

        $addtunai = AddTunai::on($cawangan['mysql'])->where('tarikh',$request->tarikh)->where('kodlaluan',$request->teller)->get();

        return $addtunai;
    }
}
