first commit
This commit is contained in:
42
backend/ride/payment/add.php
Normal file
42
backend/ride/payment/add.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$amount = filterRequest("amount");
|
||||
$payment_method = filterRequest("payment_method");
|
||||
$passengerID = filterRequest("passengerID");
|
||||
$rideId = filterRequest("rideId");
|
||||
$driverID = filterRequest("driverID");
|
||||
$token = filterRequest("token");
|
||||
|
||||
|
||||
// Retrieve token details from the database
|
||||
$stmt = $con->prepare("SELECT * FROM payment_tokens WHERE token = :token AND isUsed = FALSE");
|
||||
$stmt->execute(array(
|
||||
':token' => $token
|
||||
));
|
||||
|
||||
$tokenData = $stmt->fetch();
|
||||
|
||||
if ($tokenData) {
|
||||
|
||||
$sql = "INSERT INTO `payments` (`id`,`amount`, `payment_method`, `passengerID`, `rideId`, `driverID`)
|
||||
VALUES ( SHA2(UUID(), 256),'$amount', '$payment_method', '$passengerID', '$rideId', '$driverID')";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Print a success message
|
||||
jsonSuccess(null, "Payment record created successfully");
|
||||
// Mark the token as used in the database
|
||||
$stmt = $con->prepare("UPDATE payment_tokens SET isUsed = TRUE WHERE id = :tokenID");
|
||||
$stmt->execute(array(
|
||||
':tokenID' => $tokenData['id']
|
||||
));
|
||||
} else {
|
||||
// Print a failure message
|
||||
jsonError("Failed to save record");
|
||||
}
|
||||
} else {
|
||||
jsonError("Invalid or already used token");
|
||||
}
|
||||
0
backend/ride/payment/delete.php
Normal file
0
backend/ride/payment/delete.php
Normal file
0
backend/ride/payment/error_log
Normal file
0
backend/ride/payment/error_log
Normal file
61
backend/ride/payment/get.php
Normal file
61
backend/ride/payment/get.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
$sql = "SELECT
|
||||
p1.id,
|
||||
p1.amount,
|
||||
p2.total_amount,
|
||||
p1.payment_method,
|
||||
p1.isGiven,
|
||||
p1.passengerID,
|
||||
p1.rideId,
|
||||
p1.driverID,
|
||||
(
|
||||
SELECT SUM(amount)
|
||||
FROM payments
|
||||
WHERE driverID = '$driverID'
|
||||
AND DATE(created_at) = CURDATE()
|
||||
) AS todayAmount,
|
||||
p1.created_at,
|
||||
p1.updated_at,
|
||||
(
|
||||
SELECT ROUND(AVG(CAST(rating AS DECIMAL(4,2))), 2)
|
||||
FROM ratingDriver
|
||||
WHERE driver_id = '$driverID'
|
||||
) AS rating
|
||||
FROM payments p1
|
||||
JOIN (
|
||||
SELECT driverID, SUM(amount) AS total_amount
|
||||
FROM payments
|
||||
WHERE isGiven = 'waiting'
|
||||
GROUP BY driverID
|
||||
) p2 ON p1.driverID = p2.driverID
|
||||
WHERE p1.isGiven = 'waiting'
|
||||
AND p1.driverID = '$driverID'
|
||||
AND DATE(p1.created_at) = CURDATE(); ";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Fetch the record
|
||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$count = $stmt->rowCount();
|
||||
|
||||
// $response = array(
|
||||
|
||||
// "message" => "Payment data saved successfully",
|
||||
// "id" => "0",
|
||||
// "count" => $count,
|
||||
// "data" => $rows
|
||||
// );
|
||||
|
||||
// echo json_encode($response);
|
||||
jsonSuccess($row);
|
||||
|
||||
}
|
||||
else{
|
||||
// Print a failure message
|
||||
jsonError($message = "No wallet record found");
|
||||
}
|
||||
?>
|
||||
64
backend/ride/payment/getAllPayment.php
Normal file
64
backend/ride/payment/getAllPayment.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
$sql = "SELECT
|
||||
(
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`ride`
|
||||
WHERE
|
||||
`ride`.`status` = 'Finished'
|
||||
AND `ride`.`created_at` BETWEEN CURRENT_DATE() + INTERVAL 7 HOUR AND CURRENT_DATE() + INTERVAL 10 HOUR
|
||||
AND `ride`.`driver_id` = '$driverID'
|
||||
) AS morning_count,
|
||||
(
|
||||
SELECT
|
||||
COUNT(*)
|
||||
FROM
|
||||
`ride`
|
||||
WHERE
|
||||
`ride`.`status` = 'Finished'
|
||||
AND `ride`.`created_at` BETWEEN CURRENT_DATE() + INTERVAL 15 HOUR AND CURRENT_DATE() + INTERVAL 18 HOUR
|
||||
AND `ride`.`driver_id` = '$driverID'
|
||||
) AS afternoon_count,
|
||||
(
|
||||
SELECT
|
||||
COALESCE(SUM(amount), 0) AS total_amount
|
||||
FROM
|
||||
payments
|
||||
WHERE
|
||||
isGiven = 'waiting' AND `driverID` = '$driverID'
|
||||
) AS driver_total,
|
||||
(
|
||||
SELECT
|
||||
COALESCE(SUM(price), 0) AS total_amount
|
||||
FROM
|
||||
ride
|
||||
WHERE
|
||||
`driver_id` = '$driverID'
|
||||
AND `ride`.`status` = 'Finished'
|
||||
AND `ride`.`created_at` > CURRENT_DATE() - INTERVAL 1 WEEK
|
||||
) AS total_amount_last_week
|
||||
FROM
|
||||
dual
|
||||
LIMIT 1;
|
||||
|
||||
|
||||
";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Fetch the record
|
||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
jsonSuccess($row);
|
||||
|
||||
}
|
||||
else{
|
||||
// Print a failure message
|
||||
jsonError($message = "No wallet record found");
|
||||
}
|
||||
?>
|
||||
39
backend/ride/payment/getAllPaymentVisa.php
Normal file
39
backend/ride/payment/getAllPaymentVisa.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
$sql = "SELECT
|
||||
driverID,
|
||||
COALESCE(SUM(amount), 0) AS total_amount,
|
||||
COALESCE(SUM(amount), 0) + COALESCE(
|
||||
(
|
||||
SELECT
|
||||
SUM(`amount`)
|
||||
FROM
|
||||
`paymentsDriverPoints`
|
||||
WHERE
|
||||
`payment_method` = 'fromBudgetToPoints' AND `driverID` = '$driverID'
|
||||
),
|
||||
0
|
||||
) AS diff
|
||||
FROM
|
||||
payments
|
||||
WHERE
|
||||
isGiven = 'waiting'
|
||||
AND `payment_method` IN ('visa-in', 'visa', 'visaRide', 'TransferFrom', 'payout', 'TransferTo')
|
||||
AND `driverID` = '$driverID'";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Fetch the record
|
||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
jsonSuccess($row);
|
||||
|
||||
}
|
||||
else{
|
||||
// Print a failure message
|
||||
jsonError($message = "No wallet record found");
|
||||
}
|
||||
?>
|
||||
29
backend/ride/payment/getCountRide.php
Normal file
29
backend/ride/payment/getCountRide.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
$driver_id = filterRequest("driver_id");
|
||||
|
||||
$sql = "SELECT
|
||||
COUNT(id) AS count
|
||||
FROM
|
||||
`ride`
|
||||
WHERE
|
||||
`ride`.`status` = 'Finished'
|
||||
AND driver_id = '$driver_id'
|
||||
AND created_at >= CURDATE();
|
||||
";
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Fetch the record
|
||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
jsonSuccess($row);
|
||||
|
||||
}
|
||||
else{
|
||||
// Print a failure message
|
||||
jsonError($message = "No wallet record found");
|
||||
}
|
||||
?>
|
||||
72
backend/ride/payment/update.php
Normal file
72
backend/ride/payment/update.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$id = filterRequest("id");
|
||||
|
||||
// Create an empty array to store the column-value pairs
|
||||
$columnValues = array();
|
||||
$params = [':id' => $id];
|
||||
|
||||
// Check if each column is set in the request and add it to the array
|
||||
if (isset($_POST["amount"])) {
|
||||
$amount = filterRequest("amount");
|
||||
$columnValues[] = "`amount` = :amount";
|
||||
$params[':amount'] = $amount;
|
||||
}
|
||||
|
||||
if (isset($_POST["payment_method"])) {
|
||||
$payment_method = filterRequest("payment_method");
|
||||
$columnValues[] = "`payment_method` = :payment_method";
|
||||
$params[':payment_method'] = $payment_method;
|
||||
}
|
||||
|
||||
if (isset($_POST["passengerID"])) {
|
||||
$passengerID = filterRequest("passengerID");
|
||||
$columnValues[] = "`passengerID` = :passengerID";
|
||||
$params[':passengerID'] = $passengerID;
|
||||
}
|
||||
|
||||
if (isset($_POST["rideId"])) {
|
||||
$rideId = filterRequest("rideId");
|
||||
$columnValues[] = "`rideId` = :rideId";
|
||||
$params[':rideId'] = $rideId;
|
||||
}
|
||||
|
||||
if (isset($_POST["driverID"])) {
|
||||
$driverID = filterRequest("driverID");
|
||||
$columnValues[] = "`driverID` = :driverID";
|
||||
$params[':driverID'] = $driverID;
|
||||
}
|
||||
|
||||
if (isset($_POST["created_at"])) {
|
||||
$created_at = filterRequest("created_at");
|
||||
$columnValues[] = "`created_at` = :created_at";
|
||||
$params[':created_at'] = $created_at;
|
||||
}
|
||||
|
||||
if (isset($_POST["updated_at"])) {
|
||||
$updated_at = filterRequest("updated_at");
|
||||
$columnValues[] = "`updated_at` = :updated_at";
|
||||
$params[':updated_at'] = $updated_at;
|
||||
}
|
||||
|
||||
if (isset($_POST["isGiven"])) {
|
||||
$isGiven = filterRequest("isGiven");
|
||||
$columnValues[] = "`isGiven` = :isGiven";
|
||||
$params[':isGiven'] = $isGiven;
|
||||
}
|
||||
|
||||
// Construct the SET clause of the update query using the column-value pairs
|
||||
$sql = "UPDATE `payments` SET $setClause WHERE `id` = :id";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Print a success message
|
||||
jsonSuccess($message = "Payment data updated successfully");
|
||||
} else {
|
||||
// Print a failure message
|
||||
jsonError($message = "Failed to update payment data");
|
||||
}
|
||||
?>
|
||||
19
backend/ride/payment/updatePaymetToPaid.php
Normal file
19
backend/ride/payment/updatePaymetToPaid.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../connect.php';
|
||||
|
||||
$driverID = filterRequest("driverID");
|
||||
|
||||
|
||||
$sql = "UPDATE `payments` SET `isGiven`='Paid' WHERE driverID='$driverID'";
|
||||
|
||||
$stmt = $con->prepare($sql);
|
||||
$stmt->execute();
|
||||
|
||||
if ($stmt->rowCount() > 0) {
|
||||
// Print a success message
|
||||
jsonSuccess($message = "Payment data updated successfully");
|
||||
} else {
|
||||
// Print a failure message
|
||||
jsonError($message = "Failed to update payment data");
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user