Beginning stages of invoices

This commit is contained in:
root 2019-03-16 21:39:32 -04:00
parent e7109be170
commit f4519ca704
3 changed files with 148 additions and 0 deletions

52
add_invoice_modal.php Normal file
View File

@ -0,0 +1,52 @@
<div class="modal fade" id="addInvoiceModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-file"></i> New Invoice</h5>
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<div class="modal-body">
<div class="form-group">
<label>Client</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-user"></i></span>
</div>
<select class="form-control" name="client" required>
<option value="">- Customer -</option>
<?php
$sql = mysqli_query($mysqli,"SELECT * FROM clients");
while($row = mysqli_fetch_array($sql)){
$client_id = $row['client_id'];
$client_name = $row['client_name'];
?>
<option value="<?php echo "$client_id"; ?>"><?php echo "$client_name"; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label>Date</label>
<div class="input-group">
<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" value="<?php echo date("Y-m-d"); ?>" required>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="add_invoice" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>

83
invoices.php Normal file
View File

@ -0,0 +1,83 @@
<?php include("header.php"); ?>
<?php
$sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
WHERE invoices.client_id = clients.client_id
ORDER BY invoices.invoice_date DESC");
?>
<div class="card mb-3">
<div class="card-header">
<h6 class="float-left mt-1"><i class="fa fa-file"></i> Invoices</h6>
<button type="button" class="btn btn-primary btn-sm float-right" data-toggle="modal" data-target="#addInvoiceModal"><i class="fas fa-plus"></i> Add New</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover" id="dT" width="100%" cellspacing="0">
<thead>
<tr>
<th>Number</th>
<th>Client</th>
<th class="text-right">Amount</th>
<th>Date</th>
<th>Due</th>
<th>Status</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($sql)){
$invoice_id = $row['invoice_id'];
$invoice_number = $row['invoice_number'];
$invoice_status = $row['invoice_status'];
$invoice_date = $row['invoice_date'];
$invoice_due = $row['invoice_due'];
$invoice_amount = $row['invoice_amount'];
$client_id = $row['client_id'];
$client_name = $row['client_name'];
?>
<tr>
<td><a href="invoice.php?invoice_id=<?php echo $invoice_id; ?>">INV-<?php echo "$invoice_number"; ?></a></td>
<td><a href="client.php?client_id=<?php echo $client_id; ?>"><?php echo "$client_name"; ?></a></td>
<td class="text-right text-monospace">$<?php echo "$invoice_amount"; ?></td>
<td><?php echo "$invoice_date"; ?></td>
<td><?php echo "$invoice_due"; ?></td>
<td><?php echo "$invoice_status"; ?></td>
<td>
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editinvoiceModal<?php echo $invoice_id; ?>">Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addinvoiceCopyModal<?php echo $invoice_id; ?>">Copy</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#addinvoiceCopyModal<?php echo $invoice_id; ?>">PDF</a>
<a class="dropdown-item" href="#">Delete</a>
</div>
</div>
</td>
</tr>
<?php
include("edit_invoice_modal.php");
include("add_invoice_copy_modal.php");
}
?>
</tbody>
</table>
</div>
</div>
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
</div>
<?php include("add_invoice_modal.php"); ?>
<?php include("footer.php");

View File

@ -228,6 +228,19 @@ if(isset($_POST['edit_transfer'])){
}
if(isset($_POST['add_invoice'])){
$client = intval($_POST['client']);
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
mysqli_query($mysqli,"INSERT INTO invoices SET invoice_date = '$date', client_id = $client, invoice_status = 'Draft'");
$_SESSION['alert_message'] = "Invoice added";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if(isset($_POST['add_user'])){
$email = strip_tags(mysqli_real_escape_string($mysqli,$_POST['email']));
$password = mysqli_real_escape_string($mysqli,$_POST['password']);