diff --git a/app/Console/Commands/calculatemarkettax.php b/app/Console/Commands/calculatemarkettax.php new file mode 100644 index 000000000..e709e8e4f --- /dev/null +++ b/app/Console/Commands/calculatemarkettax.php @@ -0,0 +1,104 @@ +SetStartStatus(); + + //Setup helper classes + $hFinances = new FinanceHelper(); + $start = Carbon::now()->startOfMonth()->subMonth(); + $end = Carbon::now()->endOfMOnth()->subMonth(); + $end->hour = 23; + $end->minute = 59; + $end->second = 59; + + //Get the set of corporations from the structure table + $corps = CorpStructure::where(['structure_type' => 'Citadel'])->distinct('corporation_id'); + + foreach($corps as $corp) { + //Get the number of citadel counts to use in fuel block calculation + $citadelCount = CorpStructure::where(['corporation_id' => $corp->corporation_id, 'structure_type' => 'Citadel'])->count(); + //From the corp journal add up the taxes from the last month + $marketTaxes = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corp->corporation_id]) + ->whereBetween('date', [$start, $end]) + ->sum('amount'); + //Calculate the market fuel cost + $marketFuel = $hFinances->CalculateFuelBlockCost('market'); + //Calculate the market tax + $mTax = CorpStructure::where(['corporation_id' => $corp->corporation_id, 'structure_type' => 'Citadel'])->avg('tax'); + //Subtract the fuel cost from the market taxes + $tempTaxes = $marketTaxes - ($marketFuel * $citadelCount); + //Calculate the final tax in order to store in the database + $finalTaxes = $hFinancees->CalculateTax($tempTaxes, $mTax, 'market'); + //Check for a negative number and zero out if negative + if($finalTaxes < 0.00) { + $finalTaxes = 0.00; + } else { + $finalTaxes = number_format($finalTaxes, 2, '.', ','); + } + //Get the info about the structures from the database + $info = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first(); + //Store the value in the database + $bill = new MonthlyMarketTax; + $bill->character_id = $info->character_id; + $bill->character_name = $info->character_name; + $bill->corporation_id = $corp->corporation_id; + $bill->corporation_name = $info->corporation_name; + $bill->taxed_owed = $finalTaxes; + $bill->month = $start->monthName; + $bill->year = $start->year; + $bill->save(); + } + + //Mark the job as finished + $task->SetStopStatus(); + } +} diff --git a/app/Console/Commands/sendmail.php b/app/Console/Commands/sendmail.php index 563b14afa..0a1fb8e86 100644 --- a/app/Console/Commands/sendmail.php +++ b/app/Console/Commands/sendmail.php @@ -7,10 +7,13 @@ use Carbon\Carbon; use DB; use Commands\Library\CommandHelper; +use App\User; use App\Models\Esi\EsiScope; use App\Models\Esi\EsiToken; -use App\Library\Mail; use App\Models\ScheduledTask\ScheduleJob; +use App\Models\Market\MonthlyMarketTax; + +use App\Library\Mail; use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Configuration; @@ -58,8 +61,23 @@ class sendMail extends Command //Add the entry into the jobs table saying the job is starting $task->SetStartStatus(); - //Put our task in this section - $mail = new Mail; + //Set the date + $date = Carbon::now()->subMonth(); + //Set the mail helper variable + $mHelper = new Mail(); + + //Get the full list of bills to send out + $bills = MonthlyMarketTax::where(['month' => $date->monthName, 'year' => $date->year])->get(); + //For each of the bills send a mail out + foreach($bills as $bill) { + $subject = 'Market Taxes Owed'; + $body = 'Month: ' . + $bill->month . + '
Market Taxes Owed: ' . + $bills->tax_owed . + '
Please remit to Spatial Forces'; + $error = $mHelper->SendMail($bills->character_id, $bills->tax_owed, $subject, $body); + } //Mark the job as finished $task->SetStopStatus(); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 29a8811af..d64c31736 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel Commands\sendMail::class, Commands\UpdateMoonPricing::class, Commands\DumpFleets::class, + Commands\CalculateMarketTax::class, ]; /** @@ -40,9 +41,12 @@ class Kernel extends ConsoleKernel $schedule->command('services:dumpfleets') ->dailyAt('05:00') ->withoutOverlapping(); - //$schedule->command('services:sendmail') - // ->monthlyOn(1, '09:00') - // ->withoutOverlapping(); + $schedule->command('services:calculatemarkettax') + ->monthlyOn(1, '08:00') + ->withoutOverlapping(); + $schedule->command('services:sendmail') + ->monthlyOn(1, '09:00') + ->withoutOverlapping(); } /** diff --git a/app/Http/Controllers/StructureController.php b/app/Http/Controllers/StructureController.php index 84f549ae1..896b01dc0 100644 --- a/app/Http/Controllers/StructureController.php +++ b/app/Http/Controllers/StructureController.php @@ -47,10 +47,12 @@ class StructureController extends Controller //Get the number of structures registered to a corporation $citadelCount = CorpStructure::where(['corporation_id' => $corpId, 'structure_type' => 'Citadel'])->count(); - dd($citadelCount); + + //Get the market taxes for this month from the database $tempMonthTaxesMarket = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corpId]) ->whereBetween('date', [$start, $end]) ->sum('amount'); + //Get the market taxes from last month from the database $tempLastTaxesMarket = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corpId]) ->whereBetween('date', [$startLast, $endLast]) ->sum('amount'); diff --git a/app/Library/Mail.php b/app/Library/Mail.php index 8894d6808..2bb5e4526 100644 --- a/app/Library/Mail.php +++ b/app/Library/Mail.php @@ -14,7 +14,7 @@ use Seat\Eseye\Eseye; class Mail { - public function SendMail($charId, $taxAmount, $subject) { + public function SendMail($charId, $taxAmount, $subject, $body) { //Retrieve the token for Amund Risalo $token = DB::table('EsiTokens')->where('character_id', 93738489)->get(); $configuration = Configuration::getInstance(); diff --git a/app/Models/Market/MonthlyMarketTax.php b/app/Models/Market/MonthlyMarketTax.php new file mode 100644 index 000000000..08f40e18b --- /dev/null +++ b/app/Models/Market/MonthlyMarketTax.php @@ -0,0 +1,27 @@ +increments('id'); + $table->string('character_id'); + $table->string('character_name'); + $table->string('corporation_id'); + $table->string('corporation_name'); + $table->decimal('tax_owed', 20, 2); + $table->string('month'); + $table->string('year'); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('monthly_market_taxes'); + } +} diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 3dc1a13a3..c7714e982 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -10,6 +10,7 @@ return array( 'App\\Console\\Commands\\DumpFleets' => $baseDir . '/app/Console/Commands/dumpFleets.php', 'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/getCorps.php', 'App\\Console\\Commands\\UpdateMoonPricing' => $baseDir . '/app/Console/Commands/UpdateMoonPricing.php', + 'App\\Console\\Commands\\calculatemarkettax' => $baseDir . '/app/Console/Commands/calculatemarkettax.php', 'App\\Console\\Commands\\getLogisticContracts' => $baseDir . '/app/Console/Commands/getLogisticContracts.php', 'App\\Console\\Commands\\sendMail' => $baseDir . '/app/Console/Commands/sendmail.php', 'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.php', @@ -29,6 +30,7 @@ return array( 'App\\Http\\Controllers\\LogisticsController' => $baseDir . '/app/Http/Controllers/LogisticsController.php', 'App\\Http\\Controllers\\MoonsController' => $baseDir . '/app/Http/Controllers/MoonsController.php', 'App\\Http\\Controllers\\RegisterStructureController' => $baseDir . '/app/Http/Controllers/RegisterStructureController.php', + 'App\\Http\\Controllers\\StructureController' => $baseDir . '/app/Http/Controllers/StructureController.php', 'App\\Http\\Controllers\\WikiController' => $baseDir . '/app/Http/Controllers/WikiController.php', 'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php', 'App\\Http\\Middleware\\Authenticate' => $baseDir . '/app/Http/Middleware/Authenticate.php', @@ -36,6 +38,7 @@ return array( 'App\\Http\\Middleware\\CheckForMaintenanceMode' => $baseDir . '/app/Http/Middleware/CheckForMaintenanceMode.php', 'App\\Http\\Middleware\\EncryptCookies' => $baseDir . '/app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\RedirectIfAuthenticated' => $baseDir . '/app/Http/Middleware/RedirectIfAuthenticated.php', + 'App\\Http\\Middleware\\RequirePermission' => $baseDir . '/app/Http/Middleware/RequirePermission.php', 'App\\Http\\Middleware\\RequireRole' => $baseDir . '/app/Http/Middleware/RequireRole.php', 'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index a636622db..5bdf0ad45 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -405,6 +405,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Console\\Commands\\DumpFleets' => __DIR__ . '/../..' . '/app/Console/Commands/dumpFleets.php', 'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/getCorps.php', 'App\\Console\\Commands\\UpdateMoonPricing' => __DIR__ . '/../..' . '/app/Console/Commands/UpdateMoonPricing.php', + 'App\\Console\\Commands\\calculatemarkettax' => __DIR__ . '/../..' . '/app/Console/Commands/calculatemarkettax.php', 'App\\Console\\Commands\\getLogisticContracts' => __DIR__ . '/../..' . '/app/Console/Commands/getLogisticContracts.php', 'App\\Console\\Commands\\sendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php', 'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.php', @@ -424,6 +425,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Http\\Controllers\\LogisticsController' => __DIR__ . '/../..' . '/app/Http/Controllers/LogisticsController.php', 'App\\Http\\Controllers\\MoonsController' => __DIR__ . '/../..' . '/app/Http/Controllers/MoonsController.php', 'App\\Http\\Controllers\\RegisterStructureController' => __DIR__ . '/../..' . '/app/Http/Controllers/RegisterStructureController.php', + 'App\\Http\\Controllers\\StructureController' => __DIR__ . '/../..' . '/app/Http/Controllers/StructureController.php', 'App\\Http\\Controllers\\WikiController' => __DIR__ . '/../..' . '/app/Http/Controllers/WikiController.php', 'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php', 'App\\Http\\Middleware\\Authenticate' => __DIR__ . '/../..' . '/app/Http/Middleware/Authenticate.php', @@ -431,6 +433,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9 'App\\Http\\Middleware\\CheckForMaintenanceMode' => __DIR__ . '/../..' . '/app/Http/Middleware/CheckForMaintenanceMode.php', 'App\\Http\\Middleware\\EncryptCookies' => __DIR__ . '/../..' . '/app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\RedirectIfAuthenticated' => __DIR__ . '/../..' . '/app/Http/Middleware/RedirectIfAuthenticated.php', + 'App\\Http\\Middleware\\RequirePermission' => __DIR__ . '/../..' . '/app/Http/Middleware/RequirePermission.php', 'App\\Http\\Middleware\\RequireRole' => __DIR__ . '/../..' . '/app/Http/Middleware/RequireRole.php', 'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php',