<?php

namespace App\Http\Controllers;

use App\HargaEmas;
use App\GlCode;
use App\Cawangan;
use App\GlDetail;

use Illuminate\Http\Request;

use Carbon\Carbon;
use DB;
class GlDetailsController extends Controller
{



public function sum_gldetails($kodcaw)
{

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

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

    $gadai_aging=DB::connection($db)->select("SELECT sum(amaun)as amaun from gldetail where tarikh <= '".$current->toDateString()."' and  tarikh >'2013-12-31' and ktacct = '7000/102'");
    return response()->json($gadai_aging);


}


public function sum_advance_2014($kodcaw)
{

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

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

     $gadai_2014=DB::connection($db)->select("SELECT sum(amaun)as amaun from gldetail where tarikh <= '".$current->toDateString()."' and  tarikh >'2014-12-31' and ktacct = '7000/102'");
    return response()->json($gadai_2014);

}

public function sumJMC_2015($kodcaw)
{

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

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

     $gadai_2015=DB::connection($db)->select("SELECT sum(amaun)as amaun from gldetail where tarikh <= '".$current->toDateString()."' and  tarikh >'2015-01-01' and ktacct = '7000/026'");
    return response()->json($gadai_2015);

}


public function sumJMC_2014($kodcaw)
{

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

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

     $gadai_2014=DB::connection($db)->select("SELECT sum(amaun)as amaun from gldetail where tarikh <= '".$current->toDateString()."' and  tarikh >'2014-01-01' and ktacct = '7000/026'");
    return response()->json($gadai_2014);

}


public function JumlahSerahanHQ($kodcaw)
{

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

    $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
    $db=$cawangan['mysql'];
    $jumlahSerahHQ=DB::connection($db)->select("SELECT sum(amaun)as amaun from gldetail where tarikh <= '".$current->toDateString()."' and  tarikh >'2013-12-31' and ktacct = '1000/102'");
    return response()->json($jumlahSerahHQ);

}

 public function data_imbangduga($kodcaw, $tarikh)
 {
    $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
    $db=$cawangan['mysql'];
     $imbangduga=DB::connection($db)->select("select glcode.glcode, glcode.descpt, glcode.acttype, glcode.tarikh, glcode.amaun, glcode.kodcaw, glcode.jenisakaun, jenisakaun.keterangan,jenisakaun.kod from glcode, jenisakaun where glcode.tarikh='".$tarikh."' and glcode.amaun<>0 and jenisakaun.kod=glcode.acttype order by jenisakaun.kod,  glcode.glcode");
   
     return response()->json($imbangduga);
 }

}