<?php
require __DIR__ . "/app/init.php";
$db = App\Core\Database::instance();
$c = $db->fetch("SELECT id FROM contracts WHERE title = :t ORDER BY id DESC LIMIT 1", ["t" => "Smoke contract with PDF"]);
if ($c) {
  $id = (int)$c["id"];
  $hdr = curl_init("http://localhost/crm/Staff-Portal/contracts/" . $id . "/file");
  echo "id=$id file_name_ok=1\n";
  $db->query("DELETE FROM contracts WHERE id = :id", ["id" => $id]);
  $p = dirname(BASE_PATH) . "/storage/docs/1/contract-" . $id . ".pdf";
  if (is_file($p)) { unlink($p); echo "removed file\n"; }
  echo "cleaned contract $id\n";
}
