jun-branch #45
|
@ -111,7 +111,7 @@ if($_SESSION["user_type"]!="admin"){
|
|||
<a href="javascript:0"> <i class="mdi mdi-settings-outline"></i> Setting </a>
|
||||
</li>
|
||||
<li class="dropdown-footer">
|
||||
<a href="/logout.php"> <i class="mdi mdi-logout"></i> Log Out </a>
|
||||
<a href="../logout.php"> <i class="mdi mdi-logout"></i> Log Out </a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
|
@ -25,6 +25,28 @@ if($_SESSION["user_type"]!="admin"){
|
|||
}
|
||||
$vendor = getVendorbyId($_SESSION["vendorId"]);
|
||||
$array = json_decode($vendor,true);
|
||||
$selectedBankAccount = null;
|
||||
foreach ($array['bank_acount_details'] as $bankAccount) {
|
||||
if ($bankAccount['bank_payout']) {
|
||||
$selectedBankAccount = $bankAccount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($selectedBankAccount === null && !empty($array['bank_acount_details'])) {
|
||||
$selectedBankAccount = $array['bank_acount_details'][0];
|
||||
}
|
||||
$selectedBankAccountJSON = json_encode($selectedBankAccount);
|
||||
|
||||
$shopOrders = getOrderbyVendorId($_SESSION["vendorId"]);
|
||||
$vendorOrderss = json_decode($shopOrders);
|
||||
|
||||
if (is_array($vendorOrderss)) {
|
||||
$vendorOrders = json_decode($shopOrders);
|
||||
} elseif (is_object($vendorOrderss) && property_exists($vendorOrderss, 'message')) {
|
||||
$vendorOrders = [];
|
||||
} else {
|
||||
echo "Unknown type or no 'message' property found.";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
|
@ -843,176 +865,124 @@ $array = json_decode($vendor,true);
|
|||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><input type="checkbox"></td>
|
||||
<td>ObananaPay</td>
|
||||
<td>₱230</td>
|
||||
<td>
|
||||
<span class="badge badge-success">Paid</span>
|
||||
</td>
|
||||
<td><span class="badge badge-warning">No</span></td>
|
||||
<td>
|
||||
<a class="text-dark" href=""> Coach Swagger</a>
|
||||
</td>
|
||||
<td>Oct 20, 2018</td>
|
||||
<td class="text-right">
|
||||
<div
|
||||
class="dropdown show d-inline-block widget-dropdown">
|
||||
<a class="dropdown-toggle icon-burger-mini"
|
||||
href="" role="button"
|
||||
id="dropdown-recent-order1"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
data-display="static"></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdown-recent-order1">
|
||||
<li class="dropdown-item">
|
||||
<a href="#">Details</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$totalOrders = count($vendorOrders);
|
||||
for ($i = 0; $i < $totalOrders; $i++) {
|
||||
$order = $vendorOrders[$i];
|
||||
$orderArray = json_encode($order, true);
|
||||
$orderItems = json_decode($orderArray, true);
|
||||
|
||||
<tr>
|
||||
<td><input type="checkbox"></td>
|
||||
<td>ObananaPay</td>
|
||||
<td>₱550</td>
|
||||
<td>
|
||||
<span class="badge badge-success">Paid</span>
|
||||
</td>
|
||||
<td><span class="badge badge-warning">No</span></td>
|
||||
<td>
|
||||
<a class="text-dark" href=""> Toddler Shoes, Gucci Watch</a>
|
||||
</td>
|
||||
<td>Nov 15, 2018</td>
|
||||
<td class="text-right">
|
||||
<div
|
||||
class="dropdown show d-inline-block widget-dropdown">
|
||||
<a class="dropdown-toggle icon-burger-mini"
|
||||
href="" role="button"
|
||||
id="dropdown-recent-order1"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
data-display="static"></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdown-recent-order1">
|
||||
<li class="dropdown-item">
|
||||
<a href="#">Details</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><input type="checkbox"></td>
|
||||
<td>ObananaPay</td>
|
||||
<td>₱325</td>
|
||||
<td>
|
||||
<span class="badge badge-success">Paid</span>
|
||||
</td>
|
||||
<td><span class="badge badge-warning">No</span></td>
|
||||
<td>
|
||||
<a class="text-dark" href=""> Hat Black Suits</a>
|
||||
</td>
|
||||
<td>Nov 18, 2018</td>
|
||||
<td class="text-right">
|
||||
<div
|
||||
class="dropdown show d-inline-block widget-dropdown">
|
||||
<a class="dropdown-toggle icon-burger-mini"
|
||||
href="" role="button"
|
||||
id="dropdown-recent-order1"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
data-display="static"></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdown-recent-order1">
|
||||
<li class="dropdown-item">
|
||||
<a href="#">Details</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><input type="checkbox"></td>
|
||||
<td>PayMongo</td>
|
||||
<td>₱200</td>
|
||||
<td>
|
||||
<span class="badge badge-success">Paid</span>
|
||||
</td>
|
||||
<td><span class="badge badge-warning">No</span></td>
|
||||
<td>
|
||||
<a class="text-dark" href=""> T100 Power Bank</a>
|
||||
</td>
|
||||
<td>Nov 20, 2018</td>
|
||||
<td class="text-right">
|
||||
<div
|
||||
class="dropdown show d-inline-block widget-dropdown">
|
||||
<a class="dropdown-toggle icon-burger-mini"
|
||||
href="" role="button"
|
||||
id="dropdown-recent-order1"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
data-display="static"></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdown-recent-order1">
|
||||
<li class="dropdown-item">
|
||||
<a href="#">Details</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><input type="checkbox" disabled></td>
|
||||
<td>ObananaPay</td>
|
||||
<td>₱150</td>
|
||||
<td>
|
||||
<span class="badge badge-success">Paid</span>
|
||||
</td>
|
||||
<td><span class="badge badge-success">Yes</span></td>
|
||||
<td>
|
||||
<a class="text-dark" href=""> Vodka Milk Tea</a>
|
||||
</td>
|
||||
<td>Dec 11, 2018</td>
|
||||
<td class="text-right">
|
||||
<div
|
||||
class="dropdown show d-inline-block widget-dropdown">
|
||||
<a class="dropdown-toggle icon-burger-mini"
|
||||
href="" role="button"
|
||||
id="dropdown-recent-order1"
|
||||
data-bs-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false"
|
||||
data-display="static"></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right"
|
||||
aria-labelledby="dropdown-recent-order1">
|
||||
<li class="dropdown-item">
|
||||
<a href="#">Details</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
if ($orderItems['payment']['status'] === 'PAID') {
|
||||
foreach ($orderItems['items'] as $item) {
|
||||
?>
|
||||
<tr>
|
||||
<td><input type="checkbox"></td>
|
||||
<td><?php echo $orderItems['payment_method']; ?></td>
|
||||
<td><?php echo $item['price']; ?></td>
|
||||
<td>
|
||||
<span class="badge badge-success"><?php echo $orderItems['payment']['status']; ?></span>
|
||||
</td>
|
||||
<td><span class="badge badge-warning"> <?php echo empty($orderItems['payout_status']) ? 'No' : 'Yes'; ?></span></td>
|
||||
<td>
|
||||
<a class="text-dark" href=""><?php echo $item['product']['name']; ?></a>
|
||||
</td>
|
||||
<td><?php echo $orderItems['updatedAt']; ?></td>
|
||||
<td class="text-right">
|
||||
<div class="dropdown show d-inline-block widget-dropdown">
|
||||
<a class="dropdown-toggle icon-burger-mini" href="" role="button" id="dropdown-recent-order1" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-display="static"></a>
|
||||
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdown-recent-order1">
|
||||
<li class="dropdown-item">
|
||||
<a href="#">Details</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end mt-5">
|
||||
<button type="submit" class="btn btn-primary mb-2 btn-pill">Create Payout from Selected</button>
|
||||
</div>
|
||||
<div class="d-flex justify-content-end mt-5">
|
||||
<button type="button" class="btn btn-primary mb-2 btn-pill" onclick="createPayout()">Create Payout from Selected</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function createPayout() {
|
||||
var rows = document.querySelectorAll("#recent-orders tbody tr");
|
||||
var selectedBank = JSON.parse('<?php echo $selectedBankAccountJSON; ?>');
|
||||
var selectedOrders = [];
|
||||
var grossAmount = 0;
|
||||
var feesDeductionAdjustment = 0;
|
||||
const token = '<?php echo $_SESSION["token"] ?>';
|
||||
rows.forEach(function(row) {
|
||||
var checkbox = row.querySelector("input[type=checkbox]");
|
||||
if (checkbox && checkbox.checked) {
|
||||
var amount = parseFloat(row.cells[2].innerText);
|
||||
grossAmount += amount;
|
||||
var individualFee = 50;
|
||||
feesDeductionAdjustment += individualFee;
|
||||
var breakdownItem = {
|
||||
Type: "Payment",
|
||||
"Transaction date": row.cells[6].innerText,
|
||||
"Gross Amount": amount,
|
||||
Fee: individualFee,
|
||||
"Net Amount": amount - individualFee,
|
||||
Description: row.cells[5].querySelector("a").innerText
|
||||
};
|
||||
|
||||
selectedOrders.push(breakdownItem);
|
||||
}
|
||||
});
|
||||
|
||||
var netAmount = grossAmount - feesDeductionAdjustment;
|
||||
|
||||
var postData = {
|
||||
gross_amount: grossAmount.toFixed(2),
|
||||
fees_deduction_adjustment: feesDeductionAdjustment.toFixed(2), // Total of individual fees
|
||||
net_amount: netAmount.toFixed(2),
|
||||
breakdown: selectedOrders,
|
||||
bank_information: [
|
||||
selectedBank
|
||||
],
|
||||
transaction_logs: selectedOrders, // Assuming transaction logs structure similar to breakdown
|
||||
vendor_details: [
|
||||
{ vendor_id: "123", vendor_name: "Sample Vendor" }
|
||||
],
|
||||
status: "PENDING",
|
||||
created_by: "Sample User"
|
||||
};
|
||||
|
||||
// POST request to the endpoint
|
||||
fetch('https://api.obanana.shop/api/v1/payouts/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
"Authorization": "Bearer " + token,
|
||||
},
|
||||
body: JSON.stringify(postData)
|
||||
})
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Payout created successfully');
|
||||
} else {
|
||||
console.error('Failed to create payout');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue