mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-21 21:43:57 +00:00
account-statement-pagination
This commit is contained in:
+110
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Exports;
|
||||
|
||||
use App\Classes\Modules\Exports\Services\ExportsCustomersWalletTransactionHistory;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Company;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
|
||||
class ExportCustomersAccountStatementTransactionToPDFController
|
||||
{
|
||||
|
||||
/**
|
||||
* ExportCustomersWalletTransactionToExcelController constructor.
|
||||
* @param Request $request
|
||||
*/
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer ' . $token);
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
ini_set('max_execution_time', '1000000');
|
||||
ini_set("pcre.backtrack_limit", "5000000");
|
||||
|
||||
$companyId = $request->route('id');
|
||||
$company = Company::find($companyId);
|
||||
|
||||
$transactions = Transaction::where(function ($query) use ($companyId) {
|
||||
$query
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($q) use ($companyId) {
|
||||
$q->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId) {
|
||||
$query->whereHas('owner', function ($query) use ($companyId) {
|
||||
$query->where('owner_id', $companyId);
|
||||
$query->where('owner_type', Company::class);
|
||||
})
|
||||
->where('owner_type', Wallet::class)
|
||||
->where('type', '!=', TransactionType::PAYMENT);
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId) {
|
||||
$query
|
||||
->where('type', TransactionType::INVOICE)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($query) use ($companyId) {
|
||||
$query->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
$total_incoming = Transaction::where(function ($query) use ($companyId, $transactions) {
|
||||
$query->whereHas('owner', function ($query) use ($companyId) {
|
||||
$query->where('owner_id', $companyId);
|
||||
$query->where('owner_type', Company::class);
|
||||
})
|
||||
->where('owner_type', Wallet::class)
|
||||
->where('type', '!=', TransactionType::PAYMENT);
|
||||
})
|
||||
->orWhere(function ($query) use ($companyId, $transactions) {
|
||||
$query
|
||||
->where('type', TransactionType::INVOICE)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($query) use ($companyId) {
|
||||
$query->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->sum(
|
||||
DB::raw(
|
||||
'if (transactions.type = 2,(transactions.amount / transactions.currency_rate + transactions.service_charge),transactions.amount)'
|
||||
)
|
||||
);
|
||||
|
||||
$total_outgoing = Transaction::where(function ($query) use ($companyId) {
|
||||
$query
|
||||
->where('type', TransactionType::PAYMENT)
|
||||
->where('owner_type', Booking::class)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereHas('booking', function ($query) use ($companyId) {
|
||||
$query->where('company_id', $companyId);
|
||||
});
|
||||
})
|
||||
->sum('transactions.amount');
|
||||
|
||||
$currentBalance = $total_incoming - $total_outgoing;
|
||||
|
||||
$pdf = LaravelMpdf::loadView('pages.pdfs.company_account_statement_transaction', ['transactions' => $transactions, 'runningBalance' => $currentBalance, 'company' => $company, 'isPrecise' => $request->route('is_precise') == 'true']);
|
||||
|
||||
return $pdf->download("test.pdf");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user