Merge branch 'ujrah_master' of https://bitbucket.org/arrahn-pkb/api_arrahn into izzati-ujrah
This commit is contained in:
@@ -63,7 +63,17 @@ class MarhunController extends Controller
|
||||
|
||||
$harga = HargaEmas::on('mysql7')->where('karat',$request->karat)->first();
|
||||
|
||||
$nilai_marhun = $request->berat_emas * $harga['harga'];
|
||||
$hargaemas = $harga['harga'];
|
||||
if(isset($request->jenisAT)){
|
||||
if($request->jenisAT == 'hargalama'){
|
||||
$hargaemas = $request->harga;
|
||||
// $nilai_marhun = $request->berat_emas * $request->harga;
|
||||
}else $hargaemas = $harga['harga'];
|
||||
// $nilai_marhun = $request->berat_emas * $harga['harga'];
|
||||
}else $hargaemas = $harga['harga'];
|
||||
|
||||
$nilai_marhun = $request->berat_emas * $hargaemas;
|
||||
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
$marhun = Marhun::on($cawangan['mysql'])->create([
|
||||
@@ -75,7 +85,7 @@ class MarhunController extends Controller
|
||||
'nota' => $request->nota,
|
||||
'karat' => $request->karat,
|
||||
'berat' => $request->berat_emas,
|
||||
'harga' => $harga['harga'],
|
||||
'harga' => $hargaemas,
|
||||
'n_marhun' => $nilai_marhun
|
||||
]);
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Cawangan;
|
||||
use App\Gadai;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\Reports\GadaianService as ReportGadaianService;
|
||||
use App\Helper;
|
||||
|
||||
|
||||
class ReportGadaiController extends Controller
|
||||
{
|
||||
|
||||
public function getLaporanCawangan(string $kod_cawangan, Request $request)
|
||||
{
|
||||
$reportGadaianService = new ReportGadaianService($kod_cawangan, $request);
|
||||
return $reportGadaianService->getCawanganReport();
|
||||
}
|
||||
|
||||
public function getSummaryLaporanGadai(Request $request)
|
||||
{
|
||||
$onDate = $request->onDate;
|
||||
$startDate = $request->startDate;
|
||||
$endDate = $request->endDate;
|
||||
|
||||
$active_cawangan_db_connection = Helper::getActiveCawanganDbConnection();
|
||||
|
||||
$active_cawangan_db_name = array_map(function ($db_connection) {
|
||||
return config('database.connections' . '.' . $db_connection . '.' . 'database');
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$active_cawangan_detail = Cawangan::select('kodcaw', 'details_caw')->whereIn('db_name', $active_cawangan_db_name)->get()->toArray();
|
||||
|
||||
$summary_gadaian_data = array_map(function ($db_connection) use ($request) {
|
||||
$query = Gadai::on($db_connection);
|
||||
|
||||
$query->select(DB::raw('count(norujukan) as total_gadaian, sum(berat) as sum_berat, sum(nilaimarhun) as sum_nilai_marhun, sum(pinjaman) as sum_pinjaman'));
|
||||
|
||||
$query->when($request->filled('startDate') and $request->filled('endDate'), function ($q) use ($request) {
|
||||
return $q->where('t_gadai', '>=', $request->startDate)
|
||||
->where('t_gadai', '<=', $request->endDate);
|
||||
});
|
||||
|
||||
return $query->get()->toArray();
|
||||
|
||||
}, $active_cawangan_db_connection);
|
||||
|
||||
$response = array_map(function ($cawangan_detail, $summary_gadaian_data) {
|
||||
return array_merge($cawangan_detail, $summary_gadaian_data[0]);
|
||||
}, $active_cawangan_detail, $summary_gadaian_data);
|
||||
|
||||
return json_encode($response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user