# Function deleteCharter

### <a name="func_1"></a>

#### <span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span><span lang="AR-SA"><span style="mso-spacerun: yes;"> </span>هدف:</span>

این متد مسئولیت حذف کامل و دائمی یک چارتر و تمام داده‌های وابسته‌ی آن از سیستم را بر عهده دارد. عملکرد این تابع بسیار حساس و حیاتی است، زیرا قبل از اقدام به حذف، یک بررسی امنیتی کلیدی انجام می‌دهد: با فراخوانی تابع `getCharterCapacity`، ظرفیت فروخته‌شده‌ی چارتر را استعلام می‌کند. اگر حتی یک صندلی یا اتاق از چارتر فروخته شده باشد (یعنی ظرفیت کل با ظرفیت باقیمانده برابر نباشد)، متد عملیات را متوقف کرده و با یک خطای `409 Conflict` به کاربر اطلاع می‌دهد که حذف به دلیل وجود رزروهای قطعی ممکن نیست. در صورت موفقیت‌آمیز بودن این بررسی، متد با استفاده از یک `DB::transaction`، حذف آبشاری داده‌ها را تضمین می‌کند. ابتدا خود رکورد چارتر از جدول `charters` حذف می‌شود، سپس تمام رکوردهای مرتبط در جداول `charter_items` و `charter_calculations` نیز پاک می‌شوند. این رویکرد تراکنشی، یکپارچگی دیتابیس را حفظ می‌کند و از باقی ماندن داده‌های یتیم (Orphaned Data) جلوگیری می‌نماید.

<table border="1" class="align-center" id="bkmrk-%D9%88%DB%8C%DA%98%DA%AF%DB%8C%E2%80%8C%D9%87%D8%A7-%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA-%D9%87%D8%AF%D9%81" style="border-collapse: collapse; width: 80.9524%; height: 196.891px; background-color: rgb(236, 202, 250); border: 1px inset rgb(206, 212, 217);"><colgroup><col style="width: 50.0736%;"></col><col style="width: 50.0736%;"></col></colgroup><thead><tr style="height: 30.7969px;"><td style="height: 30.7969px; border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">ویژگی‌ها</span>**</span></td><td style="height: 30.7969px; border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">توضیحات</span>**</span></td></tr></thead><tbody><tr style="height: 29.7969px; background-color: rgb(206, 212, 217);"><td style="height: 29.7969px; border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">هدف کلی</span>**</span></td><td style="height: 29.7969px; border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span lang="AR-SA" style="color: rgb(0, 0, 0);">حذف کامل و دائمی یک چارتر و تمام موجودیت‌های مرتبط با آن.</span></td></tr><tr style="height: 29.7969px; background-color: rgb(206, 212, 217);"><td style="height: 29.7969px; border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">نوع حذف</span>**</span></td><td style="height: 29.7969px; border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255);"><span lang="AR-SA" style="color: rgb(0, 0, 0);">حذف فیزیکی (Hard Delete) از دیتابیس، نه حذف منطقی (Soft Delete).</span></td></tr><tr style="height: 29.7969px; background-color: rgb(206, 212, 217);"><td style="height: 29.7969px; border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">بررسی امنیتی</span>**</span></td><td style="height: 29.7969px; border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">جلوگیری قاطع از حذف چارتری که دارای فروش قطعی است.</span></td></tr><tr style="height: 30.1094px; background-color: rgb(206, 212, 217);"><td style="height: 30.1094px; border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">یکپارچگی داده</span>**</span></td><td style="height: 30.1094px; border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);">استفاده از `DB::transaction` برای تضمین حذف اتمیک (موفقیت یا شکست کامل عملیات).</span></td></tr><tr><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">حذف آبشاری</span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">حذف رکوردهای وابسته از جداول `charter_items` و `charter_calculations`.</span></td></tr><tr><td style="border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">خطایابی</span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0);">بازگرداندن خطای `409 Conflict` با پیام واضح در صورت نقض قانون فروش.</span></td></tr><tr><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA">بازخورد موفقیت</span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">ارسال پاسخ `204 No Content` در صورت موفقیت‌آمیز بودن عملیات حذف.</span></td></tr></tbody></table>

