-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add payment cycle to csv/json export
feat: run db migration after restoring database feat: run db migration after importing db feat: store weekly the total yearly cost of subscriptions fix: double encoding in statistics labels
- Loading branch information
Showing
10 changed files
with
224 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php'; | ||
|
||
if (php_sapi_name() == 'cli') { | ||
$date = new DateTime('now'); | ||
echo "\n" . $date->format('Y-m-d') . " " . $date->format('H:i:s') . "<br />\n"; | ||
} | ||
|
||
$currentDate = new DateTime(); | ||
$currentDateString = $currentDate->format('Y-m-d'); | ||
|
||
function getPriceConverted($price, $currency, $database, $userId) | ||
{ | ||
$query = "SELECT rate FROM currencies WHERE id = :currency AND user_id = :userId"; | ||
$stmt = $database->prepare($query); | ||
$stmt->bindParam(':currency', $currency, SQLITE3_INTEGER); | ||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER); | ||
$result = $stmt->execute(); | ||
|
||
$exchangeRate = $result->fetchArray(SQLITE3_ASSOC); | ||
if ($exchangeRate === false) { | ||
return $price; | ||
} else { | ||
$fromRate = $exchangeRate['rate']; | ||
return $price / $fromRate; | ||
} | ||
} | ||
|
||
// Get all users | ||
|
||
$query = "SELECT id, main_currency FROM user"; | ||
$stmt = $db->prepare($query); | ||
$result = $stmt->execute(); | ||
|
||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) { | ||
$userId = $row['id']; | ||
$userCurrencyId = $row['main_currency']; | ||
$totalYearlyCost = 0; | ||
|
||
$query = "SELECT * FROM subscriptions WHERE user_id = :userId"; | ||
$stmt = $db->prepare($query); | ||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER); | ||
$resultSubscriptions = $stmt->execute(); | ||
|
||
while ($rowSubscriptions = $resultSubscriptions->fetchArray(SQLITE3_ASSOC)) { | ||
$price = getPriceConverted($rowSubscriptions['price'], $rowSubscriptions['currency_id'], $db, $userId); | ||
$totalYearlyCost += $price; | ||
} | ||
|
||
$query = "INSERT INTO total_yearly_cost (user_id, date, cost, currency) VALUES (:userId, :date, :cost, :currency)"; | ||
$stmt = $db->prepare($query); | ||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER); | ||
$stmt->bindParam(':date', $currentDateString, SQLITE3_TEXT); | ||
$stmt->bindParam(':cost', $totalYearlyCost, SQLITE3_FLOAT); | ||
$stmt->bindParam(':currency', $userCurrencyId, SQLITE3_INTEGER); | ||
|
||
if ($stmt->execute()) { | ||
echo "Inserted total yearly cost for user " . $userId . " with cost " . $totalYearlyCost . "<br />\n"; | ||
} else { | ||
echo "Error inserting total yearly cost for user " . $userId . "<br />\n"; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?php | ||
$version = "v2.40.0"; | ||
$version = "v2.41.0"; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.