Skip to content

Commit

Permalink
add new function delete meralco
Browse files Browse the repository at this point in the history
  • Loading branch information
Norseolee committed Dec 22, 2023
1 parent 6edc653 commit dade2bb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 247 deletions.
50 changes: 38 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

// mySQL;
// const pool = mysql.createPool({
// host: "localhost",
// user: "root",
// password: "",
// database: "Am9Commercial",
// connectionLimit: 20,
// });
const pool = mysql.createPool({
host: "b18rvltkeprxyrwdxj35-mysql.services.clever-cloud.com",
user: "u1llarmjzoo3t683",
password: "HKDuDLkfJO1cZQJX58M7",
database: "b18rvltkeprxyrwdxj35",
host: "localhost",
user: "root",
password: "",
database: "Am9Commercial",
connectionLimit: 20,
});
// const pool = mysql.createPool({
// host: "b18rvltkeprxyrwdxj35-mysql.services.clever-cloud.com",
// user: "u1llarmjzoo3t683",
// password: "HKDuDLkfJO1cZQJX58M7",
// database: "b18rvltkeprxyrwdxj35",
// connectionLimit: 20,
// });

// get all the tenant_data
app.get("/tenant", (req, res) => {
Expand Down Expand Up @@ -83,7 +83,7 @@ app.get("/tenant/:tenant_id", (req, res) => {
});
});

// delete a record
// delete tenant record
app.delete("/tenant/delete/:tenant_id", (req, res) => {
pool.getConnection((err, connection) => {
if (err) throw err;
Expand Down Expand Up @@ -122,6 +122,32 @@ app.delete("/tenant/delete/:tenant_id", (req, res) => {
});
});

// delete meralco record
app.delete("/meralco/delete/:meralco_id", (req, res) => {
pool.getConnection((err, connection) => {
if (err) throw err;
console.log(`connected as id ${connection.threadId}`);

const meralcoId = req.params.meralco_id;

connection.query(
"DELETE FROM Meralco WHERE meralco_id = ?",
[meralcoId],
(meralcoErr) => {
if (meralcoErr) {
return connection.rollback(() => {
connection.release();
throw meralcoErr;
});
}

connection.release();
res.send(`Tenant with the meralco ID ${meralcoId} has been removed`);
}
);
});
});

//create a record tenant
app.post("/tenant/add-tenant", (req, res) => {
pool.getConnection((err, connection) => {
Expand Down
26 changes: 16 additions & 10 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ <h1>Am9 Electricity Billing</h1>
History
</button>

<button class="button red" onclick="deleteTenant();">
Delete Tenant
<button class="button red" onclick="deleteMeralco()">
Delete Meralco
</button>
</div>

Expand All @@ -81,6 +81,9 @@ <h1>Am9 Electricity Billing</h1>
<button class="button" onclick="toggleSection('update-section')">
Update Tenant
</button>
<button class="button red" onclick="deleteTenant();">
Delete Tenant
</button>
</div>

<div class="add-section">
Expand All @@ -90,25 +93,24 @@ <h1 style="text-align: center">ADD NEW TENANT</h1>
<div class="add-Information">
<label for="add-Name">Name: </label>
<input type="text" name="name" id="add-Name" />

<label for="add-Building">Building and Stall: </label>
<input type="text" name="building" id="add-Building" />
</div>
<div class="add-Billing">
<label for="add-DateOfReading">Date of Reading: </label>
<input type="text" name="date_of_reading" id="add-DateOfReading" />

<label for="add-CurrentReading">Current Reading: </label>
<input type="text" name="current_reading" id="add-CurrentReading" />
</div>

<button type="submit" id="post" class="button green">
Add New Tenant
</button>
</form>
</div>
</div>


<div class="update-section-tenant">
<div class="update-content-tenant">
Expand Down Expand Up @@ -169,16 +171,20 @@ <h1 style="text-align: center">UPDATE READING</h1>

<div class="update-Totalamount">
<label for="updateConsume">Consumption: </label>
<input type="number" name="updateConsume" class="updateConsume" readonly />
<input
type="number"
name="updateConsume"
class="updateConsume"
readonly />
<label for="TotalAmount"
>Total Amount: <span class="updateTotal"></span
></label>
</div>
<button type="submit" id="updateBtn" class="button">
<button type="submit" id="AddMeralco" class="button">
Add Meralco
</button>
</div>
</form>
</form>
</div>
<script>
function amountCalculation() {
let preReading =
Expand Down
Loading

0 comments on commit dade2bb

Please sign in to comment.