Added Expense Reciept upload functionality new db dump as well

This commit is contained in:
root 2019-04-09 16:18:03 -04:00
parent 333e885a39
commit cb2eefe8d4
4 changed files with 33 additions and 11 deletions

View File

@ -7,7 +7,7 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<form action="post.php" method="post" autocomplete="off"> <form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
<div class="modal-body"> <div class="modal-body">
<div class="form-row"> <div class="form-row">
<div class="form-group col-md"> <div class="form-group col-md">
@ -119,7 +119,7 @@
<textarea class="form-control" rows="4" name="description" required></textarea> <textarea class="form-control" rows="4" name="description" required></textarea>
</div> </div>
<div class="custom-file"> <div class="custom-file">
<input type="file" class="custom-file-input" name="attachment"> <input type="file" class="custom-file-input" name="file">
<label class="custom-file-label">Attach Reciept...</label> <label class="custom-file-label">Attach Reciept...</label>
</div> </div>
</div> </div>

17
db.sql
View File

@ -99,7 +99,7 @@ CREATE TABLE `client_assets` (
`client_contact_id` int(11) NOT NULL, `client_contact_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL, `client_id` int(11) NOT NULL,
PRIMARY KEY (`client_asset_id`) PRIMARY KEY (`client_asset_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -179,7 +179,7 @@ CREATE TABLE `client_logins` (
`client_application_id` int(11) NOT NULL, `client_application_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL, `client_id` int(11) NOT NULL,
PRIMARY KEY (`client_login_id`) PRIMARY KEY (`client_login_id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -271,11 +271,12 @@ CREATE TABLE `expenses` (
`expense_description` text NOT NULL, `expense_description` text NOT NULL,
`expense_amount` decimal(15,2) NOT NULL, `expense_amount` decimal(15,2) NOT NULL,
`expense_date` date NOT NULL, `expense_date` date NOT NULL,
`expense_receipt` varchar(200) NOT NULL,
`vendor_id` int(11) NOT NULL, `vendor_id` int(11) NOT NULL,
`category_id` int(11) NOT NULL, `category_id` int(11) NOT NULL,
`account_id` int(11) NOT NULL, `account_id` int(11) NOT NULL,
PRIMARY KEY (`expense_id`) PRIMARY KEY (`expense_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -292,7 +293,7 @@ CREATE TABLE `invoice_history` (
`invoice_history_description` varchar(200) NOT NULL, `invoice_history_description` varchar(200) NOT NULL,
`invoice_id` int(11) NOT NULL, `invoice_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_history_id`) PRIMARY KEY (`invoice_history_id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -313,7 +314,7 @@ CREATE TABLE `invoice_items` (
`invoice_item_total` decimal(15,2) NOT NULL, `invoice_item_total` decimal(15,2) NOT NULL,
`invoice_id` int(11) NOT NULL, `invoice_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_item_id`) PRIMARY KEY (`invoice_item_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -334,7 +335,7 @@ CREATE TABLE `invoices` (
`category_id` int(11) NOT NULL, `category_id` int(11) NOT NULL,
`client_id` int(11) NOT NULL, `client_id` int(11) NOT NULL,
PRIMARY KEY (`invoice_id`) PRIMARY KEY (`invoice_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -465,7 +466,7 @@ CREATE TABLE `vendors` (
`vendor_created_at` int(11) NOT NULL, `vendor_created_at` int(11) NOT NULL,
`vendor_updated_at` int(11) NOT NULL, `vendor_updated_at` int(11) NOT NULL,
PRIMARY KEY (`vendor_id`) PRIMARY KEY (`vendor_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
@ -477,4 +478,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-04-08 15:29:51 -- Dump completed on 2019-04-09 16:16:46

View File

@ -24,6 +24,7 @@
<th>Vendor</th> <th>Vendor</th>
<th>Category</th> <th>Category</th>
<th>Account</th> <th>Account</th>
<th></th>
<th class="text-center">Actions</th> <th class="text-center">Actions</th>
</tr> </tr>
</thead> </thead>
@ -35,6 +36,7 @@
$expense_date = $row['expense_date']; $expense_date = $row['expense_date'];
$expense_amount = $row['expense_amount']; $expense_amount = $row['expense_amount'];
$expense_description = $row['expense_description']; $expense_description = $row['expense_description'];
$expense_receipt = $row['expense_receipt'];
$vendor_id = $row['vendor_id']; $vendor_id = $row['vendor_id'];
$vendor_name = $row['vendor_name']; $vendor_name = $row['vendor_name'];
$category_id = $row['category_id']; $category_id = $row['category_id'];
@ -42,6 +44,12 @@
$account_name = $row['account_name']; $account_name = $row['account_name'];
$account_id = $row['account_id']; $account_id = $row['account_id'];
if(empty($expense_receipt)){
$receipt_attached = "";
}else{
$receipt_attached = "<a class='btn btn-dark btn-sm' target='_blank' href='$expense_receipt'><i class='fa fa-file-pdf'></i></a>";
}
?> ?>
<tr> <tr>
@ -50,6 +58,7 @@
<td><?php echo $vendor_name; ?></td> <td><?php echo $vendor_name; ?></td>
<td><?php echo $category_name; ?></td> <td><?php echo $category_name; ?></td>
<td><?php echo $account_name; ?></td> <td><?php echo $account_name; ?></td>
<td><?php echo $receipt_attached; ?></td>
<td> <td>
<div class="dropdown dropleft text-center"> <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"> <button class="btn btn-secondary btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

View File

@ -135,6 +135,11 @@ if(isset($_POST['add_vendor'])){
mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_account_number = '$account_number', vendor_created_at = UNIX_TIMESTAMP()"); mysqli_query($mysqli,"INSERT INTO vendors SET vendor_name = '$name', vendor_description = '$description', vendor_account_number = '$account_number', vendor_created_at = UNIX_TIMESTAMP()");
$vendor_id = mysqli_insert_id($mysqli);
//Create Directory to store expense reciepts for that vendor
mkdir("uploads/expenses/$vendor_id");
$_SESSION['alert_message'] = "Vendor added"; $_SESSION['alert_message'] = "Vendor added";
header("Location: vendors.php"); header("Location: vendors.php");
@ -335,7 +340,14 @@ if(isset($_POST['add_expense'])){
$category = intval($_POST['category']); $category = intval($_POST['category']);
$description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description']));
mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = '$date', expense_amount = '$amount', account_id = $account, vendor_id = $vendor, category_id = $category, expense_description = '$description'"); if(!empty($_FILES['file'])){
$path = "uploads/expenses/$vendor/";
$path = $path . basename( $_FILES['file']['name']);
$file_name = basename($path);
move_uploaded_file($_FILES['file']['tmp_name'], $path);
}
mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = '$date', expense_amount = '$amount', account_id = $account, vendor_id = $vendor, category_id = $category, expense_description = '$description', expense_receipt = '$path'");
$_SESSION['alert_message'] = "Expense added"; $_SESSION['alert_message'] = "Expense added";