Path : /var/www/html/moneyexchange/app/Http/Controllers/ |
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
Current File : /var/www/html/moneyexchange/app/Http/Controllers/TransactionController.php |
<?php namespace App\Http\Controllers; use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; use App\Models\Transaction; use App\Models\BankAccount; use App\Models\BankAccountTransaction; use App\Http\Controllers\Controller; use App\Models\MoneyExchangeList; // use Illuminate\Support\Facades\Mail; // use App\Mail\BankMail; use Carbon\Carbon; class TransactionController extends Controller { /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware('auth'); } /** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function destroy($id) { $transaction = Transaction::findOrFail($id); // dd($transaction->created_at->format('d/m/Y'),Carbon::today()->format('d/m/Y')); $moneyExchangeList = $transaction->moneyExchangeList; $bankAccountExchangeFrom = BankAccount::where('responsible_by_user_id',$transaction->user_id)->where('currency_id',$moneyExchangeList->exchange_from_currency_id)->orderBy('id','desc')->first(); $bankAccountExchangeTo = BankAccount::where('responsible_by_user_id',$transaction->user_id)->where('currency_id',$moneyExchangeList->exchange_to_currency_id)->orderBy('id','desc')->first(); if($bankAccountExchangeFrom && $bankAccountExchangeTo) { // dd($transaction->created_at->format('d/m/Y'),Carbon::today()->format('d/m/Y')); if($transaction->created_at->format('d/m/Y')!=Carbon::today()->format('d/m/Y')){ return redirect()->back()->with('error',__("message.can't delete")); } if(Auth::user()->role_id==2||Auth::id()==$transaction->user_id) { $bankAccountTransaction = $transaction->bankAccountTransactions->where('transaction_type','in')->first(); $bankAccountTransaction->delete(); $bankAccountExchangeFrom->credit = $bankAccountExchangeFrom->credit-$transaction->amount; $bankAccountExchangeFrom->save(); //update bank after give to customer exchange $bankAccountTransaction = $transaction->bankAccountTransactions->where('transaction_type','out')->first(); $bankAccountTransaction->delete(); $bankAccountExchangeTo->credit = $bankAccountExchangeTo->credit+$transaction->amount_after_exchange; $bankAccountExchangeTo->save(); $transaction->delete(); } else{ return redirect()->back()->with('error',__("message.can't delete")); } return redirect()->back()->with('success', __('message.deleted successfully')); } else { return redirect()->back()->with('error', __('message.bank account configuration is not correct for this user')); } } // public function show(){ // return redirect()->route('transactions'); // } }