i have this function ::
public static function generateMonthly() //: JsonResponse
{
# dates
self::init();
#invoice settings
$otherInvoiceDetails = OtherInvoiceSettings::find(1);
$billingDay = date('d');
$toiletCost = 0;
$responseData = array();
if ($billingDay != null && $billingDay == self::$TODAY) :
if (!empty($allActiveCustomers = Customer::where(['status' => $ACTIVE=1])->get())) :
foreach ($allActiveCustomers as $customer) :
try {
# generate new invoice
$responseData[] = InvoiceService::generateInvoice($customer);
}
catch (\Exception $e) {
return $e->getMessage();
}
endforeach;
endif;
return 01;
}
When i call in a controller class and hit it as an API invoices are generated but when i created a command to hit the same method, command runs without errors but invoices are not generated.
Below is the content of the command class ::
<?php
namespace App\Console\Commands;
use App\Services\InvoiceService;
use Illuminate\Console\Command;
class AutogenerateInvoice extends Command
{
/**
* The name and signature of the console command.
*
* @var
string
*/
protected $signature = 'autogenerate:invoice';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command generates monthly invoice for customers';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
InvoiceService::generateMonthly();
}
}
below is the kernel content ::
/**
* The Artisan commands provided by your application.
*
* @var
array
*/
protected $commands = [
//
AutogenerateInvoice::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('tenancy:run autogenerate:invoice')->everyMinute();
}
Top comments (0)