Path : /var/www/html/thb_loan_system/app/Console/Commands/ |
B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H |
Current File : /var/www/html/thb_loan_system/app/Console/Commands/SummaryReport.php |
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\Loan; class SummaryReport extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'summary:report'; /** * The console command description. * * @var string */ protected $description = 'This command will send summary report to telegram group'; /** * Execute the console command. * * @return int */ public function handle() { $apiToken = env('TELEGRAM_API_TOKEN', '6263559826:AAG4em1JAjlqgKgiRoqzbaUVYDuZs-bFoQY'); $groupId= env('TELEGRAM_GROUP_ID', '-1001854899010'); $todayOutStanding = \App\Helpers\GeneralHelper::loans_total_paid(); $todayRepayment = \App\Models\LoanTransaction::where('transaction_type','repayment')->where('reversed', 0)->where('date',date("Y-m-d"))->sum('credit'); $pandingLoanUrl = url('loan/data?status=pending'); $pendingLoan = Loan::query()->toBase() ->where("status", 'pending') // ->where('branch_id', session('branch_id')) ->count(); $message = "Today Outstanding = ".currency_converter($todayOutStanding)."\n"; $message .= "Today Repayment = ".currency_converter($todayRepayment)."\n"; $message .= "Pending Loan = ".$pendingLoan."\n"; $message .= "URL = ".$pandingLoanUrl."\n"; if($pendingLoan>0){ $this->sendMessage($groupId, $message, $apiToken); } } private function sendMessage($chatID, $messaggio, $token) { $url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chatID; $url = $url . "&text=" . urlencode($messaggio); $ch = curl_init(); $optArray = array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true ); curl_setopt_array($ch, $optArray); $result = curl_exec($ch); curl_close($ch); return $result; } }