浏览代码

add vendor ability to undo

Bernn 1 周之前
父节点
当前提交
afd762fff3
共有 3 个文件被更改,包括 26 次插入0 次删除
  1. 1 0
      assets/app.css
  2. 22 0
      bin/jobs_update.php
  3. 3 0
      lib/render.php

+ 1 - 0
assets/app.css

@@ -122,6 +122,7 @@ input.inline-edit {
 .btn-finish { background: var(--c-ok); }
 .btn-finish { background: var(--c-ok); }
 .btn-ship   { background: var(--c-info); }
 .btn-ship   { background: var(--c-info); }
 .btn-partial{ background: #ff9800; }
 .btn-partial{ background: #ff9800; }
+.btn-undo   { background: #757575; padding: 0.25rem 0.55rem; font-size: 0.8rem; }
 .btn-receive{ background: var(--c-accent-strong); }
 .btn-receive{ background: var(--c-accent-strong); }
 .btn-add    { background: var(--c-accent-strong); padding: 0.5rem 1.25rem; font-size: 1rem; }
 .btn-add    { background: var(--c-accent-strong); padding: 0.5rem 1.25rem; font-size: 1rem; }
 .btn-post   { background: var(--c-accent-strong); padding: 0.5rem 1rem; font-size: 1rem; }
 .btn-post   { background: var(--c-accent-strong); padding: 0.5rem 1rem; font-size: 1rem; }

+ 22 - 0
bin/jobs_update.php

@@ -33,6 +33,28 @@ if ($actor !== 'ICG' && (int) $job['vendor_id'] !== $vendor_id) {
 }
 }
 
 
 // --- Button-driven state transitions ---
 // --- Button-driven state transitions ---
+// Undo is dynamic: it reverses one step based on current status. Vendors only.
+// Once ICG marks Received, undo is no longer available (vendor would need to
+// message ICG to get them to back it out).
+if ($action === 'undo') {
+    if ($actor === 'ICG') {
+        http_response_code(403);
+        echo 'Undo is a vendor action';
+        return;
+    }
+    if ($job['status'] === 'Finished') {
+        apply_job_change($job, 'status', '', $actor);
+    } elseif ($job['status'] === 'Shipped') {
+        apply_job_change($job, 'status', 'Finished', $actor);
+    } else {
+        http_response_code(400);
+        echo 'Nothing to undo from current status';
+        return;
+    }
+    echo 'Success';
+    return;
+}
+
 if ($action !== '') {
 if ($action !== '') {
     $allowed = [
     $allowed = [
         'acknowledge'    => ['ack',    '',          ['vendor']],
         'acknowledge'    => ['ack',    '',          ['vendor']],

+ 3 - 0
lib/render.php

@@ -152,6 +152,9 @@ function render_actions(array $r, string $audience): string {
         if (in_array($r['status'], ['', 'Finished'], true) && (int) $r['qty'] > 1) {
         if (in_array($r['status'], ['', 'Finished'], true) && (int) $r['qty'] > 1) {
             $btns[] = '<button class="btn btn-partial" data-action="partial_ship" data-qty="' . (int) $r['qty'] . '">Partial Ship</button>';
             $btns[] = '<button class="btn btn-partial" data-action="partial_ship" data-qty="' . (int) $r['qty'] . '">Partial Ship</button>';
         }
         }
+        if (in_array($r['status'], ['Finished', 'Shipped'], true)) {
+            $btns[] = '<button class="btn btn-undo" data-action="undo">Undo</button>';
+        }
     } else { // ICG
     } else { // ICG
         if ($r['status'] === 'Shipped') {
         if ($r['status'] === 'Shipped') {
             $btns[] = '<button class="btn btn-receive" data-action="mark_received">Mark Received</button>';
             $btns[] = '<button class="btn btn-receive" data-action="mark_received">Mark Received</button>';