319 lines
9.9 KiB
PHP
319 lines
9.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Cawangan;
|
|
use App\Tunai;
|
|
use App\Gadai;
|
|
use App\AddTunai;
|
|
use App\RequestTeller;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
|
|
|
|
$addtunai=AddTunai::on($cawangan['mysql'])->create([
|
|
|
|
'tarikh' => $current->toDateString(),
|
|
'kodcaw'=> $request->kodcaw,
|
|
'kodlaluan'=>$request->kodlaluan,
|
|
'tambah'=>$request->tambah,
|
|
'kurang'=>$request->kurang,
|
|
'nota'=>$request->nota
|
|
]);
|
|
|
|
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 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 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 updateRequestTeller($kodcaw,Request $request)
|
|
{
|
|
$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();
|
|
|
|
$reqteller=RequestTeller::on('mysql7')->create([
|
|
|
|
'tarikh' => $current->toDateString(),
|
|
'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'
|
|
]);
|
|
|
|
return response()->json($reqteller,200);
|
|
}
|
|
}
|
|
|
|
|