mirror of https://github.com/itflow-org/itflow
Transfers now fully work and Fixed some math on the dashboard and new DB dump
This commit is contained in:
parent
40c08a1635
commit
04fa61421a
|
|
@ -16,7 +16,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="date" required autofocus="autofocus">
|
||||
<input type="date" class="form-control" name="date" value="<?php echo date("Y-m-d"); ?>" required autofocus="autofocus">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md">
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-calendar"></i></span>
|
||||
</div>
|
||||
<input type="date" class="form-control" name="date" required>
|
||||
<input type="date" class="form-control" name="date" value="<?php echo date("Y-m-d"); ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-sm">
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
<?php include("header.php"); ?>
|
||||
|
||||
<?php
|
||||
|
||||
$sql_total_income = mysqli_query($mysqli,"SELECT SUM(invoice_payment_amount) AS total_income FROM invoice_payments");
|
||||
//Get Total income Do not grab transfer payment as these have an invoice_id of 0
|
||||
$sql_total_income = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_income FROM payments WHERE invoice_id > 0");
|
||||
$row = mysqli_fetch_array($sql_total_income);
|
||||
$total_income = $row['total_income'];
|
||||
|
||||
$sql_total_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses");
|
||||
//Get Total expenses and do not grab transfer expenses as these have a vendor of 0
|
||||
$sql_total_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE vendor_id > 0");
|
||||
$row = mysqli_fetch_array($sql_total_expenses);
|
||||
$total_expenses = $row['total_expenses'];
|
||||
|
||||
$sql_invoice_totals = mysqli_query($mysqli,"SELECT SUM(invoice_total) AS invoice_totals FROM invoices WHERE invoice_status NOT LIKE 'Draft'");
|
||||
//Total up all the
|
||||
$sql_invoice_totals = mysqli_query($mysqli,"SELECT SUM(invoice_amount) AS invoice_totals FROM invoices WHERE invoice_status NOT LIKE 'Draft'");
|
||||
$row = mysqli_fetch_array($sql_invoice_totals);
|
||||
$invoice_totals = $row['invoice_totals'];
|
||||
|
||||
|
|
@ -20,10 +22,10 @@ $profit = $total_income - $total_expenses;
|
|||
|
||||
$sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts ORDER BY account_id DESC");
|
||||
|
||||
$sql_latest_income_payments = mysqli_query($mysqli,"SELECT * FROM invoice_payments, invoices, clients
|
||||
WHERE invoice_payments.invoice_id = invoices.invoice_id
|
||||
$sql_latest_income_payments = mysqli_query($mysqli,"SELECT * FROM payments, invoices, clients
|
||||
WHERE payments.invoice_id = invoices.invoice_id
|
||||
AND invoices.client_id = clients.client_id
|
||||
ORDER BY invoice_payments.invoice_payment_id DESC LIMIT 5"
|
||||
ORDER BY payment_id DESC LIMIT 5"
|
||||
);
|
||||
|
||||
$sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, categories
|
||||
|
|
@ -99,7 +101,7 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
|
|||
<tr>
|
||||
<td><?php echo $account_name; ?></a></td>
|
||||
<?php
|
||||
$sql2 = mysqli_query($mysqli,"SELECT SUM(invoice_payment_amount) AS total_payments FROM invoice_payments WHERE account_id = $account_id");
|
||||
$sql2 = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id");
|
||||
$row2 = mysqli_fetch_array($sql2);
|
||||
|
||||
$sql3 = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id");
|
||||
|
|
@ -125,7 +127,7 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
|
|||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
Latest Incomes
|
||||
Latest Payments
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-borderless">
|
||||
|
|
@ -140,16 +142,16 @@ $sql_latest_expenses = mysqli_query($mysqli,"SELECT * FROM expenses, vendors, ca
|
|||
<tbody>
|
||||
<?php
|
||||
while($row = mysqli_fetch_array($sql_latest_income_payments)){
|
||||
$invoice_payment_date = $row['invoice_payment_date'];
|
||||
$invoice_payment_amount = $row['invoice_payment_amount'];
|
||||
$payment_date = $row['payment_date'];
|
||||
$payment_amount = $row['payment_amount'];
|
||||
$invoice_number = $row['invoice_number'];
|
||||
$client_name = $row['client_name'];
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $invoice_payment_date; ?></td>
|
||||
<td><?php echo $payment_date; ?></td>
|
||||
<td><?php echo $client_name; ?></td>
|
||||
<td><?php echo $invoice_number; ?></td>
|
||||
<td class="text-right text-monospace">$<?php echo number_format($invoice_payment_amount,2); ?></td>
|
||||
<td class="text-right text-monospace">$<?php echo number_format($payment_amount,2); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
|
|
|||
10
db.sql
10
db.sql
|
|
@ -258,7 +258,7 @@ CREATE TABLE `expenses` (
|
|||
`category_id` int(11) NOT NULL,
|
||||
`account_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`expense_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
|
|
@ -357,7 +357,7 @@ CREATE TABLE `payments` (
|
|||
`account_id` int(11) NOT NULL,
|
||||
`invoice_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`payment_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
|
|
@ -410,8 +410,10 @@ CREATE TABLE `transfers` (
|
|||
`transfer_date` date NOT NULL,
|
||||
`transfer_account_from` int(11) NOT NULL,
|
||||
`transfer_account_to` int(11) NOT NULL,
|
||||
`expense_id` int(11) NOT NULL,
|
||||
`payment_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`transfer_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
|
|
@ -458,4 +460,4 @@ CREATE TABLE `vendors` (
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-04-08 0:26:08
|
||||
-- Dump completed on 2019-04-08 1:16:28
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body">
|
||||
<input type="hidden" name="transfer_id" value="<?php echo $transfer_id; ?>">
|
||||
<input type="hidden" name="expense_id" value="<?php echo $expense_id; ?>">
|
||||
<input type="hidden" name="payment_id" value="<?php echo $payment_id; ?>">
|
||||
<div class="form-row">
|
||||
<div class="form-group col-sm">
|
||||
<label>Date</label>
|
||||
|
|
|
|||
29
post.php
29
post.php
|
|
@ -379,14 +379,13 @@ if(isset($_POST['add_transfer'])){
|
|||
$account_from = intval($_POST['account_from']);
|
||||
$account_to = intval($_POST['account_to']);
|
||||
|
||||
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = '$date', expense_amount = '$amount', vendor_id = 0, account_id = $account_from");
|
||||
$expense_id = mysqli_insert_id($mysqli);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO payments SET payment_date = '$date', payment_amount = '$amount', account_id = $account_to, invoice_id = 0");
|
||||
$payment_id = mysqli_insert_id($mysqli);
|
||||
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO invoice_payments SET invoice_payment_date = '$date', invoice_payment_amount = '$amount', account_id = $account_to, invoice_id = 0");
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO transfers SET transfer_date = '$date', transfer_amount = '$amount', transfer_account_from = $account_from, transfer_account_to = $account_to");
|
||||
mysqli_query($mysqli,"INSERT INTO transfers SET transfer_date = '$date', transfer_amount = '$amount', transfer_account_from = $account_from, transfer_account_to = $account_to, expense_id = $expense_id, payment_id = $payment_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Transfer added";
|
||||
|
||||
|
|
@ -397,14 +396,20 @@ if(isset($_POST['add_transfer'])){
|
|||
if(isset($_POST['edit_transfer'])){
|
||||
|
||||
$transfer_id = intval($_POST['transfer_id']);
|
||||
$expense_id = intval($_POST['expense_id']);
|
||||
$payment_id = intval($_POST['payment_id']);
|
||||
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
|
||||
$amount = $_POST['amount'];
|
||||
$account_from = intval($_POST['account_from']);
|
||||
$account_to = intval($_POST['account_to']);
|
||||
|
||||
mysqli_query($mysqli,"UPDATE expenses SET expense_date = '$date', expense_amount = '$amount', account_id = $account_from WHERE expense_id = $expense_id");
|
||||
|
||||
mysqli_query($mysqli,"UPDATE payments SET payment_date = '$date', payment_amount = '$amount', account_id = $account_to WHERE payment_id = $payment_id");
|
||||
|
||||
mysqli_query($mysqli,"UPDATE transfers SET transfer_date = '$date', transfer_amount = '$amount', transfer_account_from = $account_from, transfer_account_to = $account_to WHERE transfer_id = $transfer_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Transfer added";
|
||||
$_SESSION['alert_message'] = "Transfer modified";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
|
|
@ -413,6 +418,16 @@ if(isset($_POST['edit_transfer'])){
|
|||
if(isset($_GET['delete_transfer'])){
|
||||
$transfer_id = intval($_GET['delete_transfer']);
|
||||
|
||||
//Query the transfer ID to get the Pyament and Expense IDs so we can delete those as well
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM transfers WHERE transfer_id = $transfer_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$expense_id = $row['expense_id'];
|
||||
$payment_id = $row['payment_id'];
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM expenses WHERE expense_id = $expense_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM payments WHERE payment_id = $payment_id");
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM transfers WHERE transfer_id = $transfer_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Transfer deleted";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM transfers ORDER BY transfers.transfer_date DESC");
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM transfers ORDER BY transfer_date DESC");
|
||||
|
||||
?>
|
||||
|
||||
|
|
@ -33,7 +33,9 @@ $sql = mysqli_query($mysqli,"SELECT * FROM transfers ORDER BY transfers.transfer
|
|||
$transfer_account_from = $row['transfer_account_from'];
|
||||
$transfer_account_to = $row['transfer_account_to'];
|
||||
$transfer_amount = $row['transfer_amount'];
|
||||
|
||||
$expense_id = $row['expense_id'];
|
||||
$payment_id = $row['payment_id'];
|
||||
|
||||
$sql2 = mysqli_query($mysqli,"SELECT * FROM accounts WHERE account_id = $transfer_account_from");
|
||||
$row = mysqli_fetch_array($sql2);
|
||||
$account_name_from = $row['account_name'];
|
||||
|
|
|
|||
Loading…
Reference in New Issue