Yohohohohohooho | Sanrei Aya
Sanrei Aya


Server : LiteSpeed
System : Linux barito.iixcp.rumahweb.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : elvh3918 ( 1528)
PHP Version : 8.2.31
Disable Function : mail
Directory :  /home/elvh3918/public_html/tenant/app/Http/Controllers/API/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/elvh3918/public_html/tenant/app/Http/Controllers/API/GlobalAPIController.php
<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Auth;
use App\Models\Bussiness;
use App\Models\Accounting\Bank;
use App\Models\Master\Tenant;
use App\Models\Master\Item;

class GlobalAPIController extends Controller
{
    public function get_auth_user() {
        return Auth::user()->load('model');
    }

    public function select_role($role)
    {
        $query = DB::select("CALL sp_permission_by_role_view('$role')");
        return response()->json($query);
    }

    public function split_upper($data) {
        $OutString = '';
        $i = 0;
        for ($index=0; $index < count($data); $index++) {
            $cChar = $data[$index]; 
            if (preg_match('/[A-Z]/', $cChar)) {
                $OutString += ' ' + $cChar;
            } else {
                $OutString += $cChar;
            }

            $i += 1;
        }
        
        return strtolower($OutString);
    }

    public function delete_image_buss($id)
    {
        $msg = '';
        try{
            $buss = Bussiness::where('id', '=', $id)->first();
            if (Storage::disk('public')->exists(config('app.dir_file_buss') . '/'. $buss->image)) {
                Storage::disk('public')->delete(config('app.dir_file_buss') . '/' . $buss->image);
    
                $msg = 'success';
            } else {
                $msg = 'not exists';
            }

            if ($msg == 'success') {
                $buss->update([
                    'image' => null,
                ]);
            }
        } catch (\Exception $e) {
            $msg = 'failed';
        }

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

    public function delete_image_bank($id)
    {
        $msg = '';
        try{
            $bank = Bank::where('id', '=', $id)->first();
            if (Storage::disk('public')->exists(config('app.dir_file_bank') . '/'. $bank->photo)) {
                Storage::disk('public')->delete(config('app.dir_file_bank') . '/' . $bank->photo);
    
                $msg = 'success';
            } else {
                $msg = 'not exists';
            }

            if ($msg == 'success') {
                $bank->update([
                    'photo' => null,
                ]);
            }
        } catch (\Exception $e) {
            $msg = 'failed';
        }

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

    public function delete_image_tenant($id)
    {
        $msg = '';
        try{
            $tenant = Tenant::where('id', '=', $id)->first();
            if (Storage::disk('public')->exists(config('app.dir_file_tenant') . '/'. $tenant->image)) {
                Storage::disk('public')->delete(config('app.dir_file_tenant') . '/' . $tenant->image);
    
                $msg = 'success';
            } else {
                $msg = 'not exists';
            }

            if ($msg == 'success') {
                $tenant->update([
                    'image' => null,
                ]);
            }
        } catch (\Exception $e) {
            $msg = 'failed';
        }

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

    public function delete_image_items($id)
    {
        $msg = '';
        try{
            $items = Item::where('id', '=', $id)->first();
            if (Storage::disk('public')->exists(config('app.dir_file_items') . '/'. $items->photo)) {
                Storage::disk('public')->delete(config('app.dir_file_items') . '/' . $items->photo);
    
                $msg = 'success';
            } else {
                $msg = 'not exists';
            }

            if ($msg == 'success') {
                $items->update([
                    'image' => null,
                ]);
            }
        } catch (\Exception $e) {
            $msg = 'failed';
        }

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

Yohohohohohooho | Sanrei Aya