From 47b09492901fbbc4f4e6fc084a4e9a5f89028b9a Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Tue, 12 May 2020 02:04:30 -0500 Subject: [PATCH] creating the moon rental invoice verify --- .../Moons/MoonRentalInvoiceCreate.php | 14 ++++ .../Moons/MoonRentalInvoiceVerify.php | 78 ++++++++++++++++++- app/Models/MoonRentals/MoonRentalInvoice.php | 1 + 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Commands/Moons/MoonRentalInvoiceCreate.php b/app/Jobs/Commands/Moons/MoonRentalInvoiceCreate.php index b03885f1a..5ae72447f 100644 --- a/app/Jobs/Commands/Moons/MoonRentalInvoiceCreate.php +++ b/app/Jobs/Commands/Moons/MoonRentalInvoiceCreate.php @@ -29,6 +29,20 @@ class MoonRentalInvoiceCreate implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * Timeout in seconds + * + * @var int + */ + public $timeout = 3600; + + /** + * Retries + * + * @var int + */ + public $retries = 3; + /** * Today's date * diff --git a/app/Jobs/Commands/Moons/MoonRentalInvoiceVerify.php b/app/Jobs/Commands/Moons/MoonRentalInvoiceVerify.php index 21f519837..53713514a 100644 --- a/app/Jobs/Commands/Moons/MoonRentalInvoiceVerify.php +++ b/app/Jobs/Commands/Moons/MoonRentalInvoiceVerify.php @@ -14,11 +14,28 @@ use Log; //App Models use App\Models\Finances\PlayerDonationJournal; +use App\Models\MoonRentals\MoonRentalInvoice; +use App\Models\MoonRentals\MoonRentalPayment; +use App\Models\MoonRentals\MoonRent; class MoonRentalInvoiceVerify implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + /** + * Timeout in seconds + * + * @var int + */ + public $timeout = 3600; + + /** + * Retries + * + * @var int + */ + public $retries = 3; + /** * Create a new job instance. * @@ -36,6 +53,65 @@ class MoonRentalInvoiceVerify implements ShouldQueue */ public function handle() { - // + //Create the date to look through + $date = Carbon::now()->subDays(60); + + //Get the open moon rental invoices + $unpaid = MoonRentalInvoice::where([ + 'Paid' => 'No', + ])->get(); + + //If there are no unpaid invoices, then return out of the job as successful + if($unpaid == null || $unpaid == false) { + return; + } + + //Foreach unpaid invoice, run through them and check if there is an entry in the player journal table to verify the invoice + foreach($unpaid as $un) { + //Get everything which has a description like the invoice code. + $checkA = PlayerDonationJournal::where('description', 'like', '%' . $un->invoice_id . '%')->get(); + + //Get the player donations and corp transfers which have the amount we are looking for + $checkB = PlayerDonationJournal::where([ + 'amount' => $un->invoice_amount, + ])->where('date', '>=', $date)->get(); + + //Check each of the checkA's for the correct description + foreach($checkA as $check) { + //Search for the sub string of the invoice id in the description + $desc = strstr($check->description, $un->invoice_id); + //If the description is found, then update the invoice. + //Create an invoice payment + if($desc == $un->invoice_id) { + //Insert a new moon rental payment once completed + MoonRentalPayment::insert([ + 'invoice_id' => $un->invoice_id, + 'payment_amount' => $un->invoice_amount, + 'reference_payment' => $check->id, + ]); + + //Update the invoice as paid + MoonRentalInvoice::where([ + 'invoice_id' => $un->invoice_id, + ])->update([ + 'Paid' => 'Yes', + ]); + + //Increase the moon rental by another month + $moons = $un->rental_moons; + //Turns the moons into an array + $moons = explode(',', $moons); + foreach($moons as $moon) { + //Need to separate each moon into system, planet, and moon to update the moon rental + + } + } + } + + //Check each of checkB's for the invoice amount + foreach($checkB as $check) { + + } + } } } diff --git a/app/Models/MoonRentals/MoonRentalInvoice.php b/app/Models/MoonRentals/MoonRentalInvoice.php index 12c438343..4bbf19b93 100644 --- a/app/Models/MoonRentals/MoonRentalInvoice.php +++ b/app/Models/MoonRentals/MoonRentalInvoice.php @@ -21,6 +21,7 @@ class MoonRentalInvoice extends Model * @var array */ protected $fillable = [ + 'invoice_id', 'character_id', 'character_name', 'corporation_id',