mirror of https://github.com/itflow-org/itflow
Added Products CRUD and new DB dump to include products
This commit is contained in:
parent
2b7bdee81e
commit
40c08a1635
|
|
@ -30,7 +30,7 @@
|
|||
<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");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<div class="modal" id="addProductModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-box"></i> New Product</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name" required autofocus="autofocus">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<input type="text" class="form-control" name="description">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Cost</label>
|
||||
<input type="text" class="form-control" name="cost" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="add_product" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
<div class="modal fade" id="addRecurringInvoiceModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-copy"></i> New Recurring Invoice</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</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-row">
|
||||
<div class="form-group col">
|
||||
<label>Start 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 class="form-group col">
|
||||
<label>Frequency</label>
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa fa-clock"></i></span>
|
||||
</div>
|
||||
<select class="form-control" name="category" required>
|
||||
<option value="">- frequency -</option>
|
||||
<option value="">Daily</option>
|
||||
<option value="">Weekly</option>
|
||||
<option value="">Monthly</option>
|
||||
<option value="">Yearly</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Income Category</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="category" required>
|
||||
<option value="">- Category -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT * FROM categories WHERE category_type = 'Income'");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$category_id = $row['category_id'];
|
||||
$category_name = $row['category_name'];
|
||||
?>
|
||||
<option value="<?php echo $category_id; ?>"><?php echo $category_name; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</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>
|
||||
18
db.sql
18
db.sql
|
|
@ -360,6 +360,22 @@ CREATE TABLE `payments` (
|
|||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `products`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `products`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `products` (
|
||||
`product_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`product_name` varchar(200) NOT NULL,
|
||||
`product_description` text NOT NULL,
|
||||
`product_cost` decimal(15,2) NOT NULL,
|
||||
PRIMARY KEY (`product_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `recurring_invoices`
|
||||
--
|
||||
|
|
@ -442,4 +458,4 @@ CREATE TABLE `vendors` (
|
|||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2019-04-07 23:34:02
|
||||
-- Dump completed on 2019-04-08 0:26:08
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
<div class="modal" id="editProductModal<?php echo $product_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="fa fa-box"></i> Edit Product</h5>
|
||||
<button type="button" class="close" data-dismiss="modal">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>">
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" name="name" value="<?php echo $product_name; ?>" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Description</label>
|
||||
<input type="text" class="form-control" name="description" value="<?php echo $product_description; ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Cost</label>
|
||||
<input type="text" class="form-control" name="cost" value="<?php echo $product_cost; ?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" name="edit_product" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<div class="modal fade" id="editVendorModal<?php echo $vendor_id; ?>" tabindex="-1">
|
||||
<div class="modal" id="editVendorModal<?php echo $vendor_id; ?>" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
|
|
|
|||
40
post.php
40
post.php
|
|
@ -167,6 +167,46 @@ if(isset($_GET['delete_vendor'])){
|
|||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_product'])){
|
||||
|
||||
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||
$cost = strip_tags(mysqli_real_escape_string($mysqli,$_POST['cost']));
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO products SET product_name = '$name', product_description = '$description', product_cost = '$cost'");
|
||||
|
||||
$_SESSION['alert_message'] = "Product added";
|
||||
|
||||
header("Location: products.php");
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['edit_product'])){
|
||||
|
||||
$product_id = intval($_POST['product_id']);
|
||||
$name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name']));
|
||||
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
|
||||
$cost = strip_tags(mysqli_real_escape_string($mysqli,$_POST['cost']));
|
||||
|
||||
mysqli_query($mysqli,"UPDATE products SET product_name = '$name', product_description = '$description', product_cost = '$cost' WHERE product_id = $product_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Product modified";
|
||||
|
||||
header("Location: products.php");
|
||||
|
||||
}
|
||||
|
||||
if(isset($_GET['delete_product'])){
|
||||
$product_id = intval($_GET['delete_product']);
|
||||
|
||||
mysqli_query($mysqli,"DELETE FROM products WHERE product_id = $product_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Product deleted";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
|
||||
}
|
||||
|
||||
if(isset($_POST['add_mileage'])){
|
||||
|
||||
$date = strip_tags(mysqli_real_escape_string($mysqli,$_POST['date']));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
<?php include("header.php"); ?>
|
||||
|
||||
<?php $sql = mysqli_query($mysqli,"SELECT * FROM products ORDER BY product_name ASC"); ?>
|
||||
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<h6 class="float-left mt-1"><i class="fa fa-box"></i> Products</h6>
|
||||
<button type="button" class="btn btn-primary btn-sm mr-auto float-right" data-toggle="modal" data-target="#addProductModal"><i class="fas fa-plus"></i> New</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-borderless table-hover" id="dataTable" width="100%" cellspacing="0">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th class="text-right">Cost</th>
|
||||
<th class="text-center">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$product_id = $row['product_id'];
|
||||
$product_name = $row['product_name'];
|
||||
$product_description = $row['product_description'];
|
||||
$product_cost = $row['product_cost'];
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td><?php echo $product_name; ?></td>
|
||||
<td><?php echo $product_description; ?></td>
|
||||
<td class="text-right text-monospace">$<?php echo number_format($product_cost,2); ?></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="#editProductModal<?php echo $product_id; ?>">Edit</a>
|
||||
<a class="dropdown-item" href="post.php?delete_product=<?php echo $product_id; ?>">Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
include("edit_product_modal.php");
|
||||
}
|
||||
?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("add_product_modal.php"); ?>
|
||||
|
||||
<?php include("footer.php");
|
||||
|
|
@ -82,6 +82,6 @@
|
|||
<div class="card-footer small text-muted">Updated yesterday at 11:59 PM</div>
|
||||
</div>
|
||||
|
||||
<?php include("add_invoice_modal.php"); ?>
|
||||
<?php include("add_recurring_invoice_modal.php"); ?>
|
||||
|
||||
<?php include("footer.php");
|
||||
|
|
@ -11,6 +11,11 @@
|
|||
<i class="fas fa-fw fa-users mx-2"></i>
|
||||
<span>Clients</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="products.php">
|
||||
<i class="fas fa-fw fa-box mx-2"></i>
|
||||
<span>Products</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="vendors.php">
|
||||
<i class="fas fa-fw fa-building mx-2"></i>
|
||||
|
|
|
|||
Loading…
Reference in New Issue