Skip to content

Commit

Permalink
Deal with income entries
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Jun 25, 2023
1 parent 6720a9e commit 1d96ba3
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/pj2-based/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ function toJournalEntries($journal) {
"date" => $this->getField("date")
]);

// $milestone = $journal->getMilestone([
// $income = $journal->getIncome([
// "organization" => $this->getField("organization"),
// "projectr" => $this->getField("project"),
// "project" => $this->getField("project"),
// "date" => $this->getField("date")
// ]);

Expand Down Expand Up @@ -176,7 +176,7 @@ class Journal {

private $entries = [];
private $knownContracts = [];
private $knownMilestones = [];
private $knownIncomes = [];

function __construct() {
}
Expand Down Expand Up @@ -215,28 +215,28 @@ public function getContract($query) {
throw new Exception("Contract not found!");
}

public function getMilestone($query) {
foreach($this->knownMilestones as $milestone) {
if ($milestone["organization"] !== $query["organization"]) {
// echo "milestone organization " . $milestone["organization"] . " !== " . $query["organization"] . "\n";
public function getIncome($query) {
foreach($this->knownIncomes as $income) {
if ($income["organization"] !== $query["organization"]) {
// echo "income organization " . $income["organization"] . " !== " . $query["organization"] . "\n";
continue;
}
if ($milestone["project"] !== $query["project"]) {
// echo "milestone project " . $milestone["project"] . " !== " . $query["project"] . "\n";
if ($income["project"] !== $query["project"]) {
// echo "income project " . $income["project"] . " !== " . $query["project"] . "\n";
continue;
}
if (dateIsAfter($milestone["from"], $query["date"])) {
// echo "milestone started at " . $milestone["from"] . " which is after " . $query["date"] . "\n";
if (dateIsAfter($income["from"], $query["date"])) {
// echo "income started at " . $income["from"] . " which is after " . $query["date"] . "\n";
continue;
}
if (dateIsBefore($milestone["to"], $query["date"])) {
// echo "milestone ended at " . $milestone["to"] . " which is before " . $query["date"] . "\n";
if (dateIsBefore($income["to"], $query["date"])) {
// echo "income ended at " . $income["to"] . " which is before " . $query["date"] . "\n";
continue;
}
echo "milestone found! " . var_export($milestone) . "\n";
return $milestone;
echo "income found! " . var_export($income) . "\n";
return $income;
}
throw new Exception("Milestone not found!");
throw new Exception("Income not found!");
}

function addEntries($newEntries) {
Expand All @@ -249,6 +249,14 @@ function addEntries($newEntries) {
}
array_push($this->knownContracts[$newEntries[$i]["worker"]], $newEntries[$i]);
}
if ($newEntries[$i]["type"] == "income") {
$fullProject = $newEntries[$i]["organization"] . " : " . $newEntries[$i]["project"];
echo "Got income for '" . $fullProject . "'\n";
if (!isset($this->knownContracts[$fullProject])) {
$this->knownContracts[$fullProject] = [];
}
array_push($this->knownContracts[$fullProject], $newEntries[$i]);
}
}
}

Expand Down

0 comments on commit 1d96ba3

Please sign in to comment.