mail and market tax structure

This commit is contained in:
2018-12-08 04:25:59 -06:00
parent 417a1218d5
commit e54b2abed1
9 changed files with 209 additions and 8 deletions

View File

@@ -0,0 +1,104 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Carbon\Carbon;
use DB;
use Commands\Library\CommandHelper;
use App\Models\Market\MonthlyMarketTax;
use App\Models\ScheduledTask\ScheduleJob;
use App\Models\Corporation\CorpJournal;
use App\Models\Corporation\CorpStructure;
use App\Library\FinanceHelper;
class CalculateMarketTax extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'services:calculatemarkettax';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Calculate the market taxes owed to the holding corporation and store in the database.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Create the command helper container
$task = new CommandHelper('CorpJournal');
//Add the entry into the jobs table saying the job is starting
$task->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();
}
}

View File

@@ -7,10 +7,13 @@ use Carbon\Carbon;
use DB; use DB;
use Commands\Library\CommandHelper; use Commands\Library\CommandHelper;
use App\User;
use App\Models\Esi\EsiScope; use App\Models\Esi\EsiScope;
use App\Models\Esi\EsiToken; use App\Models\Esi\EsiToken;
use App\Library\Mail;
use App\Models\ScheduledTask\ScheduleJob; use App\Models\ScheduledTask\ScheduleJob;
use App\Models\Market\MonthlyMarketTax;
use App\Library\Mail;
use Seat\Eseye\Cache\NullCache; use Seat\Eseye\Cache\NullCache;
use Seat\Eseye\Configuration; use Seat\Eseye\Configuration;
@@ -58,8 +61,23 @@ class sendMail extends Command
//Add the entry into the jobs table saying the job is starting //Add the entry into the jobs table saying the job is starting
$task->SetStartStatus(); $task->SetStartStatus();
//Put our task in this section //Set the date
$mail = new Mail; $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 .
'<br>Market Taxes Owed: ' .
$bills->tax_owed .
'<br>Please remit to Spatial Forces';
$error = $mHelper->SendMail($bills->character_id, $bills->tax_owed, $subject, $body);
}
//Mark the job as finished //Mark the job as finished
$task->SetStopStatus(); $task->SetStopStatus();

View File

