testing invoiceAmount

This commit is contained in:
2021-05-31 17:56:14 +09:00
parent d842e7bc02
commit a0e6fc6157

View File

@@ -37,40 +37,115 @@ class TestController extends Controller
} }
public function DebugMiningTaxesInvoices() { public function DebugMiningTaxesInvoices() {
$lookup = new LookupHelper; //Declare variables
$mailDelay = 15;
$mains = new Collection;
$perms = null;
/**
* This section will determine if users are mains or alts of a main.
* If they are mains, we keep the key. If they are alts of a main, then we delete
* the key from the collection.
*/
//Pluck all the users from the database of ledgers to determine if they are mains or alts.
$tempMains = Ledger::where([
'invoiced' => 'No',
])->where('last_updated', '>', Carbon::now()->subDays(7))->pluck('character_id');
//Get the unique character ids from the ledgers in the previous statement
$tempMains = $tempMains->unique()->values()->all();
//Cycle through the array of mains, and remove any characters which are in the User Alt table,
//as those characters will be grouped with their correct main later.
for($i = 0; $i < sizeof($tempMains); $i++) {
if(UserAlt::where(['character_id' => $tempMains[$i]])->count() == 0) {
$mains->push($tempMains[$i]);
}
}
/**
* For each of the users, let's determine if there are any ledgers,
* then determine if there are any alts and ledgers associated with the alts.
*/
foreach($mains as $main) {
//Declare some variables for each run through the for loop
$ledgers = new Collection; $ledgers = new Collection;
$perms = new Collection;
//Count the ledgers for the main
$mainLedgerCount = Ledger::where([
'character_id' => $main,
'invoiced' => 'No',
])->where('last_updated', '>', Carbon::now()->subDays(7))->count();
var_dump(auth()->user()->getAlts()); //If there are ledgers for the main, then let's grab them
dd(auth()->user()->altCount()); if($mainLedgerCount > 0) {
$mainLedgers = Ledger::where([
'character_id' => $main,
'invoiced' => 'No',
])->where('last_updated', '>', Carbon::now()->subDays(7))->get();
//Get all of the users in the database //Cycle through the entries, and add them to the ledger to send with the invoice
$users = User::all(); foreach($mainLedgers as $row) {
$ledgers->push([
//Get a list of the alts for each character, then process the ledgers and combine them to send one mail out 'character_id' => $row->character_id,
//in this first part 'character_name' => $row->character_name,
foreach($users as $char) { 'observer_id' => $row->observer_id,
$altCount = $char->altCount(); 'type_id' => $row->type_id,
'ore_name' => $row->ore_name,
'quantity' => (int)$row->quantity,
'amount' => (float)$row->amount,
'last_updated' => $row->last_updated,
]);
}
}
//Get the alt count for the main character
$altCount = UserAlt::where(['main_id' => $main])->count();
//If more than 0 alts, grab all the alts.
if($altCount > 0) { if($altCount > 0) {
$alts = $char->getAlts(); $alts = UserAlt::where([
'main_id' => $main,
])->get();
//Cycle through the alts, and get the ledgers, and push onto the stack
foreach($alts as $alt) { foreach($alts as $alt) {
$perms->push([ $altLedgerCount = Ledger::where([
'main_id' => $char->character_id, 'character_id' => $alt->character_id,
'alt_id' => $alt->character_id, 'invoiced' => 'No',
'count' => $altCount, ])->where('last_updated', '>', Carbon::now()->subDays(7))->count();
if($altLedgerCount > 0) {
$altLedgers = Ledger::where([
'character_id' => $alt->character_id,
'invoiced' => 'No',
])->where('last_updated', '>', Carbon::now()->subDays(7))->get();
foreach($altLedgers as $row) {
$ledgers->push([
'character_id' => $row->character_id,
'character_name' => $row->character_name,
'observer_id' => $row->observer_id,
'type_id' => $row->type_id,
'ore_name' => $row->ore_name,
'quantity' => (int)$row->quantity,
'amount' => (float)$row->amount,
'last_updated' => $row->last_updated,
]); ]);
} }
} else {
$perms->push([
'main_id' => $char->character_id,
'alt_id' => null,
'count' => 0,
]);
} }
} }
}
/**
* Send the collected information over to the function to send the actual mail
*/
if($ledgers->count() > 0) {
$invoiceAmount = round(((float)$ledgers->sum('amount') * (float)$config['mining_tax']), 2);
var_dump($ledgers);
}
}
return view('test.miningtax.invoice')->with('perms', $perms); return view('test.miningtax.invoice')->with('perms', $perms);
} }