Web Systems Module 6.3 Updated
Web Systems Module 6.3 Updated
3 – TRANSACTION PROCESSING
Instructions:
1. SETUP CUSTOMER AND TRANSACTION TABLE
A. Add a tblcustomer and tbltransaction tables in api_db_initials database.
INSERT INTO
`tblcustomer`(`id`,`Customer_No`,`Last_Name`,`First_Name`,`Middle_Name`,`Gender`,`Mobile_No`,`
Home_Address`) values (1,'001','Dela Cruz','Juan','Dizon','Male','0917222344','Bacolor
Pampanga'),(2,'002','Di Magkamali','Perfecto','Mahusay','Male','0916111234','San Fernando
Pampanga');
<?php
class Customer{
// database connection and table name
private $conn;
// object properties
public $Customer_No;
public $Last_Name;
public $First_Name;
public $Middle_Name;
function readOne(){
// query to read single record
$query = "SELECT
*
FROM
tblcustomer
WHERE
Customer_No = ?";
// execute query
$stmt->execute();
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: GET");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');
if($customer->Customer_No!=null){
// create array
$customer_arr = array(
"Customer_No" => $customer->Customer_No,
"Last_Name" => $customer->Last_Name,
"First_Name" => $customer->First_Name,
"Middle_Name" => $customer->Middle_Name
);
else{
// set response code - 404 Not found
http_response_code(404);
<?php
class Transaction{
// database connection and table name
private $conn;
// object properties
public $Transaction_ID;
public $Transaction_No;
public $Customer_No;
public $Last_Name;
public $First_Name;
public $Middle_Name;
public $Product_ID;
public $Product_Name;
public $Product_Price;
public $Quantity;
public $Total_Amount;
// create product
function create(){
// query to insert record
$query = "INSERT INTO
tbltransaction
SET
Transaction_No=:transNo,
Customer_No=:custNo,
Product_ID=:prodID,
Quantity=:qty,
Total_Amount=:totAmount";
// prepare query
$stmt = $this->conn->prepare($query);
// sanitize
$this->Transaction_No=htmlspecialchars(strip_tags($this->Transaction_No));
$this->Customer_No=htmlspecialchars(strip_tags($this->Customer_No));
$this->Product_ID=htmlspecialchars(strip_tags($this->Product_ID));
$this->Quantity=htmlspecialchars(strip_tags($this->Quantity));
$this->Total_Amount=htmlspecialchars(strip_tags($this->Total_Amount));
// bind values
$stmt->bindParam(":transNo", $this->Transaction_No);
$stmt->bindParam(":custNo", $this->Customer_No);
$stmt->bindParam(":prodID", $this->Product_ID);
$stmt->bindParam(":qty", $this->Quantity);
$stmt->bindParam(":totAmount", $this->Total_Amount);
// execute query
if($stmt->execute()){
return true;
}
return false;
}
// execute query
$stmt->execute();
return $stmt;
}
// execute query
$stmt->execute();
return $row['total_rows'];
}
// search products
function search($keywords){
// select all query
$query = "SELECT
t.id as Transaction_ID, Transaction_No, c.Customer_No, Last_Name, First_Name,
Middle_Name,
p.name as Product_Name, p.price as Product_Price,Quantity,Total_Amount
FROM
tbltransaction t
LEFT JOIN
tblcustomer c
ON t.Customer_No = c.Customer_No
LEFT JOIN
products p
ON t.Product_ID = p.id
WHERE
Last_Name LIKE ? OR p.name LIKE ? OR Transaction_No LIKE ?
ORDER BY
t.id DESC";
// sanitize
$keywords=htmlspecialchars(strip_tags($keywords));
$keywords = "%{$keywords}%";
// bind
$stmt->bindParam(1, $keywords);
$stmt->bindParam(2, $keywords);
$stmt->bindParam(3, $keywords);
// execute query
$stmt->execute();
return $stmt;
}
}
?>
5. SETUP THE CREATE-REC-TRANS API
A. Go module5-files directory >> Right click api-initials folder and create a new folder
transactions
B. Right Click transactions folder in api-initials directory >> Add a new file create-rec-trans.php
and type following codes:
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers,
Authorization, X-Requested-With");
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
// initialize object
$transaction = new Transaction($db);
// query products
$stmt = $transaction->readall();
$num = $stmt->rowCount();
// products array
$transaction_arr=array();
$transaction_arr["records"]=array();
$transaction_item=array(
"Transaction_ID" => $Transaction_ID,
"Transaction_No" => $Transaction_No,
"Customer_No" => $Customer_No,
"Last_Name" => $Last_Name,
"First_Name" => $First_Name,
"Middle_Name" => $Middle_Name,
"Product_Name" => $Product_Name,
"Product_Price" => $Product_Price,
"Quantity" => $Quantity,
"Total_Amount" => $Total_Amount
);
array_push($transaction_arr["records"], $transaction_item);
}
else{
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
// utilities
$utilities = new Utilities();
// initialize object
$transaction = new Transaction($db);
// query transaction
$stmt = $transaction->readPaging($from_record_num, $records_per_page);
$num = $stmt->rowCount();
// transaction array
$transaction_arr=array();
$transaction_arr["records"]=array();
$transaction_arr["paging"]=array();
$transaction_item=array(
"Transaction_ID" => $Transaction_ID,
"Transaction_No" => $Transaction_No,
"Customer_No" => $Customer_No,
"Last_Name" => $Last_Name,
"First_Name" => $First_Name,
"Middle_Name" => $Middle_Name,
"Product_Name" => $Product_Name,
"Product_Price" => $Product_Price,
"Quantity" => $Quantity,
"Total_Amount" => $Total_Amount
);
array_push($transaction_arr["records"], $transaction_item);
}
// include paging
$total_rows=$transaction->count();
$page_url="{$home_url}transactions/read-paging-trans.php?";
$paging=$utilities->getPaging($page, $total_rows, $records_per_page, $page_url);
$transaction_arr["paging"]=$paging;
else{
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
// initialize object
$transaction = new Transaction($db);
// get keywords
$keywords=isset($_GET["s"]) ? $_GET["s"] : "";
// query products
$stmt = $transaction->search($keywords);
$num = $stmt->rowCount();
// transaction array
$transaction_arr=array();
$transaction_arr["records"]=array();
$transaction_item=array(
"Transaction_ID" => $Transaction_ID,
"Transaction_No" => $Transaction_No,
"Customer_No" => $Customer_No,
"Last_Name" => $Last_Name,
"First_Name" => $First_Name,
"Middle_Name" => $Middle_Name,
"Product_Name" => $Product_Name,
"Product_Price" => $Product_Price,
"Quantity" => $Quantity,
"Total_Amount" => $Total_Amount
);
array_push($transaction_arr["records"], $transaction_item);
}
else{
// set response code - 404 Not found
http_response_code(404);
9. ADDING THE DROP DOWN MENU AND TRANSACTIONS JAVASCRIPT FILES IN HOME.HTML
A. Extend api-initials working directory >> Double Click home.html and add the following codes
after the drop down codes for Categories:
<span class='input-group-btn'>
<button type='submit' class='btn btn-default' type='button'>
<span class='glyphicon glyphicon-search'></span>
</button>
</span>
</div>
</form>
<!-- when clicked, it will load the create transaction form -->
<div id='create-transaction' class='btn btn-primary pull-right m-b-15px create-transaction-
button'>
<span class='glyphicon glyphicon-plus'></span> Create Transaction
</div>
// end table
read_transaction_html+=`</table>`
// pagination
if(data.paging){
read_transaction_html+="<ul class='pagination pull-left margin-zero padding-bottom-
2em'>";
// first page
if(data.paging.first!=""){
read_transaction_html+="<li><a data-page-transaction='" + data.paging.first + "'>First
Page</a></li>";
}
// last page
if(data.paging.last!=""){
read_transaction_html+="<li><a data-page-transaction='" + data.paging.last + "'>Last
Page</a></li>";
}
read_transaction_html+="</ul>";
}
$(document).ready(function(){
function showTransactionFirstPage(){
var json_url= getUrl() + "transactions/read-paging-trans.php";
showTransaction(json_url);
}
$(document).ready(function(){
// template in transactions.js
readTransactionTemplate(data, keywords);
});
$(document).ready(function(){
// show html form when 'create product' button was clicked
$(document).on('click', '.create-transaction-button', function(){
// we have our html form here where transaction information will be entered
// we used the 'required' html5 property to prevent empty fields
var create_transaction_html=`
<!-- 'read transactions' button to show list of transactions -->
<div id='read-transactions' class='btn btn-primary pull-right m-b-15px read-transaction-
button'>
<span class='glyphicon glyphicon-list'></span> Read transactions
</div>
<!-- 'create transaction' html form -->
<form id='create-transaction-form' action='#' method='post' border='0'>
<table class='table table-hover table-responsive table-bordered'>
<tr>
<td>
</td>
<td>
<!-- button to compute -->
<div id='compute-transactions' class='btn btn-primary compute-transaction-
button'>
<span class='glyphicon glyphicon-list'></span> Compute Amount
</div>
</table>
</form>`;
// inject html to 'page-content' of our app
$("#page-content").html(create_transaction_html);
return false;
});
B. Extend transactions folder inside app directory of api-initials workspace >> Open create-
trans.js >> Provide the code after the closing </tr> tag of <!-- Transaction No field -->:
15. TEST THE WEB PAGE AND PROCESS FIVE (5) TRANSACTIONS
Notes:
Use the worksheet provided in assignment section of the course in the LMS and provide a
screenshot of the codes and output.
Using any screen recording software (Open Broadcaster Software, Bandicam or Filmora),
record the machine problem output demonstration.
Submit the activity in the assignment section of the course in the LMS:
o YouTube link or URL of the recorded output demonstration.
Five (5) points deductions will be given to each submission protocol violations:
o Not including initials in variable names, object names, class names, method
names and project names.
o Not using activity and machine problem worksheets.
o Incorrect Filename Format: ACTIVITY_TITLE_INITIALS.PDF
o Incomplete Source codes and output screenshots in PDF Format.
o Broken Links or no video demonstration outputs.
Any similarities on the source codes or any sign of “Copy and Paste” codes will be
marked as CHEATING and will be graded ZERO (0).