You would have more control running cron every minute to run the Laravel scheduler and then firing your commands from within the Laravel Scheduler.
Nov 15, 2020
8
Level 4
Multiple corn jobs command are not getting executed.
i have created the cron job for service charge, it works properly the purpose of service charge is to deduct a certain amount of money from every user after 10 months the same way i implemented cron job for default charge, and its purpose is to deduct a certain amount when user does not pay installment accordingly. Now the cron job for default does not get executed when i use it in cpanel. Hope someone can help me out
Service charge is working
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\SavingAcount;
use App\UserNotification;
use App\User;
use DB;
use App\Accounts;
use App\ServiceChrg;
class ServiceCharge extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'day:juneFirst';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Your Service Charge is automatically cut from your savings by our system. Thanks for stay with us';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$users = User::get();
foreach($users as $user) {
$total = 0;
if($user->hasSavings() == $user->id) {
$service_charges = new ServiceChrg();
$saving = SavingAcount::where('user_id', $user->id)
->latest()
->first();
$saving->total = $saving->total - 20;
$saving->save();
$service_charges->user_id = $user->id;
$service_charges->save();
$total += 20;
// Service charge goes to accounts
$accounts = new Accounts();
$accounts->service_charge = 20;
$accounts->user_id = $user->id;
$row = count(Accounts::select('service_charge')->where('user_id', $user->id)->get());
if($row == 0) {
$accounts->total_service_charge = 20;
$accounts->total = 20;
} else {
$prev_fees = Accounts::where('user_id', $user->id)->latest()->first();
$accounts->total_service_charge = 20 + $prev_amount->total_service_charge;
$accounts->total = $accounts->total_service_charge + $accounts->total_default_charge + $accounts->total_fee;
}
$accounts->save();
$username = "Alauddin101";
$hash = "4f9ec55ab0531a44a466910119d97847";
$numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
$message = '20tk has been deducted for your service charge. Thank you! Your current saving is '.$saving->total;
$params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
$accounts->save();
}
}
}
}
For Cpanel
/usr/local/bin/php /home/afreensh/bdloans.afreenshop.com/system/artisan day:juneFirst >> /dev/null 2>&1
Default Charge Command is not working. But I use same way
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\User;
use App\BusinessLoan;
use App\EduLoan;
use App\EmployeeLoan;
use App\SavingAcount;
use App\LoanInstallment;
class DefaultCharge extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'day:everyMonth';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Status of ddefault charge';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$users = User::get();
foreach ($users as $user) {
$user_id = $user->id;
if($user->hasBusinessLoans() == $user_id) {
$loan = BusinessLoan::where('user_id', $user->id)->where('completed', 0)->first();
$loan_installments = LoanInstallment::where('loan_id', $loan->id)->latest()->first();
if($loan_installments == '') {
// user doesn't give first installment
$saving = SavingAcount::where('user_id', $user->id)->latest()->first();
$saving->total = $saving->total - 20;
$saving->save();
// Default charge goes to accounts
$accounts = new Accounts();
$accounts->default_charge = 20;
$accounts->user_id = $user->id;
$row = count(Accounts::select('default_charge')->where('user_id', $user->id)->get());
if($row == 0) {
$accounts->total_default_charge = 20;
$accounts->total = 20;
} else {
$prev_fees = Accounts::where('user_id', $user->id)->latest()->first();
$accounts->total_default_charge = 20 + $prev_amount->total_default_charge;
$accounts->total = $accounts->total_service_charge + $accounts->total_default_charge + $accounts->total_fee;
}
$accounts->save();
$username = "Alauddin101";
$hash = "4f9ec55ab0531a44a466910119d97847";
$numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
$message = '20tk has been deducted for your late of Loan from saving. Thank you! Your current saving is '.$saving->total;
$params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
} else {
$to = \Carbon\Carbon::parse($loan->approved_date)->floorMonth();
$from = \Carbon\Carbon::parse($loan_installments->this_month)->floorMonth();
$net_installment_month = $to->diffInMonths($from);
if($loan_installments->amount < $net_installment_month * $loan->perInstallmentAmount) {
$saving = SavingAcount::where('user_id', $user->id)->latest()->first();
$saving->total = $saving->total - 20;
$saving->save();
// Default charge goes to accounts
$accounts = new Accounts();
$accounts->default_charge = 20;
$accounts->user_id = $user->id;
$row = count(Accounts::select('default_charge')->where('user_id', $user->id)->get());
if($row == 0) {
$accounts->total_default_charge = 20;
$accounts->total = 20;
} else {
$prev_fees = Accounts::where('user_id', $user->id)->latest()->first();
$accounts->total_default_charge = 20 + $prev_amount->total_default_charge;
$accounts->total = $accounts->total_service_charge + $accounts->total_default_charge + $accounts->total_fee;
}
$accounts->save();
$username = "Alauddin101";
$hash = "4f9ec55ab0531a44a466910119d97847";
$numbers = $user->mobile_number; //Recipient Phone Number multiple number must be separated by comma
$message = '20tk has been deducted for less amount then per installment amount of Loan from saving. Thank you! Your current saving is '.$saving->total;
$params = array('app'=>'ws', 'u'=>$username, 'h'=>$hash, 'op'=>'pv', 'unicode'=>'1','to'=>$numbers, 'msg'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://alphasms.biz/index.php?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
return 0;
} else {
return 0;
}
}
} elseif($user->hasEmployeeLoans() == $user_id) {
} elseif($user->hasEduLoans() == $user_id) {
} else {
// user has no loan
return 0;
}
}
}
}
Cpanel code for default charge
/usr/local/bin/php /home/afreensh/bdloans.afreenshop.com/system/artisan day:everyMonth >> /dev/null 2>&1
Please or to participate in this conversation.