Skip to content

Instantly share code, notes, and snippets.

@InspectorGadget
Last active December 10, 2018 05:38
Show Gist options
  • Save InspectorGadget/92ea52d84e768554662110204b652397 to your computer and use it in GitHub Desktop.
Save InspectorGadget/92ea52d84e768554662110204b652397 to your computer and use it in GitHub Desktop.
PHP
<?php
public function setFinance($month, $year, $param, $money) {
if ($this->checkFinance($month, $year) !== false) { // UPDATE
switch (strtolower($param)) {
case "inbound":
$previousInbound = $this->returnPrevInbound($month, $year);
$newInbound = $previousInbound + $money;
$run = $this->updateDatabase($month, $year, "inbound", $newInbound);
if ($run === true) {
return true;
} else {
// return false;
var_dump($run);
}
break;
case "outbound":
$previousOutbound = $this->returnPrevOutbound($month, $year);
$newOutbound = $previousOutbound + $money;
$run = $this->updateDatabase($month, $year, "outbound", $newOutbound);
if ($run === true) {
return true;
} else {
// return false;
var_dump($run);
}
break;
}
} else {
$createdOn = time();
$sql = "INSERT INTO financial (inbound, outbound, month, year, createdOn) VALUES (?, ?, ?, ?, ?)";
$stmt = mysqli_stmt_init($this->storedSQL);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "Prepare Failed!";
exit();
} else {
switch (strtolower($param)) {
case "inbound":
$outbound = (int) 0;
mysqli_stmt_bind_param($stmt, "ssss", $money, $outbound, $month, $year, $createdOn);
$result = mysqli_stmt_execute($stmt);
if ($result) {
echo "Record Created! : Inbound";
} else {
echo "Failed to create record! : Inbound";
}
break;
case "outbound":
$inbound = (int) 0;
mysqli_stmt_bind_param($stmt, "ssss", $inbound, $money, $month, $year, $createdOn);
$result = mysqli_stmt_execute($stmt);
if ($result) {
echo "Record Created! : Outbound";
} else {
echo "Failed to create record! : Outbound";
}
break;
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment