'" . date('Y-m-d') . "'"; $result = $conn->query($sqlstr); $row = $result->fetch_assoc(); $reachedLimit = ($row['claimcount'] > 10); // Get employee code $result = $conn->query("SELECT em_code FROM employee WHERE id = " . $_SESSION['employee_id']); $row = $result->fetch_assoc(); $em_code = $row['em_code']; if ($reachedLimit) { echo "-1"; } else { // Get customer info and update $sql = "SELECT employee.id as originalId, cs_code, em_user, cs_belong, cs_updatetime, cs_claimdate, cs_claimFrom, cs_chain, is_silent FROM customer LEFT JOIN employee ON customer.cs_belong = employee.id WHERE customer.id = " . $conn->real_escape_string($cid); $result = $conn->query($sql); if ($row = $result->fetch_assoc()) { $oldCode = $row['cs_code']; $originalEmp = $row['em_user']; $newCode = str_replace("-", "/0" . substr($em_code, 1) . "-", $oldCode); // Update chain and check circulation $newChain = $row['cs_chain'] . "," . $_SESSION['employee_id']; $circulation = substr_count($newChain, ','); $is_silent = ($circulation > 3) ? 1 : 0; // Update customer $updateSql = "UPDATE customer SET cs_belong = " . $_SESSION['employee_id'] . ", cs_claimdate = NOW(), cs_code = '" . $conn->real_escape_string($newCode) . "', cs_updatetime = NOW(), cs_claimFrom = " . $row['originalId'] . ", cs_chain = '" . $conn->real_escape_string($newChain) . "', is_silent = " . $is_silent . " WHERE id = " . $cid; $conn->query($updateSql); // Insert claim record $insertSql = "INSERT INTO claimrecord (oldCode, originalEmp, newEmp, cs_id, claimTime, isread) VALUES ( '" . $conn->real_escape_string($oldCode) . "', '" . $conn->real_escape_string($originalEmp) . "', '" . $conn->real_escape_string($_SESSION['employee_name']) . "', " . $cid . ", NOW(), 0 )"; $conn->query($insertSql); // Delete tags $conn->query("DELETE FROM tagtable WHERE customerId = " . $cid); echo "1"; } } ?>