283 lines
10 KiB
PHP
283 lines
10 KiB
PHP
<?php
|
|
session_start();
|
|
require '../config.php';
|
|
require '../include_header.php';
|
|
?>
|
|
|
|
<body>
|
|
<?php require '../include_topbar.php'; ?>
|
|
<?php require '../include_sidebar.php'; ?>
|
|
|
|
<main id="content" class="content py-15">
|
|
<div class="container-fluid">
|
|
|
|
<div class="row mb-6">
|
|
<div class="col-12">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<h1 class="fs-3 mb-1">Supplier Returns</h1>
|
|
<p class="mb-0 text-muted">Goods returned to suppliers</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-5 mb-5">
|
|
<div class="col-lg-3 col-sm-6 col-12">
|
|
<div class="card p-4">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<div class="icon-shape icon-md bg-primary bg-opacity-10 text-primary rounded-2">
|
|
<i class="ti ti-arrow-back-up fs-4"></i>
|
|
</div>
|
|
<div>
|
|
<p class="mb-0 text-muted small">Total</p>
|
|
<h3 class="fw-bold mb-0" id="stat_total">—</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-sm-6 col-12">
|
|
<div class="card p-4">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<div class="icon-shape icon-md bg-warning bg-opacity-10 text-warning rounded-2">
|
|
<i class="ti ti-pencil fs-4"></i>
|
|
</div>
|
|
<div>
|
|
<p class="mb-0 text-muted small">Draft</p>
|
|
<h3 class="fw-bold mb-0" id="stat_draft">—</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-sm-6 col-12">
|
|
<div class="card p-4">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<div class="icon-shape icon-md bg-success bg-opacity-10 text-success rounded-2">
|
|
<i class="ti ti-circle-check fs-4"></i>
|
|
</div>
|
|
<div>
|
|
<p class="mb-0 text-muted small">Confirmed</p>
|
|
<h3 class="fw-bold mb-0" id="stat_confirmed">—</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3 col-sm-6 col-12">
|
|
<div class="card p-4">
|
|
<div class="d-flex align-items-center gap-3">
|
|
<div class="icon-shape icon-md bg-secondary bg-opacity-10 text-secondary rounded-2">
|
|
<i class="ti ti-x fs-4"></i>
|
|
</div>
|
|
<div>
|
|
<p class="mb-0 text-muted small">Cancelled</p>
|
|
<h3 class="fw-bold mb-0" id="stat_cancelled">—</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row g-5">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body p-4">
|
|
<div class="row g-3 align-items-end">
|
|
<div class="col-lg-4">
|
|
<div class="position-relative">
|
|
<input type="text" id="search_input" class="form-control ps-9"
|
|
placeholder="Search return number, PO, or supplier...">
|
|
<span class="position-absolute top-25 ms-4">
|
|
<i class="ti ti-search text-muted"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-2">
|
|
<select id="filter_status" class="form-select">
|
|
<option value="">All Status</option>
|
|
<option value="-1">Cancelled</option>
|
|
<option value="0">Draft</option>
|
|
<option value="1">Confirmed</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-lg-2">
|
|
<select id="filter_dept" class="form-select">
|
|
<option value="">All Departments</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-lg-2">
|
|
<button class="btn btn-secondary w-100" onclick="retrieve_returns()">
|
|
<i class="ti ti-search me-1"></i>Search
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-body p-5">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover mb-0 table-centered" id="return_list">
|
|
<thead class="table-primary border-light">
|
|
<tr>
|
|
<th>Return #</th>
|
|
<th>PO #</th>
|
|
<th>Date</th>
|
|
<th>Supplier</th>
|
|
<th>Department</th>
|
|
<th>Items</th>
|
|
<th>Refund Amount</th>
|
|
<th>Status</th>
|
|
<th>Fulfillment</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody></tbody>
|
|
<tfoot></tfoot>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</main>
|
|
|
|
<?php require '../include_ending.php'; ?>
|
|
|
|
<script>
|
|
|
|
const can_delete = ['admin', 'owner'].includes(user_role);
|
|
|
|
function return_status_badge(status) {
|
|
const map = {
|
|
'-1': '<span class="badge bg-secondary">Cancelled</span>',
|
|
'0': '<span class="badge bg-warning text-dark">Draft</span>',
|
|
'1': '<span class="badge bg-success">Confirmed</span>',
|
|
};
|
|
return map[String(status)] ?? '—';
|
|
}
|
|
|
|
function fulfillment_status_badge(status) {
|
|
const map = {
|
|
'1': '<span class="badge bg-warning text-dark"><i class="ti ti-list-check me-1"></i>Picking</span>',
|
|
'2': '<span class="badge bg-info text-white"><i class="ti ti-package me-1"></i>Packed</span>',
|
|
'3': '<span class="badge bg-success"><i class="ti ti-truck me-1"></i>Shipped</span>',
|
|
};
|
|
return map[String(status)] ?? '<span class="text-muted">—</span>';
|
|
}
|
|
|
|
function retrieve_returns() {
|
|
return ajax_request({
|
|
url: '<?php echo $server_url?>po/api/engine/retrieve_supplier_return.php',
|
|
autoPrepare: true,
|
|
checkRequired: 0,
|
|
action: 'read',
|
|
onSuccess: function(res) {
|
|
var all = res.output || [];
|
|
|
|
var keyword = $('#search_input').val().toLowerCase();
|
|
var fil_status = $('#filter_status').val();
|
|
var fil_dept = $('#filter_dept').val();
|
|
|
|
var data = all.filter(function(r) {
|
|
var match_kw = !keyword ||
|
|
(r.return_number || '').toLowerCase().includes(keyword) ||
|
|
(r.po_number || '').toLowerCase().includes(keyword) ||
|
|
(r.contact_name || '').toLowerCase().includes(keyword);
|
|
var match_st = fil_status === '' || String(r.status) === fil_status;
|
|
var match_dept = !fil_dept || String(r.department_id) === fil_dept;
|
|
return match_kw && match_st && match_dept;
|
|
});
|
|
|
|
$('#stat_total').text(format_number(all.length));
|
|
$('#stat_draft').text(format_number(all.filter(r => String(r.status) === '0').length));
|
|
$('#stat_confirmed').text(format_number(all.filter(r => String(r.status) === '1').length));
|
|
$('#stat_cancelled').text(format_number(all.filter(r => String(r.status) === '-1').length));
|
|
|
|
alasql('CREATE TABLE IF NOT EXISTS return_list');
|
|
alasql.tables.return_list.data = data;
|
|
$('table#return_list tfoot').html(generate_pagination('return_list', data.length));
|
|
change_page_return_list(1);
|
|
}
|
|
});
|
|
}
|
|
|
|
function change_page_return_list(page_num) {
|
|
var offset = (page_num - 1) * prop_limit;
|
|
var rows = alasql(`SELECT * FROM return_list LIMIT ${prop_limit} OFFSET ${offset}`);
|
|
var body = '';
|
|
|
|
if (!rows.length) {
|
|
$('table#return_list tbody').html(
|
|
'<tr><td colspan="9" class="text-center py-5 text-muted">No supplier returns found.</td></tr>'
|
|
);
|
|
return;
|
|
}
|
|
|
|
$.each(rows, function(i, r) {
|
|
var items = [];
|
|
try { items = JSON.parse(r.items || '[]'); } catch(e) {}
|
|
var item_count = items.length;
|
|
body += `<tr>
|
|
<td class="py-3 fw-semibold">${escape_html(r.return_number || '')}</td>
|
|
<td class="py-3">
|
|
${r.po_id ? `<a href="<?php echo $server_url?>po/manage_po.php?id=${r.po_id}">${escape_html(r.po_number || 'PO #' + r.po_id)}</a>` : '<span class="text-muted">—</span>'}
|
|
</td>
|
|
<td class="py-3">${format_date(r.return_date)}</td>
|
|
<td class="py-3">${escape_html(r.contact_name || '—')}</td>
|
|
<td class="py-3">${get_dept_label(r.department_id)}</td>
|
|
<td class="py-3">${item_count} item${item_count !== 1 ? 's' : ''}</td>
|
|
<td class="py-3 fw-semibold">${format_number(r.refund_amount, 2)}</td>
|
|
<td class="py-3">${return_status_badge(r.status)}</td>
|
|
<td class="py-3">${fulfillment_status_badge(r.fulfillment_status)}</td>
|
|
<td class="py-3">
|
|
<a href="<?php echo $server_url?>po/manage_supplier_return.php?id=${r.id}" title="View">
|
|
<i class="ti ti-eye fs-5"></i>
|
|
</a>
|
|
<a href="javascript:void(0);" class="ms-2 text-secondary" title="Stock"
|
|
onclick="show_stock_rows('supplier_return', ${r.id}, '${escape_html(r.return_number || '')}')">
|
|
<i class="ti ti-packages fs-5"></i>
|
|
</a>
|
|
${can_delete ? `<a href="javascript:void(0);" class="link-danger ms-2" title="Delete" onclick="delete_supplier_return(${r.id})"><i class="ti ti-trash fs-5"></i></a>` : ''}
|
|
</td>
|
|
</tr>`;
|
|
});
|
|
|
|
$('table#return_list tbody').html(body);
|
|
}
|
|
|
|
function delete_supplier_return(id) {
|
|
bootbox.confirm({
|
|
message: 'Delete this return? Unconfirmed stock rows will be removed.',
|
|
buttons: { confirm: { label: 'Delete', className: 'btn-danger' }, cancel: { label: 'Back', className: 'btn-secondary' } },
|
|
callback: function(result) {
|
|
if (!result) return;
|
|
ajax_request({
|
|
url: '<?php echo $server_url?>po/api/engine/delete_supplier_return.php',
|
|
autoPrepare: false,
|
|
checkRequired: 0,
|
|
action: 'delete',
|
|
data: { id: id },
|
|
onSuccess: function() { retrieve_returns(); }
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
$(async function() {
|
|
await load_dept_cache();
|
|
populate_dept_filter('filter_dept');
|
|
retrieve_returns();
|
|
$('#search_input').on('keyup', function(e) {
|
|
if (e.key === 'Enter') retrieve_returns();
|
|
});
|
|
$('#filter_status, #filter_dept').on('change', retrieve_returns);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|