/
home
/
corsairdevelopme
/
public_html
/
amplivo-console
/
app
/
Services
/
Upload File
HOME
<?php namespace App\Services; use App\Models\CSRNow\State; use App\Models\TaxManagement; use App\Models\UnsubscribeEmail; use App\Models\Wallet; use App\Models\BV; use App\Models\WalletLog; use DateObjectError; use Illuminate\Support\Facades\Auth; use Zip; use Exception; use Carbon\Carbon; use App\Models\User; use App\Models\ProductStaticOption; use App\Models\CSRNow\User as CsrNowUser; use App\Mail\JobEmail; use App\Models\ApiSettings; use App\Models\Member; use App\Models\CSRNow\Country; use App\Models\CSRNow\Language as CSRNowLanguage; use App\Models\GiftCode; use App\Models\Template; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; // use App\Models\IdentifyVerification; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; use Spatie\Activitylog\Models\Activity; class Export { public function createfile($investorShareLog, $columns, $fieldsTable, $keys, $table) { $file = fopen('php://output', 'w'); fputcsv($file, $columns); $counter = 1; Log::info($keys); foreach ($investorShareLog as $mainKey => $investment) { $row = $this->dataFormet($fieldsTable, $investment, $counter, $table); $temp = array(); foreach ($keys as $itm) { if ($itm != 'id') { if ($itm == 'index') { $temp[] = $row['counter']; } else { $temp[] = $row[$itm] ?? ''; } } else { $temp[] = $row['counter']; } } fputcsv($file, $temp); $counter++; } fclose($file); return $file; } public function dataFormet($fieldsTable, $investment, $counter, $table) { $row['counter'] = $counter; foreach ($fieldsTable['data'] as $key => $item) { if (isset($item['status']) && $item['status']) { if (isset($item['relation']) && $item['relation']) { $row[$key] = !empty($investment[$item['index']][$item['relationKey']]) ? $investment[$item['index']][$item['relationKey']] : ''; $row[$key] = $item['replace'][$row[$key]] ?? ''; } else { $row[$key] = $item['replace'][$investment[$item['index']]] ?? $investment[$item['index']]; } } elseif (isset($item['relation']) && $item['relation']) { $row[$key] = !empty($investment[$item['index']][$item['relationKey']]) ? $investment[$item['index']][$item['relationKey']] : ''; if ($item['type'] == 'date') { $row[$key] = !empty($row[$key]) ? Carbon::parse($row[$key])->format('d/m/Y') : ''; } if ($item['type'] == 'float') { $row[$key] = !empty($row[$key]) ? number_format($row[$key], 2) : 0; } if ($item['type'] == 'number') { $row[$key] = !empty($row[$key]) ? number_format($row[$key]) : 0; } } elseif ($item['type'] == 'date') { $row[$key] = !empty($investment[$item['index']]) ? Carbon::parse($investment[$item['index']])->format('d/m/Y') : ''; } elseif ($item['type'] == 'datetime') { $row[$key] = !empty($investment[$item['index']]) ? Carbon::parse($investment[$item['index']])->format('d-m-Y h:i:s A') : ''; } elseif ($item['type'] == 'float') { $row[$key] = !empty($investment[$item['index']]) ? number_format($investment[$item['index']], 2) : 0; } elseif ($key == 'causer_id') { $row[$key] = ($investment['causer']['details']['first_name'] ?? '')." ".($investment['causer']['details']['last_name'] ?? ''); } elseif ($item['type'] == 'number') { $row[$key] = !empty($investment[$item['index']]) ? number_format($investment[$item['index']]) : 0; } elseif ($key == 'role' && ($table == 'users')) { $allRoles = $investment['roles']; $displayRoles = []; foreach ($allRoles as $showRole) { $displayRoles[] = $showRole['name']; } $row[$key] = !empty($investment['roles'][0]['name']) ? implode(',', $displayRoles) : ''; } elseif ($key == 'status' && ($table == 'su_tokens' || $table == 'su_tokens_archived')) { if ($investment->status == '1') { $row[$key] = 'Active'; } else if ($investment->status == '2') { $row[$key] = 'Archived'; } else { $row[$key] = 'Inactive'; } } elseif ($key == 'name' && ($table == 'su_tokens' || $table == 'su_tokens_archived')) { $row[$key] = $investment->symbol . ' ' . $investment->type; } elseif ($key == 'reference' && ($table == 'member_deposit_history')) { if ($investment->transaction_type == 1 && $investment->meta_data) { $row[$key] = $investment->reference; } else if ($investment->transaction_type == 3) { $row[$key] = 'Deposit from ' . (isset($investment->SavingPlan->type) ? ($investment->savingPlan->type == 0 ? 'Flexible' : 'Locked') : '') . ' savings plan'; } else if ($investment->transaction_type == 4) { $row[$key] = 'Interest deposit from ' . (isset($investment->SavingPlan->type) ? ($investment->savingPlan->type == 0 ? 'Flexible' : 'Locked') : '') . ' savings plan'; } else { $row[$key] = $investment->reference; } } elseif ($key == 'currency' && ($table == 'member_deposit_history')) { $row[$key] = $investment->currency->type ?? 'N-A'; } elseif ($key == 'status' && ($table == 'member_deposit_history')) { $row[$key] = 'Done'; } elseif ($key == 'reference' && ($table == 'member_withdraw_history')) { if ($investment->transaction_type == 3) { $row[$key] = 'Transfer to ' . (isset($investment->SavingPlan->type) ? ($investment->savingPlan->type == 0 ? 'Flexible' : 'Locked') : '') . ' savings plan'; } else { $row[$key] = $investment->reference; } } elseif ($key == 'currency' && ($table == 'member_withdraw_history')) { $row[$key] = $investment->currency->type ?? 'N-A'; } elseif ($key == 'status' && $table == 'member_withdraw_history') { if ($investment->status == 0) { $row[$key] = 'Processing'; } else if ($investment->status == 3) { $row[$key] = 'Failed'; } else { $row[$key] = 'Done'; } } elseif ($key == 'name' && ($table == 'member_transfer_history')) { $row[$key] = $investment->TransferUser->name ?? 'N-A'; } elseif ($key == 'currency' && ($table == 'member_transfer_history')) { $row[$key] = $investment->currency->type ?? 'N-A'; } elseif ($key == 'type' && $table == 'member_transfer_history') { if ($investment->type == 'Deposit') { $row[$key] = 'Received'; } else { $row[$key] = 'Sent'; } } elseif ($key == 'status' && ($table == 'member_transfer_history')) { $row[$key] = 'Done'; } elseif ($key == 'type' && ($table == 'member_all_history')) { $row[$key] = $investment->type; if ($investment->transaction_type == 1) { $row[$key] .= ' Transfer'; } } elseif ($key == 'currency_type' && ($table == 'member_all_history')) { $row[$key] = $investment->currency->type ?? 'N-A'; } elseif ($key == 'country' && ($table == 'sa_order_invoice' || $table == 'sa_order_invoice_archive')) { $row[$key] = Country::where('id', '=', $investment->country)->first()->country_name ?? ''; } elseif ($key == 'reference' && ($table == 'member_seller_zone')) { $row[$key] = substr("$investment->reference_no", 0, 4) . '******' . substr("$investment->reference_no", -4); } elseif ($key == 'type' && ($table == 'member_seller_zone')) { if ($investment->type == 1) { $row[$key] = 'Multi-Usage'; } else { $row[$key] = 'Single-Usage'; } } elseif ($key == 'metadata' && ($table == 'member_seller_zone')) { $row[$key] = count($investment->meta_data ?? []); } elseif ($key == 'status' && ($table == 'member_seller_zone')) { if ($investment->status == 1) { $row[$key] = 'Completed'; } elseif ($investment->status == 2) { $row[$key] = 'Cancel'; } elseif ($investment->status == 3) { $row[$key] = 'Expired'; } else { $row[$key] = 'Available'; } } elseif ($key == 'is_active' && ($table == 'sm_account_detail' || $table == 'sm_account_detail_archive')) { if ($investment->is_active == 1) { $row[$key] = 'Active'; } else { $row[$key] = 'Inactive'; } } elseif (($table == "orderlist") && $key == "name") { $investment = (array) $investment; $row[$key] = $investment['column_name']; } elseif (($table == "orderlist") && $key == "type") { $investment = (array) $investment; if ($investment['type'] == 'varchar') { $row[$key] = 'string'; } else { $row[$key] = $investment['type']; } } elseif ($key == 'languages.name' && ($table == 'country_settings_sm')) { $row[$key] = $investment['languages']['name']; }elseif ($key == 'activity' && ($table == 'su_wallet_transaction')) { if (isset($investment->daily_sum)){ $row[$key] = date('d-m-Y',strtotime($investment->created_at)); } elseif (isset($investment->weekly_sum)){ $row[$key] = date('Y/W',strtotime($investment->created_at)); } else { $row[$key] = dateCustom($investment->created_at); } } elseif ($key == 'value' && ($table == 'su_wallet_transaction')) { if (isset($investment->daily_sum)){ $row[$key] = number_format($investment->daily_sum,2); } elseif (isset($investment->weekly_sum)){ $row[$key] = number_format($investment->weekly_sum,2); } else { $row[$key] = number_format($investment->value,2); } } elseif ($key == 'wallet_type' && ($table == 'su_wallet_transaction')) { $row[$key] = $investment->wallet->wallet_list->name ?? '-'; } elseif ($key == 'external_comment' && ($table == 'su_wallet_transaction')) { $data = json_decode($investment->data); $row[$key] = $data->external_comment ?? ''; } elseif ($key == 'internal_comment' && ($table == 'su_wallet_transaction')) { $data = json_decode($investment->data); $row[$key] = $data->internal_comment ?? ''; } elseif ($key == 'created_at' && ($table == 'su_wallet_transaction')) { $row[$key] = dateCustom($investment->created_at); } elseif ($key == 'user_id' && ($table == 'su_wallet_transaction')) { $row[$key] = isset($investment->wallet->user->details) ? ($investment->wallet->user->details->username ?? '') : ''; } elseif ($key == 'admin_id' && ($table == 'su_wallet_transaction')) { $data = json_decode($investment->data); if (isset($data->admin_id) && !empty($data->admin_id)){ $row[$key] = User::where('id',$data->admin_id)->first()->details->username ?? ''; }else{ $row[$key] = '-'; } } elseif ($key == 'action_msg' && ($table == 'su_wallet_transaction')) { $row[$key] = getActionMessageOfWalletLog($investment); } elseif ($table == "su_languages" && $key == "TranslatorManager") { $name = ($investment['translatorManger']['details']['first_name'] ?? '')." ".($investment['translatorManger']['details']['last_name'] ?? ''); $row[$key] = $name ?? 'NA'; } elseif ($table == "su_languages" && $key == "Translator") { $name = ($investment['translator']['details']['first_name'] ?? '')." ".($investment['translator']['details']['last_name'] ?? ''); $row[$key] = $name ?? 'NA'; } elseif ($table == "su_language_archive" && $key == "TranslatorManager") { $row[$key] = $investment['translatorManger']['name'] ?? 'NA'; } elseif ($table == "su_language_archive" && $key == "Translator") { $row[$key] = $investment['translator']['name'] ?? 'NA'; } elseif ($key == 'bravo' && ($table == 'member_list' || $table == 'member_list_archive')) { $unsubscribeEmail = UnsubscribeEmail::where('email',$investment->email); $row[$key] = !empty($unsubscribeEmail) ? 'blocked' : ''; } elseif ($key == 'sponsor_ids' && ($table == 'member_list' || $table == 'member_list_archive')) { if (gettype($investment->sponsor_ids) == 'array') { $row[$key] = implode(',', $investment->sponsor_ids); } else { $row[$key] = $investment['sponsor_ids']; } } elseif ($key == 'member_id' && ($table == 'member_list' || $table == 'member_list_archive')) { $row[$key] = $investment->amplivoUser->member->id; }elseif ($key == 'last_login_date' && ($table == 'member_list' || $table == 'member_list_archive')) { $row[$key] = ($investment->amplivoUser->last_login_at) ? dateCustom($investment->amplivoUser->last_login_at, false)->format('d/m/Y h:i:s a') : ''; }elseif ($key == 'personal_sponsor_ids' && ($table == 'member_list' || $table == 'member_list_archive')) { if (gettype($investment->personal_sponsor_ids) == 'array') { $row[$key] = implode(',', $investment->personal_sponsor_ids); } else { $row[$key] = $investment->personal_sponsor_ids; } } elseif ($key == 'id' && ($table == 'member_list' || $table == 'member_list_archive')) { $row[$key] = $investment->id; } elseif ($key == 'name' && ($table == 'member_list' || $table == 'member_list_archive')) { $row[$key] = ($investment) ? $investment->first_name." ".$investment->last_name : 'Unknown'; } elseif ($key == 'status' && ($table == 'member_list' || $table == 'member_list_archive')) { $member = $investment['amplivo_user']['member'] ?? null; if (empty($member)) { $amplivoUser = User::firstOrCreate(['external_id' => $investment['id']]); $member = Member::firstOrCreate(['user_id' => $amplivoUser->id])->toArray(); } $row[$key] = ucwords($member['status'] ?? 'NA'); } elseif ($key == 'rank' && ($table == 'member_list' || $table == 'member_list_archive')) { $row[$key] = ($investment->amplivoUser->member->rank) ?? ''; } elseif ($item['type'] == 'date') { if ($table == "load_setting") { $row[$key] = !empty($investment[$item['index']]) ? dateCustom($investment[$item['index']], false)->format('d/m/Y h:i:s a') : ''; } else { $row[$key] = !empty($investment[$item['index']]) ? dateCustom($investment[$item['index']], false)->format('d/m/Y') : ''; } } elseif ($key == 'wallet_name' && ($table == 'product_static_options' || $table == 'product_static_options_archive')) { $walletList = []; foreach ($investment['productStaticOptionsWallet'] as $wallet) { $walletList[] = $wallet["name"]; } $row[$key] = implode(", ", $walletList); } elseif ($key == 'type' && ($table == 'product_static_options' || $table == 'product_static_options_archive')) { $row[$key] = $investment['type'] == 1 ? "Product" : "License" ; } elseif ($key == 'name' && ($table == 'gift_codes' || $table == 'redemption_req_list')) { $row[$key] = $investment->purchaseProduct->ProductStaticOption->title ?? ("Plastic Neutrality Package - " . number_format($investment->purchaseProduct->price,2,'.','')); } elseif ($key == 'transaction_id' && ($table == 'gift_codes' || $table == 'redemption_req_list')) { $row[$key] = isset($investment->purchaseProduct->walletLog) && $investment->purchaseProduct->walletLog ? $investment->purchaseProduct->walletLog->transaction_id : '-'; } elseif ($key == 'price' && ($table == 'gift_codes' || $table == 'sa_purchase')) { $row[$key] = formatDisplayNumber(number_format($investment->purchaseProduct->price,2,'.','')); } elseif ($key == 'package_date' && ($table == 'gift_codes' || $table == 'redeemed_gift_codes' || $table == 'sa_purchase')) { $row[$key] = dateCustom($investment->purchaseProduct->created_at); } elseif ($key == 'transaction_id' && $table == 'sa_purchase') { $row[$key] =$investment->purchaseProduct->transaction_id; } elseif ($key == 'expiration_date' && ($table == 'gift_codes' || $table == 'redeemed_gift_codes' || $table == 'sa_purchase')) { $row[$key] = dateCustom($investment->expire_date); } elseif ($key == 'redeemed_date' && ($table == 'gift_codes' || $table == 'redeemed_gift_codes' || $table == 'sa_purchase')) { $row[$key] = isset($investment->redeemed_date) ? dateCustom($investment->redeemed_date) : '-'; } elseif ($key == 'redeem_by' && ($table == 'gift_codes')) { $row[$key] = $investment->redeemedBy ? ($investment->redeemedBy->details->username ?? '') : '-'; } elseif ($key == 'transferred_by' && ($table == 'gift_codes')) { $row[$key] = ($investment->transferredUser && $investment->user) ? ($investment->user->details->first_name ?? '').' '.($investment->user->details->last_name ?? '') : '-'; } elseif ($key == 'transferred_to' && ($table == 'gift_codes')) { $row[$key] = $investment->transferredUser ? ($investment->transferredUser->details->first_name ?? '').' '.($investment->transferredUser->details->last_name ?? '') : '-'; } elseif ($key == 'redeem_by' && ($table == 'sa_purchase')) { $row[$key] = $investment->redeemedBy ? ($investment->redeemedBy->details->username ?? '') : '-'; } elseif ($key == 'status' && ($table == 'gift_codes')) { $row[$key] = GiftCode::statusName[$investment->status] ?? ''; } elseif ($key == 'status' && ($table == 'sa_purchase')) { $row[$key] = GiftCode::statusName[$investment->status] ?? ''; } elseif ($key == 'username' && ($table == 'redeemed_gift_codes' )) { $row[$key] = $investment->redeemedBy ? ($investment->redeemedBy->details->username ?? '-') : '-'; } elseif ($key == 'name' && ($table == 'redeemed_gift_codes')) { $row[$key] = $investment->purchaseProduct->productStaticOption->title ?? 'Plastic Neutrality Package'; } elseif ($key == 'status' && ($table == 'redeemed_gift_codes')) { $row[$key] = ($investment->status == 4) ? 'Rejected' : 'Completed'; } elseif ($key == 'amount' && ($table == 'redeemed_gift_codes')) { $row[$key] = number_format($investment->purchaseProduct->price,2,'.',''); } elseif ($key == 'type' && ($table == 'redeemed_gift_codes')) { $row[$key] = $investment->purchaseProduct->ProductTypeName ?? ''; } elseif ($key == 'created_at' && ($table == 'redeemed_gift_codes')) { $row[$key] = dateCustom($investment->redeemed_date); } elseif ($key == 'transaction_id' && ($table == 'redeemed_gift_codes')) { $row[$key] = $investment->purchaseProduct->walletLog->transaction_id ?? ''; } elseif ($key == 'purchase_by' && ($table == 'sa_purchase')) { $row[$key] = ($investment->user->details->username ?? '') ; } elseif ($key == 'purchase_by' && ($table == 'invoices')) { $row[$key] = ($investment->wallet->user->details->username ?? '') ; }elseif ($key == 'purchase_date' && ($table == 'invoices')) { $row[$key] = dateCustom($investment->created_at); } elseif ($key == 'name' && ($table == 'invoices')) { $name = []; if (isset($investment->purchase) && !empty($investment->purchase)){ foreach ($investment->purchase as $purchaseRow){ $name[] = $purchaseRow->ProductStaticOption->title ?? 'Plastic Neutrality Package'; } } $row[$key] = implode(',', $name ?? ''); }elseif ($key == 'price' && ($table == 'invoices')) { $row[$key] = abs($investment->value ?? '') - ($investment->tax ?? 0); }elseif ($key == 'value' && ($table == 'invoices')) { $row[$key] = abs($investment->value ?? ''); } elseif ($key == 'tax' && ($table == 'invoices')) { $row[$key] = $investment->tax ? formatDisplayNumber($investment->tax) : '0.00'; } elseif ($key == 'description' && ($table == 'sa_purchase')) { $row[$key] = $investment->purchaseProduct->ProductStaticOption->title ?? ("Plastic Neutrality Package - " . number_format($investment->purchaseProduct->price,2,'.','')); } elseif ($key == 'name' && ($table == 'gift_codes')) { $row[$key] = $investment->purchaseProduct->ProductStaticOption->title ?? 'Plastic Neutrality Package'; } elseif ($key == 'transaction_id' && ($table == 'gift_codes')) { $row[$key] = isset($investment->purchaseProduct->walletLog) && $investment->purchaseProduct->walletLog ? $investment->purchaseProduct->walletLog->transaction_id : '-'; } elseif ($key == 'price' && ($table == 'gift_codes' )) { $row[$key] = formatDisplayNumber(number_format($investment->purchaseProduct->price,2,'.','')); } elseif ($key == 'package_date' && ($table == 'gift_codes' )) { $row[$key] = dateCustom($investment->purchaseProduct->created_at); } elseif ($key == 'expiration_date' && ($table == 'gift_codes' )) { $row[$key] = dateCustom($investment->expire_date); } elseif ($key == 'redeem_by' && ($table == 'gift_codes' )) { $row[$key] = $investment->redeemedBy ? ($investment->redeemedBy->details->first_name ?? '').' '.($investment->redeemedBy->details->last_name ?? '') : '-'; } elseif ($key == 'purchase_by' && ($table == 'gift_codes' )) { $row[$key] = $investment->user ? ($investment->user->details->username ?? '') : '-'; } elseif ($key == 'username' && ($table == 'gift_codes' )) { $row[$key] = $investment->user ? ($investment->user->details->first_name ?? '').' '.($investment->user->details->last_name ?? '') : '-'; } elseif ($key == 'status' && $table == 'gift_codes') { $row[$key] = $investment->redeemedBy ? ($investment->redeemedBy->details->first_name ?? '').' '.($investment->redeemedBy->details->last_name ?? '') : '-'; if ($investment->status === 3 || (strtotime(date('Y-m-d')) > strtotime($investment->expire_date))) $row[$key] = 'Expired'; else if ($investment->status === 2) $row[$key] = 'Redeemed'; else if ($investment->status === 4) $row[$key] = 'Rejected'; else if ($investment->status === 5) $row[$key] = 'Canceled'; else if ($investment->status === 1) $row[$key] = 'Pending'; } elseif ($key == 'created_at_fr' && ($table == 'member_wallet_log')) { if (isset($investment->daily_sum)){ $row[$key] = date('d-m-Y',strtotime($investment->created_at)); } elseif (isset($investment->weekly_sum)){ $row[$key] = date('Y/W',strtotime($investment->created_at)); } else { $row[$key] = date('d-m-Y',strtotime($investment->created_at)); } } elseif ($key == 'wallet_id' && ($table == 'member_wallet_log')) { $row[$key] = $investment->wallet->wallet_list->name ?? ''; } elseif ($key == 'action_key' && ($table == 'member_wallet_log')) { $row[$key] = $investment->action_name; } elseif ($key == 'action' && ($table == 'member_wallet_log')) { $row[$key] = getActionMessageOfWalletLog($investment); } elseif ($key == 'amount' && ($table == 'member_wallet_log')) { if (isset($investment->daily_sum)){ $row[$key] = getCustomizeAmountWalletLog($investment->daily_sum,$investment->action); } elseif (isset($investment->weekly_sum)){ $row[$key] = getCustomizeAmountWalletLog($investment->weekly_sum,$investment->action); } else { $row[$key] = getCustomizeAmountWalletLog($investment->value,$investment->action); } } elseif ($key == 'admin_id' && ($table == 'member_wallet_log')) { $data = json_decode($investment->data); $row[$key] = ''; if (isset($data->admin_id) && !empty($data->admin_id)){ $row[$key] = User::where('id',$data->admin_id)->first()->details->username ?? ''; } } elseif ($key == 'internal_comment' && ($table == 'member_wallet_log')) { $data = json_decode($investment->data); $row[$key] = $data->internal_comment ?? ''; } elseif ($key == 'external_comment' && ($table == 'member_wallet_log')) { $data = json_decode($investment->data); $row[$key] = $data->external_comment ?? ''; } elseif ($key == 'created_at' && ($table == 'wallet_log')) { $row[$key] = date("d-m-Y h:i:s A", strtotime($investment->created_at)); } elseif ($key == 'username' && ($table == 'wallet_log')) { $row[$key] = $investment->wallet && $investment->wallet->user && $investment->wallet->user->details ? ($investment->wallet->user->details->username ?? '') : '-'; } elseif ($key == 'data' && ($table == 'wallet_log')) { $row[$key] = getActionMessageOfWalletLog($investment); } elseif ($key == 'action' && ($table == 'wallet_log')) { $row[$key] = $investment->action_name ?? ''; } elseif ($key == 'username' && ($table == 'star_rank_report')) { $row[$key] = $investment->user->details->username ?? ''; } elseif ($key == 'first_name' && ($table == 'star_rank_report')) { $row[$key] = $investment->user->details->first_name ?? ''; } elseif ($key == 'last_name' && ($table == 'star_rank_report')) { $row[$key] = $investment->user->details->last_name ?? ''; } elseif ($key == 'qualification_date' && ($table == 'star_rank_report')) { if (isset($investment->UserQualificationLog[0]->created_at)) { $row[$key] = date("d-m-Y h:i:s A", strtotime($investment->UserQualificationLog[0]->created_at)); } else { $row[$key] = ''; } } elseif ($key == 'username' && ($table == 'wallet_report')) { $row[$key] = $investment->wallet->user->details->username ?? ''; } elseif ($key == 'username' && ($table == 'bv')) { $row[$key] = $investment->user->details->username ?? ''; } elseif ($key == 'value' && ($table == 'bv')) { $row[$key] = $investment->value ? formatDisplayNumber($investment->value) : '0.00'; } elseif ($key == 'source' && ($table == 'bv')) { if ($investment->source == 1 ) { $source = 'Purchase'; } elseif ($investment->source == 2 ) { $source = 'Bergman'; } elseif ($investment->source == 3 ) { $source = 'CCW'; } elseif ($investment->source == 4 ) { $source = 'Admin'; } elseif($investment->source == 5 ) { $source = 'Coupon redeem'; } else { $source = '-'; } $row[$key] = $source; } elseif ($key == 'gift_code_id' && ($table == 'bv')) { if($investment->source == 5){ $data = json_decode($investment->data,true); if (isset($data['gift_code_id'])) { $giftCode = GiftCode::with('user')->where('gift_code',$data['gift_code_id'])->first(); if ($giftCode) { $row[$key] = $data['gift_code_id'].' (Username : ' . $giftCode->user->details->username . ')'; } } }else{ $row[$key] = ''; } } elseif ($key == 'first_name' && ($table == 'wallet_report')) { $row[$key] = $investment->wallet->user->details->first_name ?? ''; } elseif ($key == 'last_name' && ($table == 'wallet_report')) { $row[$key] = $investment->wallet->user->details->last_name ?? ''; } elseif ($key == 'purchase_product' && ($table == 'wallet_report')) { $data = json_decode($investment->data); $row[$key] = $data->packageName ?? ''; } elseif ($key == 'purchase_amount' && ($table == 'wallet_report')) { $row[$key] = ($investment->action == WalletLog::ACTION_PURCHASE) ? formatDisplayNumber($investment->value) : '0.00'; } elseif ($key == 'transfer_amount' && ($table == 'wallet_report')) { $data = json_decode($investment->data); $row[$key] = $data->transfer ?? '0.00'; } elseif ($key == 'other_amount' && ($table == 'wallet_report')) { $row[$key] = ($investment->action != WalletLog::ACTION_PURCHASE && $investment->action != WalletLog::ACTION_TRANSFER_IN && $investment->action != WalletLog::ACTION_TRANSFER_OUT) ? formatDisplayNumber($investment->value) : '0.00'; } elseif ($key == 'receiver_user' && ($table == 'wallet_report')) { $data = json_decode($investment->data); $row[$key] = ($investment->action == WalletLog::ACTION_TRANSFER_OUT) ? $data->receiver : ''; } elseif ($key == 'wallet_type' && ($table == 'wallet_report')) { $row[$key] = $investment->wallet->wallet_list->name ?? ''; } elseif ($key == 'action_msg' && ($table == 'wallet_report')) { $row[$key] = getActionMessageOfWalletLog($investment); } elseif ($key == 'time' && ($table == 'wallet_report')) { if (isset($investment->created_at)) { $row[$key] = date("h:i:s", strtotime($investment->created_at)); } else { $row[$key] = ''; } } elseif ($key == 'created_at' && ($table == 'wallet_report')) { if (isset($investment->created_at)) { $row[$key] = date("d-m-Y", strtotime($investment->created_at)); } else { $row[$key] = ''; } } else { if ($table == "orderlist") { $investment = (array) $investment; } $row[$key] = !empty($investment[$item['index']]) ? $investment[$item['index']] : ''; } if ($table == 'investor_dashboard') { if (isset($row['status']) && $row['status'] == 'Complete' && $row['type'] == 'Withdraw') { $row['status'] = 'Paid'; } if (isset($row['created_at']) && !$row['created_at']) { $row['created_at'] = !empty($investment['created_at']) ? Carbon::parse($investment['created_at'])->format('d/m/Y') : ''; } } if ($table == 'investment' || $table == 'investment_by_id' || $table == 'investment_by_user_id') { if (isset($row['created_at']) && !$row['created_at']) { $row['created_at'] = !empty($investment['created_at']) ? Carbon::parse($investment['created_at'])->format('d/m/Y') : ''; } } if ($table == 'redemption_req_list') { if ($key == 'username') { $row[$key] = $investment->redeemedBy ? $investment->redeemedBy->username : '-'; } if ($key == 'csr_wallet_address') { $row[$key] = $investment->csr_wallet_address ? $investment->csrWalletAddress->address : '-'; } if ($key == 'email') { $row[$key] = $investment->redeemedBy ? $investment->redeemedBy->email : '-'; } if ($key == 'gift_code') { $row[$key] = $investment->giftcode ? $investment->giftcode->gift_code : '-'; } if ($key == 'created_at') { $row[$key] = date('d-m-Y', strtotime($investment->created_at)); } } } return $row; } /** * @throws Exception */ public function jobfile($filter, $defaultSearch, $columns, $keys, $table, $user, $type, $ids) { $fieldsTable = $this->exportData($filter, $defaultSearch, $table, $user, $ids); if ($table == "orderlist") { $investorShareLog = $fieldsTable['query']->all(); } else { $investorShareLog = $fieldsTable['query']->get(); } $page = $fieldsTable['page']->pageName ?? 'Logs'; if ($table == 'news_sa' || $table == 'news_sa_archived') { $page = 'News'; } else if ($table == 'press_sa' || $table == 'press_sa_archived') { $page = 'Press'; } else if ($table == 'activity_log_my' || $table == 'activity_log_sm_my' || $table == 'activity_log_cm' || $table == 'activity_log_sa_my' || $table == 'activity_log_investor_my' || $table == 'activity_log_translator_my') { $page = 'Logs'; } else if ($table == 'csrlist') { $page = 'CSR list field settings'; } else if ($table == 'orderlist') { $page = 'Order field settings'; } else if ($table == 'sa_csr_holder_list') { $page = 'CSR Holders list'; } else if ($table == 'member_withdraw_history') { $page = 'User Withdraw'; } else if ($table == 'member_transfer_history') { $page = 'User Transfer'; } else if ($table == 'member_all_history') { $page = 'User All'; } else if ($table == 'member_seller_zone') { $page = 'Payment Links'; } else if ($table == 'sa_csr_retirement_setting') { $page = 'Review Logo & Url'; } else if ($table == 'country_settings_sm' || $table == 'country_settings_sm_archive') { $page = 'Countries'; } else if ($table == 'su_wallet_transaction') { $page = 'Transaction History'; } else if ($table == 'redeemed_gift_codes') { $page = 'Redemption'; } else if ($table == 'gift_codes') { $page = 'Gift code'; } else if ($table == 'api_settings') { $page = 'Crypto API'; } else if ($table == 'member_list') { $page = 'Member'; } else if ($table == 'activity_log_dashboard') { $page = 'My Logs'; } else if ($table == 'product_static_options' || $table == 'product_static_options_archive') { $page = 'Product Static Option'; } else if ($table == 'sa_purchase') { $page = 'Purchase'; } else if ($table == 'invoices') { $page = 'Purchase'; } else if ($table == 'redemption_req_list') { $page = 'Redemption Request List'; } else if ($table == 'member_wallet_log' || $table == 'wallet_log') { $page = 'Wallet Log'; } else if ($table == 'star_rank_report') { $page = 'Star Rank Report'; } else if ($table == 'wallet_report') { $page = 'Wallet Report'; } if (!File::exists(public_path() . "/files")) { File::makeDirectory(public_path() . "/files"); } $date = Carbon::now()->format('Ymd'); $pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyz"), 0, 8); if (!File::exists(public_path() . "/files" . "/" . $pass)) { File::makeDirectory(public_path() . "/files" . "/" . $pass); } $time = 'files' . "/" . $pass . '/' . config('app.name') . '-' . $page . '-' . $date . '.csv'; $urlFile = config('app.name') . '-' . $page . '-' . $date . '.csv'; $urlFolder = $pass; $filename = public_path() . '/' . $time; $file = fopen($filename, 'a+'); fputcsv($file, $columns); $counter = 1; foreach ($investorShareLog as $mainKey => $investment) { $row = $this->dataFormet($fieldsTable, $investment, $counter, $table); $temp = array(); foreach ($keys as $itm) { if ($itm != 'id') { if ($itm == 'index') { $temp[] = $row['counter']; } else { $temp[] = $row[$itm] ?? ''; } } else { $temp[] = $row['counter']; } } fputcsv($file, $temp); $counter++; } fclose($file); if ($type == 'zip') { $tempFilePath = public_path() . '/files' . '/' . $pass; $zip = Zip::create(public_path() . '/files' . '/' . $pass . '/' . config('app.name') . '-' . $page . '-' . $date . '.zip'); $zip->add($tempFilePath . '/' . config('app.name') . '-' . $page . '-' . $date . '.csv'); $urlFile = config('app.name') . '-' . $page . '-' . $date . '.zip'; $zip->close(); } $this->sendEmail($urlFolder, $urlFile, $user); } public function exportData($filter, $defaultSearch, $tableName, $user, $ids) { $temp = $this->exportDataStructure($filter, $defaultSearch, $user, $ids, $tableName); if (isset($temp[$tableName])) { return $temp[$tableName]; } return false; } public function exportDataStructure($filter, $defaultSearch, $user, $ids, $tableName) { $headerArray = []; $dataArray = []; $headerArray['id'] = '#'; $dataArray["created_at"] = [ 'index' => 'created_at', 'status' => false, 'type' => 'date', ]; $temp = [ 'users' => [ 'query' => $tableName == 'users' ? User::with('roles')->wherehas('roles',function ($q){ $q->where('name','!=','member'); })->where('is_active', 1)->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'created_at') { $temp = explode(' - ', $item); $startDate = createFromFormatCustom($temp[0]); $endDate = createFromFormatCustom($temp[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'role') { $q->whereHas('roles', function ($query) use ($item) { $query->where('name', [$item]); }); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('id', 'desc') : [], 'page' => new User, 'header' => ['id' => '#', 'email' => 'Email', 'name' => 'Name', 'role' => 'Role', 'created_at' => 'Created At'], 'data' => [ 'role' => [ 'index' => "roles[0]['name']", 'status' => false, 'type' => 'string', ], 'email' => [ 'index' => "email", 'status' => false, 'type' => 'string', ], 'name' => [ 'index' => "name", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date', ], ], ], 'activity_log' => [ 'query' => $tableName == 'activity_log' ? Activity::with(['causer'])->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'causer_id') { $externalId = CsrNowUser::where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('causer_id',$userId); } elseif ($key == 'log_name') { $q->where('log_name', $item); } else if ($key == 'counter') { $q->where('id', $item); } else { $q->where($key, 'like','%' . $item . '%'); } } } })->latest() : [], 'header' => ['counter' => '#', 'log_name' => 'Activity Type', 'description' => 'Activity', 'causer_id' => 'User', 'created_at' => 'Activity Time'], 'data' => [ 'log_name' => [ 'index' => "log_name", 'status' => false, 'type' => 'string', ], 'description' => [ 'index' => "description", 'status' => false, 'type' => 'string', ], 'causer_id' => [ 'index' => "causer_id", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'datetime', ], ], ], 'activity_log_dashboard' => [ 'query' => $tableName == 'activity_log_dashboard' ? Activity::with(['causer'])->where('causer_id', Auth::id())->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'causer_id') { $externalId = CsrNowUser::where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('causer_id', $userId); } else if ($key == 'counter') { $q->where('id', $item); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->latest()->take(50) : [], 'header' => ['counter' => '#', 'log_name' => 'Activity Type', 'description' => 'Activity', 'causer_id' => 'User', 'created_at' => 'Activity Time'], 'data' => [ 'log_name' => [ 'index' => "log_name", 'status' => false, 'type' => 'string', ], 'description' => [ 'index' => "description", 'status' => false, 'type' => 'string', ], 'causer_id' => [ 'index' => "causer_id", 'relationKey' => 'name', 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'datetime', ], ], ], 'activity_log_my' => [ 'query' => $tableName == 'activity_log_my' ? Activity::with(['causer'])->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'causer_id') { $externalId = CsrNowUser::where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('causer_id', $userId); } else if ($key == 'counter') { $q->where('id', $item); } elseif ($key == 'log_name') { $q->where('log_name', $item); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->latest()->where(function ($q) use ($user) { if (Auth::user()->hasAnyRole('Super Admin','super-user')){ } else { $q->where('causer_id', $user->id); } }) : [], 'header' => ['counter' => '#', 'log_name' => 'Activity Type', 'description' => 'Activity', 'causer_id' => 'User', 'created_at' => 'Activity Time'], 'data' => [ 'log_name' => [ 'index' => "log_name", 'status' => false, 'type' => 'string', ], 'description' => [ 'index' => "description", 'status' => false, 'type' => 'string', ], 'causer_id' => [ 'index' => "causer_id", 'relationKey' => 'name', 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'datetime', ], ], ],'su_wallet_transaction' => [ 'query' => $tableName == 'su_wallet_transaction' ? WalletLog::with('wallet','wallet.user') ->orderByDesc('wallet_log.created_at') ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item != '') { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'user_id') { $externalId = CsrNowUser::where("username", 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereHas("wallet", function ($q) use ($userId) { $q->whereIntegerInRaw('user_id',$userId); }); } else if ($key == 'wallet_type') { $q->whereHas("wallet.wallet_list", function ($query) use ($item) { $query->where('name', 'LIKE', '%' . trim($item) . '%'); }); } else if ($key == 'internalCommentStatus') { $q->whereRaw("JSON_UNQUOTE(JSON_EXTRACT(data, '$.internal_comment')) IS NOT NULL AND JSON_UNQUOTE(JSON_EXTRACT(data, '$.internal_comment')) != 'null' AND JSON_UNQUOTE(JSON_EXTRACT(data, '$.internal_comment')) != ''"); } else if ($key == 'external_comment' || $key == 'internal_comment') { $q->whereJsonContains("data->$key", $item); } else if ($key == 'transaction_type') { $q->where('action', $item); } elseif ($key == 'activity') { if ($item == 'week') { $q->join('wallets', 'wallets.id', '=', 'wallet_log.wallet_id')->select('wallet_log.*', DB::raw('count(*) as total'), DB::raw('sum(value) as weekly_sum'))->groupBy(DB::raw('WEEK(wallet_log.created_at)'),'wallet_log.action','wallet_log.wallet_id','wallets.user_id'); } elseif ($item == 'day') { $q->join('wallets', 'wallets.id', '=', 'wallet_log.wallet_id')->select('wallet_log.*', DB::raw('count(*) as total'), DB::raw('sum(value) as daily_sum'))->groupBy(DB::raw('DATE(wallet_log.created_at)'), 'wallet_log.action', 'wallet_log.wallet_id','wallets.user_id'); } } elseif ($key == 'wallet'){ $q->whereHas('wallet',function ($q) use ($item){ $q->where('wallet_list_id', $item); }); } elseif ($key == 'action'){ $q->where($key,$item); }elseif($key == 'start'){ $q->whereDate('wallet_log.created_at', '>=', $item); }elseif($key == 'end'){ $q->whereDate('wallet_log.created_at', '<=', $item); } else { $q->where($key, 'like', '%' . $item . '%'); } } } }) : [], 'page' => new WalletLog, 'header' => ['counter' => '#','activity' => 'Week of year', 'user_id' => 'Username', 'wallet_type' => 'Wallet', 'action_msg' => 'Description', 'value' => 'Accumulated Amount', 'external_comment' => 'External Comments', 'internal_comment' => 'Internal Comments', 'admin_id' => 'Admin', 'status' => 'status'], 'data' => [ 'activity' =>[ 'index' => "activity", 'status' => false, 'type' => 'string' ], 'user_id' => [ 'index' => "user_id", 'status' => false, 'type' => 'string' ], 'wallet_type' => [ 'index' => "wallet_type", 'status' => false, 'type' => 'string', ], 'action_msg' => [ 'index' => "action_msg", 'status' => false, 'type' => 'string' ], 'value' => [ 'index' => "value", 'status' => false, 'type' => 'string' ], 'external_comment' => [ 'index' => "external_comment", 'status' => false, 'type' => 'string' ], 'internal_comment' => [ 'index' => "internal_comment", 'status' => false, 'type' => 'string' ], 'admin_id' => [ 'index' => "admin_id", 'status' => false, 'type' => 'string' ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string' ], ], ], 'wallet_log' => [ 'query' => $tableName == 'wallet_log' ? WalletLog::with('wallet','wallet.user') ->orderByDesc('id') ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item != '') { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'action') { $q->where($key,$item); } else if ($key == 'username') { $externalId = CsrNowUser::where("username", 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereHas("wallet", function ($q) use ($userId) { $q->whereIntegerInRaw('user_id',$userId); }); } else { $q->where($key, 'like', '%' . $item . '%'); } } } }) : [], 'page' => new WalletLog, 'header' => ['counter' => '#', 'username' => 'Username', 'data' => 'Data', 'action' => 'Action', 'value' => 'Value', 'balance' => 'Balance', 'created_at' => 'Created At'], 'data' => [ 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string' ], 'data' => [ 'index' => "data", 'status' => false, 'type' => 'string' ], 'action' => [ 'index' => "action", 'status' => false, 'type' => 'string' ], 'value' => [ 'index' => "value", 'status' => false, 'type' => 'string' ], 'balance' => [ 'index' => "balance", 'status' => false, 'type' => 'string' ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'datetime' ], ], ], 'member_wallet_log' => [ 'query' => $tableName == 'member_wallet_log' ? WalletLog::with('wallet','wallet.user') ->orderBy('created_at','DESC') ->when(count($filter), function ($q) use ($filter) { $user_id = basicDecrypt($filter['user_id'] ?? ''); foreach ($filter as $key => $item) { if ($item != '') { if ($key == 'user_id'){ $walletIds = Wallet::where('user_id', $user_id)->whereNotNull('wallet_list_id')->pluck('wallet_list_id'); $q->whereHas('wallet',function ($q) use ($walletIds,$user_id){ $q->where('user_id', $user_id); $q->whereIn('wallet_list_id', $walletIds); }); } elseif ($key == 'wallet') { $q->whereHas('wallet',function ($q) use ($item,$user_id){ $q->where('user_id', $user_id); $q->where('wallet_list_id', $item); }); } elseif ($key == 'action') { $q->where('action',$item); } elseif ($key == 'start') { $q->whereDate('created_at', '>=', $item); } elseif ($key == 'end') { $q->whereDate('created_at', '<=', $item); } elseif ($key == 'internalCommentStatus') { if ($item == 'yes') { $q->whereRaw(" JSON_EXTRACT(data, '$.internal_comment') IS NOT NULL AND JSON_TYPE(JSON_EXTRACT(data, '$.internal_comment')) = 'STRING' AND JSON_UNQUOTE(JSON_EXTRACT(data, '$.internal_comment')) != '' "); } else if ($item == 'no') { $q->where(function ($query) { $query->whereRaw("JSON_EXTRACT(data, '$.internal_comment') IS NULL") ->orWhereRaw("JSON_TYPE(JSON_EXTRACT(data, '$.internal_comment')) != 'STRING'") ->orWhereRaw("JSON_UNQUOTE(JSON_EXTRACT(data, '$.internal_comment')) = ''"); }); } } elseif ($key == 'format') { if ($item == 'week'){ $q->select('*', DB::raw('count(*) as total'), DB::raw('sum(value) as weekly_sum'))->groupBy(DB::raw('WEEK(created_at)'),'action','wallet_id'); } elseif ($item == 'day'){ $q->select('*', DB::raw('count(*) as total'), DB::raw('sum(value) as daily_sum'))->groupBy(DB::raw('DATE(created_at)'),'action','wallet_id'); } } } } }) : [], 'page' => new WalletLog, 'header' => ['counter' => '#','created_at_fr' => 'Week Of Year / Date', 'action_key' => 'Action', 'wallet_id' => 'Wallet', 'action' => 'Description', 'amount' => 'Accumulated Amount', 'external_comment' => 'External Comments', 'internal_comment' => 'Internal Comments', 'admin_id' => 'Admin'], 'data' => [ 'created_at_fr' => [ 'index' => "created_at", 'status' => false, 'type' => 'string' ], 'action_key' => [ 'index' => "action_key", 'status' => false, 'type' => 'string' ], 'wallet_id' => [ 'index' => "wallet_id", 'status' => false, 'type' => 'string' ], 'action' => [ 'index' => "action", 'status' => false, 'type' => 'string' ], 'amount' => [ 'index' => "value", 'status' => false, 'type' => 'string' ], 'external_comment' => [ 'index' => "value", 'status' => false, 'type' => 'string' ], 'internal_comment' => [ 'index' => "value", 'status' => false, 'type' => 'string' ], 'admin_id' => [ 'index' => "value", 'status' => false, 'type' => 'string' ] ], ], 'load_setting' => [ 'query' => $tableName == 'load_setting' ? Template::when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('id', 'desc') : [], 'page' => new Template, 'header' => ['id' => '#', 'name' => 'Name', 'description' => 'description', 'created_at' => 'Activity Time'], 'data' => [ 'name' => [ 'index' => "name", 'status' => false, 'type' => 'string' ], 'description' => [ 'index' => "description", 'status' => false, 'type' => 'string' ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date' ] ], ], 'product_static_options' => [ 'query' => $tableName == 'product_static_options' ? ProductStaticOption::with('productStaticOptionsWallet')->whereNull('deleted_at')->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'redemption_expire_days'){ $q->where('redemption_expire_days', trim($item)); } else if ($key == 'price'){ list($operator, $value) = getFilterOperatorAndValue($item); $q->where($key, $operator, ($value * 100)); } else { $q->where($key, 'like', '%' . $item . '%'); } } })->orderBy('created_at', 'desc') : [], 'page' => new ProductStaticOption, 'header' => [ 'id' => '#', 'title' => 'Title', 'price' => 'Price', 'type' => 'Type','wallet_name' => 'Wallet Name', 'redemption_expire_days' => 'Redemption Expire Days', 'created_at' => 'Created At' ], 'data' => [ 'title' => [ 'index' => "title", 'status' => false, 'type' => 'string' ], 'price' => [ 'index' => "price", 'status' => false, 'type' => 'string' ], 'type' => [ 'index' => "type", 'status' => false, 'type' => 'string', ], 'wallet_name' => [ 'index' => "wallet_name", 'status' => false, 'type' => 'string', ], 'redemption_expire_days' => [ 'index' => "redemption_expire_days", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date', ] ], ],'product_static_options_archive' => [ 'query' => $tableName == 'product_static_options_archive' ? ProductStaticOption::with('productStaticOptionsWallet')->onlyTrashed()->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'wallet_name'){ $q->whereHas("productStaticOptionsWallet", function ($q) use ($item) { $q->where('name', 'LIKE', '%' . trim($item) . '%'); }); } else if ($key == 'redemption_expire_days'){ $q->where('redemption_expire_days', trim($item)); } else { $q->where($key, 'like', '%' . $item . '%'); } } })->orderBy('created_at', 'desc') : [], 'page' => new ProductStaticOption, 'header' => [ 'id' => '#', 'title' => 'Title', 'price' => 'Price', 'type' => 'Type', 'wallet_name' => 'Wallet Name','redemption_expire_days' => 'Redemption Expire Days', 'created_at' => 'Created At' ], 'data' => [ 'title' => [ 'index' => "title", 'status' => false, 'type' => 'string' ], 'price' => [ 'index' => "price", 'status' => false, 'type' => 'string' ], 'type' => [ 'index' => "type", 'status' => false, 'type' => 'string', ], 'wallet_name' => [ 'index' => "wallet_name", 'status' => false, 'type' => 'string', ], 'redemption_expire_days' => [ 'index' => "redemption_expire_days", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date', ] ], ],'star_rank_report' => [ 'query' => $tableName == 'star_rank_report' ? Member::with(['user','UserQualificationLog' => function ($query) { $query->orderBy('created_at', 'desc'); // Adjust the column name to your sorting preference }]) ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item != '') { if ($key == 'qualification_date') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereHas('UserQualificationLog',function ($q) use ($startDate,$endDate){ $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); }); } elseif ($key == 'username') { $externalId = CsrNowUser::where("username", 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('user_id',$userId); } elseif ($key == 'first_name' || $key == 'last_name') { $externalId = CsrNowUser::where($key, 'LIKE', trim($item))->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('user_id',$userId); } elseif ($key == 'status'){ $q->where($key,$item); } elseif ($key == 'star_rank') { $q->where('rank', $item); } else { $q->where($key,'like',$item); } } } })->orderBy('rank', 'desc') : [], 'page' => new Member, 'header' => [ 'username' => 'Username', 'first_name' => 'First Name', 'last_name' => 'Last Name','rank' => 'Rank', 'status' => 'Status', 'qualification_date' => 'Qualification Date' ], 'data' => [ 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string' ], 'first_name' => [ 'index' => "first_name", 'status' => false, 'type' => 'string' ], 'last_name' => [ 'index' => "last_name", 'status' => false, 'type' => 'string', ], 'rank' => [ 'index' => "rank", 'status' => false, 'type' => 'string', ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string', ], 'qualification_date' => [ 'index' => "qualification_date", 'status' => false, 'type' => 'string', ] ], ],'wallet_report' => [ 'query' => $tableName == 'wallet_report' ? WalletLog::with(['wallet','wallet.user','wallet.wallet_list' => function ($query) { $query->orderBy('created_at', 'desc'); // Adjust the column name to your sorting preference }]) ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item != '') { if ($key == 'start_date') { $startDate = createFromFormatCustom($item); $q->whereDate('created_at', '>=', $startDate); } elseif ($key == 'end_date') { $end_date = createFromFormatCustom($item); $q->whereDate('created_at', '<=', $end_date); } elseif ($key == 'action_type') { $q->where('action',$item); } elseif ($key == 'wallet_type'){ $q->whereHas('wallet',function ($q) use ($item){ $q->where('wallet_list_id', $item); }); } else { $q->where($key,'like',$item); } } } })->orderBy('created_at', 'desc') : [], 'page' => new WalletLog, 'header' => [ 'created_at' => 'Created At', 'time' => 'Time', 'username' => 'Username','first_name' => 'First Name', 'last_name' => 'Last Name', 'purchase_product' => 'Product Purchased', 'purchase_amount' => 'Purchased Amount', 'transfer_amount' => 'Transfer Amount', 'other_amount' => 'Other', 'receiver_user' => 'Transfer To Username','wallet_type' => 'Wallet', 'balance' => 'Balance', 'action_msg' => 'Action' ], 'data' => [ 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'string' ], 'time' => [ 'index' => "time", 'status' => false, 'type' => 'time' ], 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string' ], 'first_name' => [ 'index' => "first_name", 'status' => false, 'type' => 'string' ], 'last_name' => [ 'index' => "last_name", 'status' => false, 'type' => 'string', ], 'purchase_product' => [ 'index' => "purchase_product", 'status' => false, 'type' => 'string', ], 'purchase_amount' => [ 'index' => "purchase_amount", 'status' => false, 'type' => 'string', ], 'transfer_amount' => [ 'index' => "transfer_amount", 'status' => false, 'type' => 'string', ], 'other_amount' => [ 'index' => "other_amount", 'status' => false, 'type' => 'string', ], 'receiver_user' => [ 'index' => "receiver_user", 'status' => false, 'type' => 'string', ], 'wallet_type' => [ 'index' => "wallet_type", 'status' => false, 'type' => 'string', ], 'balance' => [ 'index' => "balance", 'status' => false, 'type' => 'string', ], 'action_msg' => [ 'index' => "action_msg", 'status' => false, 'type' => 'string', ] ], ],'member_list' => [ 'query' => $tableName == 'member_list' ? CsrNowUser::with('hasRole','profile','amplivoUser')->where('archived_status', 0)->whereHas('hasRole', function ($query) { return $query->whereHas('role',function ($q){ $q->where('name','member'); }); })->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate); $q->whereDate('created_at', '<=', $endDate); } elseif ($key === 'name') { $q->where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%'); } elseif ($key === 'phone' || $key === 'gender') { $q->whereHas("profile", function ($innerQuery) use ($item,$key) { $innerQuery->where($key, 'like', $item . '%'); }); } elseif ($key === 'member_id') { $external_id = User::whereHas('member',function ($innerQuery) use ($item,$key) { $key = ($key = 'member_id') ? 'id' : $key; $innerQuery->where($key, 'like', '%' . $item . '%'); })->pluck('external_id'); $q->whereIntegerInRaw('id',$external_id); } elseif ($key === 'last_login_date') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $external_id = User::whereHas('member',function ($innerQuery) use ($item,$key,$startDate,$endDate) { $innerQuery->whereDate('last_login_at', '>=', $startDate); $innerQuery->whereDate('last_login_at', '<=', $endDate); })->pluck('external_id'); $q->whereIntegerInRaw('id',$external_id); } elseif ($key === 'rank') { $external_id = User::whereHas('member',function ($innerQuery) use ($item,$key) { $innerQuery->where($key, $item); })->pluck('external_id'); $q->whereIntegerInRaw('id',$external_id); } elseif ($key === 'status') { $external_id = User::whereHas('member',function ($innerQuery) use ($item,$key) { $innerQuery->where($key, $item); })->pluck('external_id'); $q->whereIntegerInRaw('id',$external_id); } elseif ($key === 'birthdate') { $q->whereHas("profile", function ($innerQuery) use ($item) { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $innerQuery->whereDate('date_of_birth', '>=', $startDate); $innerQuery->whereDate('date_of_birth', '<=', $endDate); }); } elseif ($key === 'bravo') { $email = UnsubscribeEmail::pluck('email'); if ($item == 'unblocked'){ $q->whereNotIn('email',$email); } else { $q->whereIn('email',$email); } } else { $q->where($key, 'like', '%' . $item . '%'); } } })->orderBy('created_at', 'desc') : [], 'page' => new CsrNowUser, 'header' => [ 'member_id' => '#', 'username' => 'Username', 'name' => 'Name', 'email' => 'Email', 'rank' => 'Rank', 'status' => 'Status', 'bravo' => 'Brevo', 'created_at' => 'Registration Time', 'last_login_date' => 'Last Login Time' ], 'data' => [ 'member_id' => [ 'index' => "profile", 'status' => false, 'type' => 'array' ], 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string' ], 'name' => [ 'index' => "name", 'status' => false, 'type' => 'string' ], 'email' => [ 'index' => "email", 'status' => false, 'type' => 'string' ], 'rank' => [ 'index' => "rank", 'status' => false, 'type' => 'string' ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string' ], 'bravo' => [ 'index' => "bravo", 'status' => false, 'type' => 'string' ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date' ], 'last_login_date' => [ 'index' => "amplivoUser", 'status' => false, 'type' => 'string' ], ], ], 'member_list_archive' => [ 'query' => $tableName == 'member_list_archive' ? CsrNowUser::with('hasRole','profile','amplivoUser')->where('archived_status', 1)->whereHas('hasRole', function ($query) { return $query->whereHas('role',function ($q){ $q->where('name','member'); }); })->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate); $q->whereDate('created_at', '<=', $endDate); } elseif ($key === 'name') { $q->where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%'); } elseif ($key === 'phone' || $key === 'gender') { $q->whereHas("profile", function ($innerQuery) use ($item,$key) { $innerQuery->where($key, 'like', $item . '%'); }); } elseif ($key === 'birthdate') { $q->whereHas("profile", function ($innerQuery) use ($item) { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $innerQuery->whereDate('date_of_birth', '>=', $startDate); $innerQuery->whereDate('date_of_birth', '<=', $endDate); }); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('created_at', 'desc') : [], 'page' => new CsrNowUser, 'header' => [ 'id' => '#', 'username' => 'Username', 'name' => 'Name', 'email' => 'Email', 'status' => 'Status', 'created_at' => 'Registration Time', 'last_login_time' => 'Last Login Time' ], 'data' => [ 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string' ], 'name' => [ 'index' => "first_name", 'status' => false, 'type' => 'string' ], 'email' => [ 'index' => "email", 'status' => false, 'type' => 'string' ], 'phone' => [ 'index' => "profile", 'relation' => true, 'relationKey' => 'phone', 'status' => false, 'type' => 'string', ], 'gender' => [ 'index' => "profile", 'relation' => true, 'relationKey' => 'gender', 'status' => false, 'type' => 'string', ], 'birthdate' => [ 'index' => "profile", 'relation' => true, 'relationKey' => 'date_of_birth', 'status' => false, 'type' => 'string', ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string' ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date' ] ], ], 'gift_codes' => [ 'query' => $tableName == 'gift_codes' ? GiftCode::with(['purchaseProduct', 'purchaseProduct.ProductStaticOption', 'purchaseProduct.walletLog','transferredUser','user'])->with('redeemedBy','user') ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'name') { if ($item == 'Plastic Neutrality Package'){ $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->whereNull('product_static_option_id'); }); } else { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->whereHas("ProductStaticOption", function ($q) use ($item) { $q->where('title', 'like', '%' . $item . '%'); }); }); } } else if ($key == 'price') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->where("price", [$item]); }); } else if ($key == 'package_date') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); }); } else if ($key == 'expiration_date') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('expire_date', '>=', $startDate)->whereDate('expire_date', '<=', $endDate); }else if ($key == 'redeemed_date') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('redeemed_date', '>=', $startDate)->whereDate('redeemed_date', '<=', $endDate); } else if ($key == 'redeem_by') { $externalId = CsrNowUser::where('username', 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('redeem_by',$userId); } else if ($key == 'transferred_by') { $externalId = CsrNowUser::where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereNotNull('transferred_user_id')->whereIntegerInRaw('user_id',$userId); } else if ($key == 'transferred_to') { $externalId = CsrNowUser::where(DB::raw("CONCAT(first_name,' ',last_name)"), 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('transferred_user_id',$userId); } else if ($key == 'purchase_by') { $externalId = CsrNowUser::where('username', 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('user_id',$userId); } else if ($key == 'status') { if ($item === 'Pending') { $q->where("status", 1); } else if ($item === 'Redeemed') { $q->where("status", 2); } else if ($item === 'Rejected') { $q->where("status", 4); } else if ($item === 'Canceled') { $q->where("status", 5); } else if ($item === 'Expired') { $q->where(function ($q){ $q->where("status", 3); $q->orWhereDate("expire_date",'<',date('Y-m-d')); }); } } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('id', 'desc') : [], 'page' => new User, 'header' => ['counter' => '#', 'transaction_id' => 'Purchase ID','purchase_by' => 'Purchase By','name' => 'Package Name', 'price' => 'Price', 'gift_code' => 'Gift Code', 'package_date' => 'Purchase Date', 'expiration_date' => 'Expiration Date', 'redeemed_date' => 'Redemption Date','redeem_by' => 'Redeemed By','transferred_by' => 'Transferred By','transferred_to' => 'Transferred To', 'status' => 'Status'], 'data' => [ 'transaction_id' => [ 'index' => "transaction_id", 'status' => false, 'type' => 'string', ], 'purchase_by' => [ 'index' => "purchase_by", 'status' => false, 'type' => 'string', ], 'name' => [ 'index' => "name", 'status' => false, 'type' => 'string', ], 'price' => [ 'index' => "price", 'status' => false, 'type' => 'string', ], 'gift_code' => [ 'index' => "gift_code", 'status' => false, 'type' => 'string', ], 'package_date' => [ 'index' => "package_date", 'status' => false, 'type' => 'string', ], 'expiration_date' => [ 'index' => "expiration_date", 'status' => false, 'type' => 'string', ], 'redeemed_date' => [ 'index' => "redeemed_date", 'status' => false, 'type' => 'string', ], 'redeem_by' => [ 'index' => "redeem_by", 'status' => false, 'type' => 'string', ], 'transferred_by' => [ 'index' => "user_id", 'status' => false, 'type' => 'string', ], 'transferred_to' => [ 'index' => "transferred_user_id", 'status' => false, 'type' => 'string', ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string', ], ], ], 'redeemed_gift_codes' => [ 'query' => $tableName == 'redeemed_gift_codes' ? GiftCode::with('user','purchaseProduct','purchaseProduct.walletLog','purchaseProduct.ProductStaticOption') ->with('redeemedBy') ->whereNotNull('redeem_by') ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'name') { if ($item == 'Plastic Neutrality Package'){ $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->whereNull('product_static_option_id'); }); } else { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->whereHas("ProductStaticOption", function ($q) use ($item) { $q->where('title', 'like', '%' . $item . '%'); }); }); } } else if ($key == 'username') { $externalId = CsrNowUser::where("username", 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereIntegerInRaw('redeem_by',$userId); } else if ($key == 'transaction_id') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->whereHas("walletLog", function ($q) use ($item) { $q->where('transaction_id', 'like', '%' . $item . '%'); }); }); } else if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('redeemed_date', '>=', $startDate)->whereDate('redeemed_date', '<=', $endDate); } else if ($key == 'amount') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->where('price', 'like', '%' . $item . '%'); }); } else if ($key == 'type') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->where('product_type', $item); }); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('id', 'desc') : [], 'page' => new GiftCode, 'header' => ['counter' => '#', 'username' => 'Username','name' => 'Name Of Product', 'gift_code' => 'Redeem Code', 'amount' => 'Amount', 'created_at' => 'Redeem Date', 'principal_kgs' => 'Principal Kgs', 'bonus_kgs' => 'Bonus Kgs', 'discount_kgs' => 'Discount Kgs', 'status' => 'Status', 'type' => 'Type [ Product / Licence ]', 'transaction_id' => 'Transaction Id','reference_no' => 'Reference No'], 'data' => [ 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string', ], 'name' => [ 'index' => "name", 'status' => false, 'type' => 'string', ], 'amount' => [ 'index' => "amount", 'status' => false, 'type' => 'string', ], 'gift_code' => [ 'index' => "gift_code", 'status' => false, 'type' => 'string', ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "redeemed_date", 'status' => false, 'type' => 'string', ], 'principal_kgs' => [ 'index' => "principal_kgs", 'status' => false, 'type' => 'string', ], 'bonus_kgs' => [ 'index' => "bonus_kgs", 'status' => false, 'type' => 'string', ], 'discount_kgs' => [ 'index' => "discount_kgs", 'status' => false, 'type' => 'string', ], 'type' => [ 'index' => "type", 'status' => false, 'type' => 'string', ], 'transaction_id' => [ 'index' => "transaction_id", 'status' => false, 'type' => 'string', ], 'reference_no' => [ 'index' => "reference_no", 'status' => false, 'type' => 'string', ], ], ], 'sa_purchase' => [ 'query' => $tableName == 'sa_purchase' ? GiftCode::with('purchaseProduct','purchaseProduct.ProductStaticOption')->whereHas('purchaseProduct', function ($query) use ($ids) { $query->where('transaction_id', basicDecrypt($ids[0])); })->with(['redeemedBy', 'user', 'purchaseProduct']) ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'name') { } else if ($key == 'description') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->whereHas("ProductStaticOption", function ($q) use ($item) { $q->where('title', 'like', '%' . $item . '%'); }); }); } else if ($key == 'price' || $key == 'description') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $q->where("price", [$item]); }); } else if ($key == 'package_date') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); }); } else if ($key == 'expiration_date') { $q->whereHas("purchaseProduct", function ($q) use ($item) { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('expire_date', '>=', $startDate)->whereDate('expire_date', '<=', $endDate); }); } else if ($key == 'redeem_by') { $q->whereHas("redeemedBy", function ($q) use ($item) { $q->whereHas("details", function ($q) use ($item) { $q->where('username', 'like', '%' . trim($item) . '%'); }); }); } else if ($key == 'purchase_by') { $q->whereHas("user", function ($q) use ($item) { $q->whereHas("details", function ($q) use ($item) { $q->where('username', 'like', '%' . trim($item) . '%'); }); }); } else if ($key == 'status') { if ($item === 'Active') { $q->where("status", 1); } else if ($item === 'Redeem') { $q->where("status", 2); } else if ($item === 'Expired') { $q->where("status", 3); } else if ($item === 'Canceled') { $q->where("status", 5); } } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('id', 'desc') : [], 'page' => new User, 'header' => ['counter' => '#', 'transaction_id' => 'Transaction Id', 'description' => 'Product', 'price' => 'Price', 'gift_code' => 'Gift Code', 'package_date' => 'Purchase Date', 'expiration_date' => 'Expiration Date','redeemed_date' => 'Redemption Date','purchase_by' => 'Buyer', 'redeem_by' => 'Redeem By', 'status' => 'Status'], 'data' => [ 'purchase_by' => [ 'index' => "purchase_by", 'status' => false, 'type' => 'string', ], 'description' => [ 'index' => "description", 'status' => false, 'type' => 'string', ], 'transaction_id' => [ 'index' => "transaction_id", 'status' => false, 'type' => 'string', ], 'price' => [ 'index' => "price", 'status' => false, 'type' => 'string', ], 'gift_code' => [ 'index' => "gift_code", 'status' => false, 'type' => 'string', ], 'package_date' => [ 'index' => "package_date", 'status' => false, 'type' => 'string', ], 'expiration_date' => [ 'index' => "expiration_date", 'status' => false, 'type' => 'string', ], 'redeemed_date' => [ 'index' => "redeemed_date", 'status' => false, 'type' => 'string', ], 'redeem_by' => [ 'index' => "redeem_by", 'status' => false, 'type' => 'string', ], 'status' => [ 'index' => "status", 'status' => false, 'type' => 'string', ], ], ], 'bv' => [ 'query' => $tableName == 'bv' ? BV::with('user') ->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'bv_created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else if ($key == 'gift_code_id') { $q->whereJsonContains('data->gift_code_id', $item); } else { $q->where($key, $item); } } } })->orderBy('id', 'desc') : [], 'page' => new BV, 'header' => ['counter' => '#','username' => 'Username','value' => 'Amount','source' => 'Description','gift_code_id' => 'Gift Code','created_at' => 'Date'], 'data' => [ 'username' => [ 'index' => "username", 'status' => false, 'type' => 'string', ], 'value' => [ 'index' => "value", 'status' => false, 'type' => 'string', ], 'source' => [ 'index' => "source", 'status' => false, 'type' => 'string', ], 'gift_code_id' => [ 'index' => "gift_code_id", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'string', ], ], ],'invoices' => [ 'query' => $tableName == 'invoices' ? WalletLog::with('purchase','wallet','wallet.user') ->where(function ($query) use ($ids) { $query->where('action',WalletLog::ACTION_PURCHASE); if (!empty(basicDecrypt($ids[0])) && $ids[0] != 'index') { $query->where('id', basicDecrypt($ids[0])); } })->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($item) { if ($key == 'purchase_date') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate); $q->whereDate('created_at', '<=', $endDate); }else if ($key == 'price') { $q->whereRaw( 'ROUND(ABS(value) - ROUND(CAST(IFNULL(JSON_UNQUOTE(JSON_EXTRACT(data, "$.tax_data.total_amount")), 0) AS DECIMAL(20,10)), 2), 2) = ?', [round((float)trim($item), 2)] ); }else if ($key == 'tax') { $q->whereRaw('ROUND(CAST(IFNULL(JSON_UNQUOTE(JSON_EXTRACT(data, "$.tax_data.total_amount")), 0) AS DECIMAL(20,10)), 2) = ?', [ round((float)trim($item), 2) ]); } else if ($key == 'purchase_by') { $externalId = CsrNowUser::where("username", 'LIKE', '%' . trim($item) . '%')->pluck('id'); $userId = User::whereIntegerInRaw('external_id',$externalId)->pluck('id'); $q->whereHas("wallet", function ($q) use ($userId) { $q->whereIntegerInRaw('user_id',$userId); }); } else if ($key == 'value') { $q->whereRaw( 'ROUND(CAST(IFNULL(value, 0) AS DECIMAL(20,10)), 2) = ?', [round((float)trim($item), 2)] ); }else if ($key == 'name') { $names = explode(',', trim($item)); $q->whereHas('purchase.ProductStaticOption', function ($q) use ($names) { $q->whereIn('title', array_map('trim', $names)); }); } else { $q->where($key, 'like', '%' . $item . '%'); } } } })->orderBy('id', 'desc') : [], 'page' => new WalletLog, 'header' => ['counter' => '#','purchase_by' => 'Purchase By','purchase_date' => 'Purchase Date','name' => 'Package Name', 'value' => 'Total Price', 'price' => 'Price','tax' => 'Tax'], 'data' => [ 'purchase_by' => [ 'index' => "purchase_by", 'status' => false, 'type' => 'string', ], 'purchase_date' => [ 'index' => "purchase_date", 'status' => false, 'type' => 'string', ], 'name' => [ 'index' => "name", 'status' => false, 'type' => 'string', ], 'tax' => [ 'index' => "tax", 'status' => false, 'type' => 'string', ], 'value' => [ 'index' => "value", 'status' => false, 'type' => 'string', ], 'price' => [ 'index' => "price", 'status' => false, 'type' => 'string', ], ], ], 'tax_management' => [ 'query' => $tableName == 'tax_management' ? TaxManagement::with('country','state')->where('status',1)->when(count($filter), function ($query) use ($filter) { foreach ($filter as $key => $item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $query->whereDate('created_at', '>=', $startDate) ->whereDate('created_at', '<=', $endDate); } else if ($key == 'counter') { $query->where('id', $item + 1); } else if ($key == 'country_id') { $countryId = Country::where('country_name', 'like', '%' . $item . '%')->pluck('id'); $query->whereIntegerInRaw('country_id',$countryId); } else if ($key == 'state_id') { $stateId = State::where('name', 'like', '%' . $item . '%')->pluck('id'); $query->whereIntegerInRaw('state_id',$stateId); } else { $query->where($key, 'like', '%' . $item . '%'); } } }) : [], 'page' => new TaxManagement, 'header' => ['counter' => '#', 'tax_name' => 'Tax Name','tax_percentage' => 'Tax Percentage','country_id' => 'Country','state_id' => 'State', 'created_at' => 'Registration Date'], 'data' => [ 'tax_name' => [ 'index' => "tax_name", 'status' => false, 'type' => 'string', ], 'tax_percentage' => [ 'index' => "tax_percentage", 'status' => false, 'type' => 'string', ], 'country_id' => [ 'index' => "country", 'relation' => true, 'relationKey' => 'country_name', 'status' => false, 'type' => 'string', ], 'state_id' => [ 'index' => "state", 'relation' => true, 'relationKey' => 'name', 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date' ] ], ],'tax_management_archive' => [ 'query' => $tableName == 'tax_management_archive' ? TaxManagement::with('country','state')->where('status',2)->when(count($filter), function ($query) use ($filter) { foreach ($filter as $key => $item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $query->whereDate('created_at', '>=', $startDate) ->whereDate('created_at', '<=', $endDate); } else if ($key == 'counter') { $query->where('id', $item + 1); } else if ($key == 'country_id') { $query->whereHas("country", function ($q) use ($item) { $q->where('country_name', 'like', '%' . $item . '%'); }); } else if ($key == 'state_id') { $query->whereHas("state", function ($q) use ($item) { $q->where('name', 'like', '%' . $item . '%'); }); } else { $query->where($key, 'like', '%' . $item . '%'); } } }) : [], 'page' => new TaxManagement, 'header' => ['counter' => '#', 'tax_name' => 'Tax Name','tax_percentage' => 'Tax Percentage','country_id' => 'Country','state_id' => 'State', 'created_at' => 'Registration Date'], 'data' => [ 'tax_name' => [ 'index' => "tax_name", 'status' => false, 'type' => 'string', ], 'tax_percentage' => [ 'index' => "tax_percentage", 'status' => false, 'type' => 'string', ], 'country_id' => [ 'index' => "country", 'relation' => true, 'relationKey' => 'country_name', 'status' => false, 'type' => 'string', ], 'state_id' => [ 'index' => "state", 'relation' => true, 'relationKey' => 'name', 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date' ] ], ],'api_settings' => [ 'query' => $tableName == 'api_settings' ? ApiSettings::whereIn('blockchain', ['Tron','BSC','ERC20'])->when(count($filter), function ($q) use ($filter) { foreach ($filter as $key => $item) { if ($key == 'created_at') { $dates = explode(' - ', $item); $startDate = createFromFormatCustom($dates[0]); $endDate = createFromFormatCustom($dates[1]); $q->whereDate('created_at', '>=', $startDate)->whereDate('created_at', '<=', $endDate); } else { $q->where($key, 'like', '%' . $item . '%'); } } })->orderBy('created_at', 'desc') : [], 'page' => new ProductStaticOption, 'header' => [ 'id' => '#', 'test_api_source' => 'Test API Source', 'live_api_source' => 'Live API Source', 'api_key' => 'API Key','blockchain' => 'Blockchain','created_at' => 'Created At' ], 'data' => [ 'test_api_source' => [ 'index' => "test_api_source", 'status' => false, 'type' => 'string' ], 'live_api_source' => [ 'index' => "live_api_source", 'status' => false, 'type' => 'string' ], 'api_key' => [ 'index' => "api_key", 'status' => false, 'type' => 'string', ], 'blockchain' => [ 'index' => "blockchain", 'status' => false, 'type' => 'string', ], 'created_at' => [ 'index' => "created_at", 'status' => false, 'type' => 'date', ] ], ] ]; return $temp; } public function sendEmail($folder, $file, $user) { $details = [ 'name' => ($user->details->first_name ?? '')." ".($user->details->first_name ?? ''), 'email' => $user->details->email, 'file' => $file, 'folder' => $folder, ]; try { Mail::to($user->details->email)->send(new JobEmail($details)); } catch (Exception $exception) { // dd($exception); reportLog($exception); } } /** * @throws Exception */ public function zipfile($filter, $defaultSearch, $columns, $keys, $table, $user, $type, $ids) { $fieldsTable = $this->exportData($filter, $defaultSearch, $table, $user, $ids); if ($table == "orderlist") { $investorShareLog = $fieldsTable['query']->all(); } else { $investorShareLog = $fieldsTable['query']->get(); } $page = $fieldsTable['page']->pageName ?? 'Logs'; if ($table == 'news_sa') { $page = 'News'; } else if ($table == 'press_sa') { $page = 'Press'; } else if ($table == 'activity_log_my' || $table == 'activity_log_sm_my' || $table == 'activity_log_cm' || $table == 'activity_log_sa_my' || $table == 'activity_log_investor_my' || $table == 'activity_log_translator_my') { $page = 'My Logs'; } else if ($table == 'csrlist') { $page = 'CSR list field settings'; } else if ($table == 'orderlist') { $page = 'Order field settings'; } else if ($table == 'sa_csr_holder_list') { $page = 'CSR Holders list'; } else if ($table == 'member_withdraw_history') { $page = 'User Withdraw'; } else if ($table == 'member_transfer_history') { $page = 'User Transfer'; } else if ($table == 'member_all_history') { $page = 'User All'; } else if ($table == 'member_seller_zone') { $page = 'Payment Links'; } else if ($table == 'sa_csr_retirement_setting') { $page = 'Review Logo & Url'; } else if ($table == 'country_settings_sm' || $table == 'country_settings_sm_archive') { $page = 'Countries'; } else if ($table == 'su_wallet_transaction') { $page = 'Transaction History'; } else if ($table == 'redeemed_gift_codes') { $page = 'Redemption'; } else if ($table == 'gift_codes') { $page = 'My Gift Code'; } else if ($table == 'api_settings') { $page = 'Crypto API'; } else if ($table == 'member_list') { $page = 'Member'; } else if ($table == 'activity_log_dashboard') { $page = 'My Logs'; } else if ($table == 'product_static_options' || $table == 'product_static_options_archive') { $page = 'Product Static Option'; } else if ($table == 'invoices') { $page = 'Purchase'; } else if ($table == 'sa_purchase') { $page = 'Purchase'; } else if ($table == 'redemption_req_list') { $page = 'Redemption Request List'; } else if ($table == 'member_wallet_log' || $table == 'wallet_log') { $page = 'Wallet Log'; } else if ($table == 'star_rank_report') { $page = 'Star Rank Report'; } else if ($table == 'wallet_report') { $page = 'Wallet Report'; } if (!File::exists(public_path() . "/files")) { File::makeDirectory(public_path() . "/files"); } $date = Carbon::now()->format('Ymd'); $pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstvwxyz"), 0, 8); if (!File::exists(public_path() . "/files" . "/" . $pass)) { File::makeDirectory(public_path() . "/files" . "/" . $pass); } $time = 'files' . "/" . $pass . '/' . config('app.name') . '-' . $page . '-' . $date . '.csv'; $filename = public_path() . '/' . $time; $file = fopen($filename, 'a+'); fputcsv($file, $columns); $counter = 1; foreach ($investorShareLog as $mainKey => $investment) { $row = $this->dataFormet($fieldsTable, $investment, $counter, $table); $temp = array(); foreach ($keys as $itm) { if ($itm != 'id') { if ($itm == 'index') { $temp[] = $row['counter']; } else { $temp[] = $row[$itm] ?? ''; } } else { $temp[] = $row['counter']; } } fputcsv($file, $temp); $counter++; } fclose($file); if ($type == 'zip') { $tempFilePath = public_path() . '/files' . '/' . $pass; $zip = Zip::create(public_path() . '/files' . '/' . $pass . '/' . config('app.name') . '-' . $page . '-' . $date . '.zip'); $zip->add($tempFilePath . '/' . config('app.name') . '-' . $page . '-' . $date . '.csv'); $zip->close(); } $log = 'Exported ' . $type . ' file of ' . $page; saveLog($log, $user, [], "export"); return ['folder' => $tempFilePath, 'file' => config('app.name') . '-' . $page . '-' . $date . '.zip']; } public function clearData() { $directory = 'files'; $files = Storage::disk('publicfolder')->directories($directory); $hours = getSiteSettings('download_file_delete_time'); $hours = -1 * $hours; $date = strtotime(Carbon::now()->addHours($hours)); foreach ($files as $file) { $temp = filectime(public_path() . '/' . $file); if ($temp < $date) { $subFiles = Storage::disk('publicfolder')->files($file); if (count($subFiles) == 1) { foreach ($subFiles as $item) { $fileName = basename($item); if (str_contains($fileName, '.csv')) { $log = 'Deleted ' . $fileName; saveLog($log, null, [], "deleted"); } } } else { foreach ($subFiles as $item) { $fileName = basename($item); if (str_contains($fileName, '.zip')) { $log = 'Deleted ' . $fileName; saveLog($log, null, [], "deleted"); } } } File::deleteDirectory(public_path($file)); } } } }