<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class StatementsController extends Controller
{
     public function PrintChartOfAccounts()
    {
            try
            {

                $Accs=modelStatements::selectgl(Session::get('PropertyCode'));
                $Accounts=modelStatements::selectAccountsTypes(Session::get('PropertyCode'));
                $type="All";

                return view('maintanance.process.ChartOfAccountsReport', compact('Accounts','Accs','type'));

        } catch (\Exception $e) {

            return redirect()->route('otheraccounts')->withErrors(['error' => 'An error occurred!!' . $e->getMessage()]);
        }

        }

        public function fetchAccountsByType(Request $request)
        {

            $request->validate([
                'account' => 'required|string'

            ]);

            $accounts = $request->input('account');

            if($accounts=="All")
            {

                $Accs=modelStatements::selectgl(Session::get('PropertyCode'));
                $Accounts=modelStatements::selectAccountsTypes(Session::get('PropertyCode'));
                $type="All";

                return view('/ChartOfAccountsReport', compact('Accounts','Accs','type'));

            }
            else
            {
                $Accs=modelStatements::selectglByType(Session::get('PropertyCode'),$accounts);
                $Accounts=modelStatements::selectAccountsTypes(Session::get('PropertyCode'));
                $types=modelStatements::selectAccountsTypesBYID(Session::get('PropertyCode'),$accounts);
                $type=$types[0]->Name;

                return view('/ChartOfAccountsReport', compact('Accounts','Accs','type'));

            }

        }

}
