<?php

namespace App\Http\Controllers\Reports;

use App\Helper;
use App\Http\Controllers\Controller;
use App\Services\Reports\KawalanStokService;
use App\Services\Reports\RingkasanHarianService as ReportRingkasanHarianService;
use Illuminate\Http\Request;

class RingkasanHarianController extends Controller
{

    public function getLaporanCawangan(string $kod_cawangan, Request $request)
    {
        $reportRingkasanHarianService = new ReportRingkasanHarianService($kod_cawangan, $request);
        $reportKawalanStokService = new KawalanStokService($kod_cawangan, $request);

        $ringkasan_report = $reportRingkasanHarianService->getLaporanCawangan()->getContent();
        $ringkasan_kawalan = $reportKawalanStokService->getLaporanCawangan()->getContent();

        $reports = [
           'reportRingkasanHarian' => json_decode($ringkasan_report),
           'reportKawalanStok' => json_decode($ringkasan_kawalan),
        ];

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

    public function getLaporanCawanganKPI(string $kod_cawangan, Request $request)
    {
        $reportRingkasanHarianService = new ReportRingkasanHarianService($kod_cawangan, $request);

        $reports = [
           'reportRingkasanHarian' => $reportRingkasanHarianService->getLaporanCawanganKPI(),
        ];

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

    public function getSummaryLaporanRingkasanHarian()
    {
        return json_encode(Helper::getActiveCawangan());
    }
}
