diff --git a/public_html/lib/mapper/erpDailyOrderMapper.php b/public_html/lib/mapper/erpDailyOrderMapper.php index bd1d88a..36066b4 100644 --- a/public_html/lib/mapper/erpDailyOrderMapper.php +++ b/public_html/lib/mapper/erpDailyOrderMapper.php @@ -3,7 +3,8 @@ class erpDailyOrderMapper { public static function map($payload) { - $after = $payload['after']; + $data = $payload['after'] ?? $payload['before'] ?? []; + $isDelete = strtoupper($payload['action'] ?? '') === 'DELETED'; return [ @@ -18,7 +19,7 @@ class erpDailyOrderMapper "cdoPaymentType" => $after['d_paymenttype'] ?? null, "cdoCycle" => $after['d_cycle'] ?? null, "cdoRate" => isset($after['d_rate']) ? (float)$after['d_rate'] : null, - "cdoStatus" => $after['d_status'] ?? 'A', + "cdoStatus" => $isDelete ? 'D' : ($data['d_status'] ?? 'A'), "cdoVisitFlag" => $after['d_visit'] ?? 'N', "cdoEstimatedQty" => isset($after['d_estquantity']) ? (float)$after['d_estquantity'] : null, "cdoPickupAt" => ($after['d_status'] ?? '') === 'F' ? self::datetime($after['d_modifydate'] ?? null) : null, diff --git a/public_html/lib/runErpOutbox.php b/public_html/lib/runErpOutbox.php index 02f2370..499716e 100644 --- a/public_html/lib/runErpOutbox.php +++ b/public_html/lib/runErpOutbox.php @@ -107,9 +107,25 @@ while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { switch ($entity) { // DAILY case 'DAILY': - $body = erpDailyOrderMapper::map($payload); - $method = 'POST'; - $url = $serverUrl . "/crm-rest-api/customer-daily-order"; + $action = strtoupper(trim($payload['action'] ?? '')); + + if ($action === 'DELETED') { + $key = $payload['key']; + $od = preg_replace('/[^0-9]/', '', $key['d_orderdate']); + $orderDateIso = substr($od,0,4)."-".substr($od,4,2)."-".substr($od,6,2); + + $method = 'DELETE'; + $url = $serverUrl + . "/crm-rest-api/customer-daily-order" + . "/customer/" . urlencode($key['d_accountno']) + . "/date/" . urlencode($orderDateIso) + . "/jobtype/" . urlencode($key['d_jobtype']); + $body = null; // DELETE 는 바디 불필요 + } else { + $body = erpDailyOrderMapper::map($payload); + $method = 'POST'; + $url = $serverUrl . "/crm-rest-api/customer-daily-order"; + } break; // CUSTOMER