<div align="right" id="bkmrk-"></div>---

#### <span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span><span lang="AR-SA">ورودی</span><span lang="FA" style="font-family: 'Calibri',sans-serif; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-language: FA;">‌ها (پارامتر‌ها):</span>

<span dir="LTR"> </span>

<table border="1" class="align-center" id="bkmrk-%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA-%D9%86%D9%88%D8%B9-%D8%AF%D8%A7%D8%AF%D9%87-%D9%86%D8%A7%D9%85" style="border-collapse: collapse; width: 80.9235%; height: 286.906px; background-color: rgb(236, 202, 250); border: 1px inset rgb(206, 212, 217);"><colgroup><col style="width: 50.0575%;"></col><col style="width: 12.4768%;"></col><col style="width: 12.4768%;"></col><col style="width: 24.9536%;"></col></colgroup><thead><tr style="height: 30.7969px;"><td style="height: 30.7969px; border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">توضیحات</span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">موقعیت</span>**</span></td><td style="height: 30.7969px; border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">نوع داده</span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161); height: 30.7969px;"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">نام پارمتر</span>**</span></td></tr></thead><tbody><tr style="height: 47.2188px;"><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250); height: 47.2188px;"><span style="color: rgb(0, 0, 0);">**شناسه منحصر به فرد چارتری که باید حذف شود.**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);">**<span style="color: black; mso-color-alt: windowtext;">`Route/Body`</span>**</td><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250); height: 47.2188px;">**<span style="color: black; mso-color-alt: windowtext;">`integer`</span>**</td><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250); height: 47.2188px;"><span style="color: rgb(0, 0, 0);">**`$request->id`**</span></td></tr></tbody></table>

<div align="right" id="bkmrk--2"></div>---

#### <span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·<span style="font: 7.0pt 'Times New Roman';"> </span></span></span><span lang="AR-SA">خروجی</span><span dir="LTR"> (Return)</span><span lang="FA" style="font-family: 'Calibri',sans-serif; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-bidi-language: FA;">:</span>

<span dir="LTR"> </span>

