= from_date} {--to_date= : Invoice created_at <= to_date} {--send : Also email the invoice to the customer}'; /** * The console command description. * * @var string */ protected $description = 'Regenerates the Processing Fee Invoice PDF on S3 for applications fetched from the invoices table'; public function __construct(){ parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle(){ $payload = [ 'application_ids' => $this->option('application_ids'), 'lender_id' => $this->option('lender_id'), 'merchant_id' => $this->option('merchant_id'), 'from_date' => $this->option('from_date'), 'to_date' => $this->option('to_date'), 'send' => $this->option('send') ? 1 : 0 ]; // drop the empty options so the controller only applies the filters passed in $payload = array_filter($payload, function ($value) { return $value !== null && $value !== ''; }); try { $result = (new TestingController())->generateProcessingFeeInvoiceDocuments(new Request($payload)); $this->info('Invoices fetched : ' . $result['fetched']); $this->info('Documents created: ' . count($result['generated'])); $this->info('Failed : ' . count($result['failed'])); foreach ($result['failed'] as $applicationId => $reason) { $this->error($applicationId . ' => ' . $reason); } return 0; } catch (\Exception $e) { $file = fopen('processing_fee_invoice_document_' . Carbon::now()->toDateString() . '.txt', 'a') or die('Unable to open file!'); fwrite($file, "\n" . $e->getMessage()); fwrite($file, "\n" . $e->getLine()); fwrite($file, "\n" . $e->getTraceAsString()); fwrite($file, "\n" . '--------------------'); fclose($file); $this->error($e->getMessage() . ' | line: ' . $e->getLine()); return 1; } } }