@@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel
Commands\sendMail::class, Commands\sendMail::class,
Commands\UpdateMoonPricing::class, Commands\UpdateMoonPricing::class,
Commands\DumpFleets::class, Commands\DumpFleets::class,
Commands\CalculateMarketTax::class,
]; ];
/** /**
@@ -40,9 +41,12 @@ class Kernel extends ConsoleKernel
$schedule->command('services:dumpfleets') $schedule->command('services:dumpfleets')
->dailyAt('05:00') ->dailyAt('05:00')
->withoutOverlapping(); ->withoutOverlapping();
//$schedule->command('services:sendmail') $schedule->command('services:calculatemarkettax')
// ->monthlyOn(1, '09:00') ->monthlyOn(1, '08:00')
// ->withoutOverlapping(); ->withoutOverlapping();
$schedule->command('services:sendmail')
->monthlyOn(1, '09:00')
->withoutOverlapping();
} }
/** /**

View File

@@ -47,10 +47,12 @@ class StructureController extends Controller
//Get the number of structures registered to a corporation //Get the number of structures registered to a corporation
$citadelCount = CorpStructure::where(['corporation_id' => $corpId, 'structure_type' => 'Citadel'])->count(); $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]) $tempMonthTaxesMarket = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corpId])
->whereBetween('date', [$start, $end]) ->whereBetween('date', [$start, $end])
->sum('amount'); ->sum('amount');
//Get the market taxes from last month from the database
$tempLastTaxesMarket = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corpId]) $tempLastTaxesMarket = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corpId])
->whereBetween('date', [$startLast, $endLast]) ->whereBetween('date', [$startLast, $endLast])
->sum('amount'); ->sum('amount');

View File

@@ -14,7 +14,7 @@ use Seat\Eseye\Eseye;
class Mail { class Mail {
public function SendMail($charId, $taxAmount, $subject) { public function SendMail($charId, $taxAmount, $subject, $body) {
//Retrieve the token for Amund Risalo //Retrieve the token for Amund Risalo
$token = DB::table('EsiTokens')->where('character_id', 93738489)->get(); $token = DB::table('EsiTokens')->where('character_id', 93738489)->get();
$configuration = Configuration::getInstance(); $configuration = Configuration::getInstance();

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models\Market;
use Illuminate\Database\Eloquent\Model;
class MonthlyMarketTax extends Model
{
// Table Name
protected $table = 'monthly_market_taxes';
// Timestamps
public $timestamps = true;
//Primary Key
public $primaryKey = 'id';
protected $fillable = [
'character_id',
'character_name',
'corporation_id',
'corporation_name',
'tax_owed',
'month',
'year',
];
}

View File

@@ -0,0 +1,40 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateMonthlyMarketTaxesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if(!Schema::hasTable('monthly_market_taxes')) {
Schema::create('monthly_market_taxes', function (Blueprint $table) {
$table->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');
}
}

View File

@@ -10,6 +10,7 @@ return array(
'App\\Console\\Commands\\DumpFleets' => $baseDir . '/app/Console/Commands/dumpFleets.php', 'App\\Console\\Commands\\DumpFleets' => $baseDir . '/app/Console/Commands/dumpFleets.php',
'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/getCorps.php', 'App\\Console\\Commands\\GetCorps' => $baseDir . '/app/Console/Commands/getCorps.php',
'App\\Console\\Commands\\UpdateMoonPricing' => $baseDir . '/app/Console/Commands/UpdateMoonPricing.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\\getLogisticContracts' => $baseDir . '/app/Console/Commands/getLogisticContracts.php',
'App\\Console\\Commands\\sendMail' => $baseDir . '/app/Console/Commands/sendmail.php', 'App\\Console\\Commands\\sendMail' => $baseDir . '/app/Console/Commands/sendmail.php',
'App\\Console\\Kernel' => $baseDir . '/app/Console/Kernel.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\\LogisticsController' => $baseDir . '/app/Http/Controllers/LogisticsController.php',
'App\\Http\\Controllers\\MoonsController' => $baseDir . '/app/Http/Controllers/MoonsController.php', 'App\\Http\\Controllers\\MoonsController' => $baseDir . '/app/Http/Controllers/MoonsController.php',
'App\\Http\\Controllers\\RegisterStructureController' => $baseDir . '/app/Http/Controllers/RegisterStructureController.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\\Controllers\\WikiController' => $baseDir . '/app/Http/Controllers/WikiController.php',
'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php', 'App\\Http\\Kernel' => $baseDir . '/app/Http/Kernel.php',
'App\\Http\\Middleware\\Authenticate' => $baseDir . '/app/Http/Middleware/Authenticate.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\\CheckForMaintenanceMode' => $baseDir . '/app/Http/Middleware/CheckForMaintenanceMode.php',
'App\\Http\\Middleware\\EncryptCookies' => $baseDir . '/app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\EncryptCookies' => $baseDir . '/app/Http/Middleware/EncryptCookies.php',
'App\\Http\\Middleware\\RedirectIfAuthenticated' => $baseDir . '/app/Http/Middleware/RedirectIfAuthenticated.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\\RequireRole' => $baseDir . '/app/Http/Middleware/RequireRole.php',
'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrimStrings' => $baseDir . '/app/Http/Middleware/TrimStrings.php',
'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\TrustProxies' => $baseDir . '/app/Http/Middleware/TrustProxies.php',

View File

@@ -405,6 +405,7 @@ class ComposerStaticInitc3f953f8a7291d41a76e1664339777c9
'App\\Console\\Commands\\DumpFleets' => __DIR__ . '/../..' . '/app/Console/Commands/dumpFleets.php', 'App\\Console\\Commands\\DumpFleets' => __DIR__ . '/../..' . '/app/Console/Commands/dumpFleets.php',
'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/getCorps.php', 'App\\Console\\Commands\\GetCorps' => __DIR__ . '/../..' . '/app/Console/Commands/getCorps.php',
'App\\Console\\Commands\\UpdateMoonPricing' => __DIR__ . '/../..' . '/app/Console/Commands/UpdateMoonPricing.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\\getLogisticContracts' => __DIR__ . '/../..' . '/app/Console/Commands/getLogisticContracts.php',
'App\\Console\\Commands\\sendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php', 'App\\Console\\Commands\\sendMail' => __DIR__ . '/../..' . '/app/Console/Commands/sendmail.php',
'App\\Console\\Kernel' => __DIR__ . '/../..' . '/app/Console/Kernel.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\\LogisticsController' => __DIR__ . '/../..' . '/app/Http/Controllers/LogisticsController.php',
'App\\Http\\Controllers\\MoonsController' => __DIR__ . '/../..' . '/app/Http/Controllers/MoonsController.php', 'App\\Http\\Controllers\\MoonsController' => __DIR__ . '/../..' . '/app/Http/Controllers/MoonsController.php',
'App\\Http\\Controllers\\RegisterStructureController' => __DIR__ . '/../..' . '/app/Http/Controllers/RegisterStructureController.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\\Controllers\\WikiController' => __DIR__ . '/../..' . '/app/Http/Controllers/WikiController.php',
'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php', 'App\\Http\\Kernel' => __DIR__ . '/../..' . '/app/Http/Kernel.php',
'App\\Http\\Middleware\\Authenticate' => __DIR__ . '/../..' . '/app/Http/Middleware/Authenticate.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\\CheckForMaintenanceMode' => __DIR__ . '/../..' . '/app/Http/Middleware/CheckForMaintenanceMode.php',
'App\\Http\\Middleware\\EncryptCookies' => __DIR__ . '/../..' . '/app/Http/Middleware/EncryptCookies.php', 'App\\Http\\Middleware\\EncryptCookies' => __DIR__ . '/../..' . '/app/Http/Middleware/EncryptCookies.php',
'App\\Http\\Middleware\\RedirectIfAuthenticated' => __DIR__ . '/../..' . '/app/Http/Middleware/RedirectIfAuthenticated.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\\RequireRole' => __DIR__ . '/../..' . '/app/Http/Middleware/RequireRole.php',
'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php', 'App\\Http\\Middleware\\TrimStrings' => __DIR__ . '/../..' . '/app/Http/Middleware/TrimStrings.php',
'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php', 'App\\Http\\Middleware\\TrustProxies' => __DIR__ . '/../..' . '/app/Http/Middleware/TrustProxies.php',