<div align="right" id="bkmrk-%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA-%D9%86%D9%88%D8%B9-%D8%AF%D8%A7%D8%AF%D9%87-%D8%B1%D8%B4%D8%AA"></div><table border="1" class="align-center" id="bkmrk-%D8%AA%D9%88%D8%B6%DB%8C%D8%AD%D8%A7%D8%AA-%D9%86%D9%88%D8%B9-%D8%AF%D8%A7%D8%AF%D9%87-%D8%B1%D8%B4%D8%AA-1" style="border-collapse: collapse; width: 80.9524%; height: 158.609px; background-color: rgb(236, 202, 250); border: 1px inset rgb(206, 212, 217);"><colgroup><col style="width: 50.0736%;"></col><col style="width: 50.0736%;"></col></colgroup><thead><tr style="height: 30.7969px;"><td style="height: 30.7969px; border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">توضیحات</span>**</span></td><td style="height: 30.7969px; border-color: rgb(206, 212, 217); background-color: rgb(132, 63, 161);"><span style="color: rgb(255, 255, 255);">**<span lang="AR-SA" style="font-family: 'B Titr';">نوع داده</span>**</span></td></tr></thead><tbody><tr style="height: 48.5625px; background-color: rgb(206, 212, 217);"><td style="height: 48.5625px; border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA"><span dir="RTL" lang="AR-SA" style="font-size: 11.0pt; line-height: 107%; font-family: 'B Nazanin'; mso-ascii-font-family: 'B Nazanin'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: 'B Nazanin'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">در صورت موفقیت، یک پاسخ خالی با کد `204 No Content` بازگردانده می‌شود.</span></span>**</span></td><td style="height: 48.5625px; border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250);"><span lang="AR-SA" style="color: rgb(0, 0, 0);">**<span style="font-size: 11.0pt; line-height: 107%; font-family: 'B Nazanin'; mso-ascii-font-family: 'B Nazanin'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: 'B Nazanin'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">`Illuminate\Http\JsonResponse`</span>**</span></td></tr><tr style="height: 48.5625px;"><td style="border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255); height: 48.5625px;"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA"><span dir="RTL" lang="AR-SA" style="font-size: 11.0pt; line-height: 107%; font-family: 'B Nazanin'; mso-ascii-font-family: 'B Nazanin'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: 'B Nazanin'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">در صورت وجود رزرو روی چارتر، یک آبجکت `JSON` با کد `409 Conflict` و پیام خطا بازگردانده می‌شود.</span></span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(255, 255, 255); height: 48.5625px;"><span lang="AR-SA" style="color: rgb(0, 0, 0);">**<span style="font-size: 11.0pt; line-height: 107%; font-family: 'B Nazanin'; mso-ascii-font-family: 'B Nazanin'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: 'B Nazanin'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">`Illuminate\Http\JsonResponse`</span>**</span></td></tr><tr style="height: 30.6875px;"><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250); height: 30.6875px;"><span style="color: rgb(0, 0, 0);">**<span lang="AR-SA"><span dir="RTL" lang="AR-SA" style="font-size: 11.0pt; line-height: 107%; font-family: 'B Nazanin'; mso-ascii-font-family: 'B Nazanin'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: 'B Nazanin'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">در صورت بروز خطای غیرمنتظره در حین تراکنش دیتابیس، یک آبجکت `JSON` با کد `400 Bad Request` و جزئیات استثناء (Exception) بازگردانده می‌شود.</span></span>**</span></td><td style="border-color: rgb(206, 212, 217); background-color: rgb(236, 202, 250); height: 30.6875px;"><span lang="AR-SA" style="color: rgb(0, 0, 0);">**<span style="font-size: 11.0pt; line-height: 107%; font-family: 'B Nazanin'; mso-ascii-font-family: 'B Nazanin'; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-font-family: 'B Nazanin'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">`Illuminate\Http\JsonResponse`</span>**</span></td></tr></tbody></table>

---

#### <span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;">·</span></span><span lang="AR-SA"><span style="mso-spacerun: yes;"> مثال استفاده / سناریو</span>:</span>

**<span style="text-decoration: underline; background-color: rgb(251, 238, 184);">سناریو ۱</span>: حذف موفق یک چارتر بدون فروش**

- **Request:**
- `id`: 350
- **Action:**

1. متد ظرفیت چارتر با شناسه 350 را بررسی می‌کند.
2. **فرض:** هیچ رزروی ثبت نشده است (`capacity['total'] == capacity['capacity']`).
3. یک تراکنش دیتابیس آغاز می‌شود.
4. رکوردها از `charter_items` و `charter_calculations` که `main_id` آن‌ها 350 است، حذف می‌شوند.
5. رکورد اصلی از جدول `charters` با شناسه 350 حذف می‌شود.
6. تراکنش با موفقیت `commit` می‌شود.

- **Response:**
- `HTTP Status`: `204 No Content`

**<span style="text-decoration: underline; background-color: rgb(251, 238, 184);">سناریو ۲</span>: تلاش برای حذف چارتری که فروش داشته است**

- **Request:**
- `id`: 351
- **Action:**

1. متد ظرفیت چارتر با شناسه 351 را بررسی می‌کند.
2. **فرض:** تعدادی رزرو ثبت شده است (`capacity['total'] != capacity['capacity']`).
3. عملیات متوقف شده و هیچ تغییری در دیتابیس اعمال نمی‌شود.

- **Response:**
- `HTTP Status`: `409 Conflict`
- `Body`:

<div class="code-header" dir="ltr" id="bkmrk-json"><span class="language-label">json</span></div>```
        {
            "error": {
                "code": 1000,
                "message": "بر روی این چارتر رزرو انجام شده است و امکان حذف وجود ندارد."
            }
        }
```