« Back to History
taka_out_entry_api.php
|
20260921_175631.php
Initial Domain Snapshot
Copy Code
<?php // taka_out_entry_api.php header('Content-Type: application/json; charset=utf-8'); // Bootstrap + auth (uses your ERP page_acl pattern) require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('taka_out_entry'); // keep acl key appropriate $u = $ctx['user'] ?? ['id' => 0]; $company_id = (int)($ctx['company_id'] ?? 0); $pdo = $ctx['pdo'] ?? null; if (!$pdo) { http_response_code(500); echo json_encode(['ok' => false, 'error' => 'Database not available']); exit; } // only POST if ($_SERVER['REQUEST_METHOD'] !== 'POST') { http_response_code(405); echo json_encode(['ok' => false, 'error' => 'Only POST allowed']); exit; } // read values (loose: accept both JSON and form-data) $raw = file_get_contents('php://input'); $post = $_POST; if (empty($post) && $raw) { $json = json_decode($raw, true); if (is_array($json)) $post = $json; } $entry_date = trim((string)($post['entry_date'] ?? '')); $saree_no = trim((string)($post['saree_no'] ?? '')); $taka_no = trim((string)($post['taka_no'] ?? '')); $party = trim((string)($post['party'] ?? '')); $remark = trim((string)($post['remark'] ?? '')); // basic validation $errors = []; if ($entry_date === '') $errors[] = 'Entry date required'; if ($saree_no === '') $errors[] = 'Saree no required'; if ($errors) { http_response_code(422); echo json_encode(['ok' => false, 'errors' => $errors]); exit; } // insert (company scoped) try { $stmt = $pdo->prepare(" INSERT INTO folding_out_entry (company_id, entry_date, saree_no, taka_no, party, remark, created_by) VALUES (:cid, :dt, :saree, :taka, :party, :remark, :uid) "); $ok = $stmt->execute([ ':cid' => $company_id, ':dt' => $entry_date, ':saree' => $saree_no, ':taka' => $taka_no, ':party' => $party, ':remark' => $remark, ':uid' => $u['id'], ]); if ($ok) { echo json_encode(['ok' => true, 'message' => 'Saved']); exit; } else { http_response_code(500); echo json_encode(['ok' => false, 'error' => 'DB insert failed']); exit; } } catch (PDOException $ex) { http_response_code(500); echo json_encode(['ok' => false, 'error' => 'Exception: '.$ex->getMessage()]); exit; }