Files
w4rpservices/app/Library/Taxes/TaxesHelper.php

199 lines
5.4 KiB
PHP

<?php
namespace App\Library\Taxes;
//Internal Library
use Carbon\Carbon;
//Models
use App\Models\User\User;
use App\Models\User\UserRole;
use App\Models\User\UserPermission;
use App\Models\Finances\ReprocessingTaxJournal;
use App\Models\Finances\StructureIndustryTaxJournal;
use App\Models\Finances\PlanetProductionTaxJournal;
use App\Models\Finances\OfficeFeesJournal;
use App\Models\Finances\JumpBridgeJournal;
use App\Models\Finances\PISaleJournal;
use App\Models\Finances\AllianceMarketJournal;
use App\Models\SRP\SRPShip;
class TaxesHelper {
private $corpId;
private $refType;
private $start;
private $end;
public function __construct($corp = null, $ref = null, $st = null, $en = null) {
$this->corpId = $corp;
$this->refType = $ref;
$this->start = $st;
$this->end = $en;
}
public function GetAllianceSRPActual($start, $end) {
$actual = 0.00;
$actual = SRPShip::where([
'approved' => 'Approved',
])->whereBetween('created_at', [$start, $end])
->sum('paid_value');
return $actual;
}
public function GetAllianceSRPLoss($start, $end) {
$loss = 0.00;
$loss = SRPShip::where([
'approved' => 'Approved',
])->whereBetween('created_at', [$start, $end])
->sum('loss_value');
return $loss;
}
public function GetAllianceMarketGross($start, $end) {
$revenue = 0.00;
$revenue = AllianceMarketJournal::where([
'second_party_id' => '98287666',
'ref_type' => 'brokers_fee',
])->whereBetween('date', [$start, $end])
->sum('amount');
return $revenue;
}
public function GetJumpGateGross($start, $end) {
$revenue = 0.00;
$revenue = JumpBridgeJournal::where([
'ref_type' => 'structure_gate_jump',
'second_party_id' => '98287666',
])->whereBetween('date', [$start, $end])
->sum('amount');
return $revenue;
}
public function GetIndustryGross($start, $end) {
$revenue = 0.00;
$revenue = StructureIndustryTaxJournal::where([
'ref_type' => 'industry_job_tax',
'second_party_id' => '98287666',
])->whereBetween('date', [$start, $end])
->sum('amount');
return $revenue;
}
public function GetReprocessingGross($start, $end) {
$revenue = 0.00;
$revenue = ReprocessingTaxJournal::where([
'ref_type' => 'reprocessing_tax',
'second_party_id' => '98287666',
])->whereBetween('date', [$start, $end])
->sum('amount');
return $revenue;
}
public function GetPIGross($start, $end) {
$revenueImport = 0.00;
$revenueExport = 0.00;
//Get the import revenue from the database
$revenueImport = PlanetProductionTaxJournal::where([
'ref_type' => 'planetary_import_tax',
'second_party_id' => '98287666',
])->whereBetween('date', [$start, $end])
->sum('amount');
//Get the export revenue from the database
$revenueExport = PlanetProductionTaxJournal::where([
'ref_type' => 'planetary_export_tax',
'second_party_id' => '98287666',
])->whereBetween('date', [$start, $end])
->sum('amount');
//Total up the two values
$finalRevenue = $revenueImport + $revenueExport;
//Return the values
return $finalRevenue;
}
public function GetOfficeGross($start, $end) {
$revenue = 0.00;
$revenue = OfficeFeesJournal::where([
'ref_type' => 'office_rental_fee',
'second_party_id' => '98287666',
])->whereBetween('date', [$start, $end])
->sum('amount');
return $revenue;
}
public function GetPiSalesGross($start, $end) {
$revenue = 0.00;
$grosses = PISaleJournal::whereBetween('date', [$start, $end])->get()->toArray();
foreach($grosses as $gross) {
$revenue += ($gross['quantity'] * $gross['unit_price']);
}
return $revenue;
}
/**
* Returns a set of dates from now until the amount of months has passed
*
* @var integer
* @returns array
*/
public function GetTimeFrameInMonths($months) {
//Declare an array of dates
$dates = array();
//Setup the start of the array as the basis of our start and end dates
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$end->hour = 23;
$end->minute = 59;
$end->second = 59;
if($months == 1) {
$dates = [
'start' => $start,
'end' => $end,
];
return $dates;
}
//Create an array of dates
for($i = 0; $i < $months; $i++) {
if($i == 0) {
$dates[$i]['start'] = $start;
$dates[$i]['end'] = $end;
}
$start = Carbon::now()->startOfMonth()->subMonths($i);
$end = Carbon::now()->endOfMonth()->subMonths($i);
$end->hour = 23;
$end->minute = 59;
$end->second = 59;
$dates[$i]['start'] = $start;
$dates[$i]['end'] = $end;
}
//Return the dates back to the calling function
return $dates;
}
}