-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac1696b
commit 3d2ed03
Showing
4 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
app/Console/Commands/VoucherSets/GenerateVoucherSetVouchersCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\VoucherSets; | ||
|
||
use App\Models\User; | ||
use App\Models\Voucher; | ||
use App\Models\VoucherSet; | ||
use App\Services\VoucherSetService; | ||
use Illuminate\Console\Command; | ||
|
||
class GenerateVoucherSetVouchersCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:voucher-set:vouchers:generate'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Generates vouchers for a newly created voucher set'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$voucherSet = VoucherSet::where('is_denomination_valid', 1)->whereNull('voucher_generation_started_at')->whereNull('voucher_generation_finished_at')->first(); | ||
|
||
if ($voucherSet) { | ||
$voucherSet->voucher_generation_started_at = now(); | ||
$voucherSet->save(); | ||
|
||
/** | ||
* Re-validate the denomination JSON | ||
*/ | ||
$voucherSetIsValid = VoucherSetService::validateVoucherSetDenominations($voucherSet); | ||
|
||
if (!$voucherSetIsValid) { | ||
$notifyUser = User::where('email', env('MAIL_DEFAULT_EMAIL'))->first(); | ||
|
||
if ($notifyUser) { | ||
// notify that 'The voucher set denomination was invalid' | ||
// $notifyUser->notify(new VoucherSetCanNotBeGenerated($voucherSet, 'The voucher set denomination was invalid.')); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* voucher set denomination is valid | ||
*/ | ||
$denominationArray = json_decode($voucherSet->denomination_json, true); | ||
$numCreated = 0; | ||
foreach ($denominationArray as $denominationListing) { | ||
for ($i = 1; $i <= $denominationListing['number']; $i++) { | ||
$model = new Voucher(); | ||
$model->voucher_set_id = $voucherSet->id; | ||
$model->created_by_team_id = $voucherSet->created_by_team_id; | ||
$model->allocated_to_service_team_id = $voucherSet->allocated_to_service_team_id; | ||
$model->voucher_value_original = $denominationListing['value']; | ||
$model->voucher_value_remaining = $denominationListing['value']; | ||
$model->is_test = $voucherSet->is_test; | ||
$model->save(); | ||
|
||
$numCreated++; | ||
|
||
if (($numCreated % 100) == 0) { | ||
$this->line($numCreated . ' vouchers generated.'); | ||
} | ||
} | ||
} | ||
|
||
$voucherSet->voucher_generation_finished_at = now(); | ||
$voucherSet->save(); | ||
|
||
$notificationUser = User::find($voucherSet->created_by_user_id); | ||
|
||
if ($notificationUser) { | ||
// notify that 'The voucher set was successfully generated' | ||
// $notificationUser->notify(new VoucherSetWasGeneratedOkay($voucherSet)); | ||
} | ||
|
||
/** | ||
* Set the voucher aggregates | ||
*/ | ||
// dispatch(new SetVoucherSetAggregates($voucherSet)); | ||
|
||
/** | ||
* Set the team / agency budget aggregate data | ||
*/ | ||
// dispatch(new QueueTeamAgencyBudgetAggregates($voucherSet)); | ||
|
||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Jobs\Vouchers; | ||
|
||
use App\Models\Voucher; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Foundation\Queue\Queueable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\URL; | ||
|
||
class GenerateStorageVoucherQrCode implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct(public Voucher $voucher) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$redeemUrl = URL::to('/redeem/' . $this->voucher->voucher_set_id . '/' . $this->voucher->id); | ||
|
||
/** | ||
* PNG | ||
*/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
// PNG | ||
$dataPng = (new Generator())->format('png')->size(600)->generate($redeemUrl); | ||
$path = '/voucher-sets/'.$this->voucher->voucher_set_id.'/vouchers/individual/'.$this->voucher->id.'/png/voucher-qr.png'; | ||
$file = Storage::put($path, $dataPng); | ||
|
||
$path = '/voucher-sets/'.$this->voucher->voucher_set_id.'/vouchers/all/png/'.$this->voucher->id.'.png'; | ||
$file = Storage::put($path, $dataPng); | ||
|
||
// SVG | ||
$dataSvg = (new Generator())->format('svg')->size(600)->generate($redeemUrl); | ||
$path = '/voucher-sets/'.$this->voucher->voucher_set_id.'/vouchers/individual/'.$this->voucher->id.'/svg/voucher-qr.svg'; | ||
$file = Storage::put($path, $dataSvg); | ||
|
||
$path = '/voucher-sets/'.$this->voucher->voucher_set_id.'/vouchers/all/svg/'.$this->voucher->id.'.svg'; | ||
$file = Storage::put($path, $dataSvg); | ||
|
||
if (isset($this->voucher->team->voucherTemplate->voucher_template_path)) { | ||
dispatch(new GenerateStorageBrandedQrTemplate($this->voucher)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters