more updates

This commit is contained in:
Flatlogic Bot 2026-04-23 04:19:35 +00:00
parent ac740c5a25
commit 0590b5d747
3 changed files with 118 additions and 65 deletions

View File

@ -3,6 +3,38 @@ require_once __DIR__ . '/includes/app.php';
$user = require_permission('sales', 'show');
ensure_sales_table();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'mark_as_paid') {
$id = (int)$_POST['id'];
try {
$sale = fetch_sale($id);
if ($sale && $sale['order_type'] === 'eid') {
$summary = sale_payment_summary($sale);
if ($summary['due_amount'] > 0.0005) {
apply_sale_payment($id, $summary['due_amount'], false);
set_flash('success', tr('تم تحويل حالة الدفع إلى مدفوع بنجاح.', 'Payment status updated to paid successfully.'));
} else {
set_flash('info', tr('الفاتورة مدفوعة مسبقاً.', 'Invoice is already paid.'));
}
}
} catch (Exception $e) {
set_flash('danger', tr('تعذر تحديث حالة الدفع.', 'Failed to update payment status.'));
}
redirect_to('eid_orders.php', $_GET);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_delivery_status') {
$id = (int)$_POST['id'];
$newStatus = trim((string)($_POST['status'] ?? 'pending'));
$allowedStatuses = array_keys(eid_delivery_status_options());
if (in_array($newStatus, $allowedStatuses, true)) {
$stmt = db()->prepare("UPDATE sales_orders SET delivery_status = :status WHERE id = :id AND order_type = 'eid'");
$stmt->execute([':status' => $newStatus, ':id' => $id]);
set_flash('success', tr('تم تحديث حالة التجهيز بنجاح.', 'Prep status updated successfully.'));
}
redirect_to('eid_orders.php', $_GET);
}
$activeNav = 'eid_orders';
$pageTitle = tr('طلبات العيد', 'Eid Orders');
$metaDescription = tr('متابعة طلبات العيد مع الفلاتر والمدى الزمني.', 'Track Eid orders with filters and date range.');
@ -250,7 +282,7 @@ require __DIR__ . '/includes/header.php';
<option value=""><?= h(tr('كل الفروع', 'All branches')) ?></option>
<?php foreach (branches() as $branchCode => $branchLabel): ?>
<?php if ($user['role'] !== 'owner' && !in_array($branchCode, $allowedBranches, true)) { continue; } ?>
<option value="<?= h($branchCode) ?>" <?= $branch === $branchCode ? 'selected' : '' ?>><?= h($branchLabel) ?></option>
<option value="<?= h($branchCode) ?>" <?= $branch === $branchCode ? 'selected' : '' ?>><?= h(branch_label($branchCode)) ?></option>
<?php endforeach; ?>
</select>
</div>
@ -280,25 +312,25 @@ require __DIR__ . '/includes/header.php';
<div class="row g-2 mb-3">
<div class="col-6 col-md-3">
<div class="card border-0 p-2">
<div class="card border-0 p-3 bg-primary-subtle">
<div class="small text-muted mb-1"><?= h(tr('إجمالي الطلبات', 'Total orders')) ?></div>
<div class="fs-5 fw-bold"><?= (int) ($summary['total_orders'] ?? 0) ?></div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="card border-0 p-2">
<div class="card border-0 p-3 bg-info-subtle">
<div class="small text-muted mb-1"><?= h(tr('عدد القطع', 'Total items')) ?></div>
<div class="fs-5 fw-bold"><?= (int) ($summary['total_items'] ?? 0) ?></div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="card border-0 p-2">
<div class="card border-0 p-3 bg-warning-subtle">
<div class="small text-muted mb-1"><?= h(tr('قيد التجهيز', 'Pending prep')) ?></div>
<div class="fs-5 fw-bold"><?= (int) ($summary['prep_orders'] ?? 0) ?></div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="card border-0 p-2">
<div class="card border-0 p-3 bg-success-subtle">
<div class="small text-muted mb-1"><?= h(tr('إجمالي القيمة', 'Total value')) ?></div>
<div class="fs-5 fw-bold"><?= h(number_format((float) ($summary['total_amount'] ?? 0), 3)) ?></div>
</div>
@ -320,7 +352,7 @@ require __DIR__ . '/includes/header.php';
<?= h((int) ($summary['total_orders'] ?? 0)) ?> <?= h(tr('طلب', 'orders')) ?>
</span>
</div>
<div class="table-responsive">
<div class="table-responsive" style="min-height: 400px; padding-bottom: 180px;">
<table class="table table-sm table-hover align-middle mb-0">
<thead class="table-light">
<tr>
@ -336,6 +368,7 @@ require __DIR__ . '/includes/header.php';
<i class="bi <?= h($sortIcon('customer')) ?>"></i>
</a>
</th>
<th><?= h(tr('الهاتف', 'Phone')) ?></th>
<th>
<a class="text-decoration-none text-dark fw-semibold d-inline-flex align-items-center gap-1" href="<?= h($sortUrl('delivery_date')) ?>">
<?= h(tr('تسليم', 'Delivery')) ?>
@ -377,8 +410,34 @@ require __DIR__ . '/includes/header.php';
<td>
<div class="fw-semibold"><?= h($order['receipt_no']) ?></div>
</td>
<?php
$rawCustomerName = (string) ($order['customer_name'] ?: tr('عميل نقدي', 'Walk-in customer'));
$displayPhone = '';
if (str_contains($rawCustomerName, ' - ')) {
$parts = explode(' - ', $rawCustomerName);
$lastPart = trim(end($parts));
if (preg_match('/^[0-9+\s]+$/', $lastPart)) {
$displayPhone = $lastPart;
array_pop($parts);
$rawCustomerName = trim(implode(' - ', $parts));
}
}
?>
<td>
<div class="fw-semibold"><?= h((string) ($order['customer_name'] ?: tr('عميل نقدي', 'Walk-in customer'))) ?></div>
<div class="fw-semibold"><?= h($rawCustomerName) ?></div>
</td>
<td dir="ltr" class="text-start">
<?php
$phone = ltrim(preg_replace('/[^0-9]/', '', $displayPhone), '0');
if ($phone !== '') {
if (!str_starts_with($phone, '968')) {
$phone = '968' . $phone;
}
echo h($phone);
} else {
echo '-';
}
?>
</td>
<td>
<div class="fw-semibold"><?= h(date('Y-m-d', strtotime((string) $effectiveDelivery))) ?></div>
@ -396,7 +455,40 @@ require __DIR__ . '/includes/header.php';
</td>
<td class="text-end fw-semibold"><?= h(number_format((float) ($order['total_amount'] ?? 0), 3)) ?></td>
<td>
<div class="d-flex justify-content-end gap-2">
<span class="badge <?= h(payment_status_badge_class((string) ($order['payment_status'] ?? 'paid'))) ?> px-2 py-1">
<?= h(payment_status_label((string) ($order['payment_status'] ?? 'paid'))) ?>
</span>
</td>
<td>
<div class="d-flex justify-content-end gap-2">
<?php if (($order['payment_status'] ?? 'unpaid') !== 'paid'): ?>
<form method="post" action="" class="d-inline" onsubmit="return confirm('<?= h(tr('هل أنت متأكد من تغيير حالة الدفع إلى مدفوع؟', 'Are you sure you want to mark as paid?')) ?>');">
<input type="hidden" name="action" value="mark_as_paid">
<input type="hidden" name="id" value="<?= h($order['id']) ?>">
<button type="submit" class="btn btn-sm btn-outline-success" title="<?= h(tr('تحويل لمدفوع', 'Mark as Paid')) ?>">
<i class="bi bi-cash"></i>
</button>
</form>
<?php endif; ?>
<div class="dropdown">
<button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" data-bs-boundary="window" aria-expanded="false" title="<?= h(tr('تغيير الحالة', 'Change status')) ?>">
<i class="bi bi-arrow-repeat"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end shadow-sm">
<?php foreach (eid_delivery_status_options() as $val => $lbl): ?>
<?php if ($val === ($order['delivery_status'] ?? 'pending')) continue; ?>
<li>
<form method="post" action="">
<input type="hidden" name="action" value="update_delivery_status">
<input type="hidden" name="id" value="<?= h($order['id']) ?>">
<input type="hidden" name="status" value="<?= h($val) ?>">
<button class="dropdown-item" type="submit"><?= h($lbl) ?></button>
</form>
</li>
<?php endforeach; ?>
</ul>
</div>
<a class="btn btn-sm btn-light border text-primary" href="<?= h(url_for('sale.php', ['id' => $order['id']])) ?>" title="<?= h(tr('تفاصيل', 'Detail')) ?>"><i class="bi bi-eye"></i></a>
<a class="btn btn-sm btn-outline-secondary" href="<?= h(url_for('edit_sale.php', ['id' => $order['id']])) ?>" title="<?= h(tr('تعديل', 'Edit')) ?>"><i class="bi bi-pencil"></i></a>
</div>

View File

@ -1,57 +0,0 @@
import sys
with open()eid_orders.php', 'r') as f:
content = f.read()
search1 = """ <tr>
<td>
<div class="fw-semibold"><?= h($order['receipt_no']) ?></div>
</td>
<td>
<div class="fw-semibold"><?= h((string) ($order['customer_name'] ?: tr('عميل نقدن', 'Walk-in customer'))) ?></div>
</td>"""
replace1 = """ <?php
$cNameRaw = (string) ($order['customer_name'] ?: tr('عميل نہدق', 'Walk-in customer'));
$cName = $cNameRaw;
$cPhone = '';
if (strpos($cNameRaw, ' - ') !== false) {
$parts = explode(' - ', $cNameRaw, 2);
$cName = trim($parts[0]);
$rawPhone = trim($parts[1]);
if (preg_match('/^968\s*/', $rawPhone)) {
$cPhone = preg_replace('/^968\s*/', '968 ', $rawPhone);
} elseif (is_numeric(str_replace(' ', '', $rawPhone))) {
$cPhone = '968 ' . $rawPhone;
} else {
$cName = $cNameRaw;
}
}
?>
<tr>
<td>
<div class="fw-semibold"><?= h($order['receipt_no']) ?></div>
</td>
<td>
<div class="fw-semibold"><?= h(${cName}) ?></div>
<?php if ($cPhone !== ''): ?>
<div class="small text-muted" dir="ltr"><?= h($cPhone) ?></div>
<?php endif; ?>
</td>"""
search2 = """ <td class="text-end fw-semibold"><?= h(number_format((float) ($order['total_amount'] ?? 0), 3)) ?></td>
<td>
<div class="d-flex justify-content-end gap-2">"""
replace2 = """ <td class="text-end fw-semibold"><?= h(number_format((float) ($order['total_amount'] ?? 0), 3)) ?></td>
<td>
<span class="badge <?= h(payment_status_badge_class((string) ($order['payment_status'] ?? 'paid'))) ?> px-2 py-1"><?= h(payment_status_label((string) ($order['payment_status'] ?? 'paid'))) ?></span>
</td>
<td>
<div class="d-flex justify-content-end gap-2">"""
content = content.replace(search1, replace1)
content = content.replace(search2, replace2)
with open()eid_orders.php', 'w') as f:
f.write(content)

18
patch_boxes.py Normal file
View File

@ -0,0 +1,18 @@
import re
with open('eid_orders.php', 'r') as f:
content = f.read()
colors = ['bg-primary-subtle', 'bg-info-subtle', 'bg-warning-subtle', 'bg-success-subtle']
parts = content.split('<div class="card border-0 p-2 bg-primary-subtle">')
if len(parts) == 5:
new_content = parts[0]
for i in range(4):
new_content += f'<div class="card border-0 p-3 {colors[i]}">' + parts[i+1]
with open('eid_orders.php', 'w') as f:
f.write(new_content)
print("Patched successfully")
else:
print(f"Found {len(parts)} parts, expected 5.")