---
tags: [attachments, service]
module: Attachments
---

# AttachmentServices

## Connections
[[_Attachments]] · [[[Model]GeneralAttachment]] · [[[Repo]GeneralAttachmentsRepository]] · [[[Controller]GeneralAttachmentController]] · [[[Cross]CrossModuleDependencies]] · [[Accounting/[Cross]CrossModuleDependencies]]

## Source
`Modules/Attachments/Services/`

## Services

| Service | Responsibility |
|---|---|
| `CreatingNewGeneralAttachmentService` | Uploads file via `Upload::privateUpload()`, creates [[[Model]GeneralAttachment]] record with `is_attached = false` |
| `DeletingAttachmentService` | Deletes file from S3 or local storage, sets `deleted_by`, soft-deletes record; temporarily disables auditing during multi-step delete |
| `PreparingDataForCreatingAttachmentService` | Loads active customers + suppliers for the reference dropdown on the create form |
| `RetrievingNotAttachedFilesService` | Returns all `is_attached = false` files filtered by customer/supplier; maps paths to URLs |
| `AttachingFileToModelService` | **Used by other modules** — attaches a staged [[[Model]GeneralAttachment]] to an Invoice, PurchaseBill, or Expense; moves the file, sets `is_attached = true`, creates the specific attachment record |

## AttachingFileToModelService Detail
This is the primary integration point — called from Sales and Purchases modules:
```
AttachingFileToModelService::execute(int $attachmentId, Model $model, BaseRepository $repo)
  → Identifies model type (Invoice / PurchaseBill / Expense)
  → Moves file on S3 or local disk
  → Updates GeneralAttachment.is_attached = true
  → Creates InvoiceAttachment / PurchaseBillAttachment / ExpenseAttachment record
```

## Validation
`CreatingNewGeneralAttachmentValidator` — rules:
- `title`: required, string, max:255
- `reference`: nullable, uses `SuppliersAndCustomersExistenceRule` ([[[Cross]CrossModuleDependencies#Accounting]])
- `attachment`: required, uses `GlobalAttachmentRule`

`CreatingNewGeneralAttachmentRequestEntity` — parses `reference` field:
- prefix `s_id` → supplier_id
- prefix `c_id` → customer_id
