---
tags: [purchases, model]
module: Purchases
---

# [Model]PurchaseBill

## Connections
[[_Purchases]] · [[[Model]Supplier]] · [[[Model]BillReturn]] · [[[Model]PurchaseOrder]] · [[[Model]SupplierPaymentReceipt]] · [[[Controller]Controllers]] · [[[Service]PurchaseBillServices]] · [[[Repo]Repositories]] · [[[Enum]Enums]] · [[[Observer]Observers]] · [[[Cross]CrossModuleDependencies]]

## Source
`Modules/Purchases/Models/PurchaseBill.php`  
Related: `PurchaseBillDetails.php` · `PurchaseBillAttachment.php` · `BillPaymentReceipt.php`

## Responsibilities
- Core purchase transaction: records goods/services purchased from a supplier
- Tracks payment via `paid_amount` / `total` and computes status (PAID, NOT_PAID, DUE, OVERDUE…)
- Linked to journal entry for double-entry accounting
- Supports draft mode (`is_draft` flag)
- Has `BillObserver` → records usage for `BillsLimits` feature + updates last activity
- Auditable, FormatDateAndTimeTrait, SoftDeletes, UsesTenantConnection

## Key Relationships
| Relation | Type | Target |
|---|---|---|
| supplier | belongsTo | Supplier (withTrashed) |
| paymentTerm | belongsTo | PaymentTerm (withTrashed) |
| paymentAccount | belongsTo | Account (Accounting) via `payment_account_id` |
| purchaseBillDetails | hasMany | PurchaseBillDetails |
| attachments | hasMany | PurchaseBillAttachment |
| assignedReceipts | belongsToMany | SupplierPaymentReceipt via BillPaymentReceipt (active) |
| allAssignedReceipts | belongsToMany | SupplierPaymentReceipt (includes trashed) |
| payments | hasMany | BillPaymentReceipt |
| costCenter | belongsTo | CostCenter (Products) |
| journalEntry | belongsTo | JournalEntry (Accounting) |
| fiscalYear | belongsTo | FiscalYear (Settings) |
| formDesign | belongsTo | FormDesign (Settings) |
| billReturn | hasOne | BillReturn (withTrashed) |
| purchaseOrder | belongsTo | PurchaseOrder |
| addedBy / updatedBy / deletedBy | belongsTo | User (CompanyUser) withTrashed |

## Appended Attributes
`final_total` — computed from total + vat

## Methods
`disableAudit()` · `enableAudit()` · `deleteAutoCreatedReceipt()`

---

## [Model]PurchaseBillDetails

**Table:** `purchase_bill_details`  
**Source:** `Modules/Purchases/Models/PurchaseBillDetails.php`

| Relation | Type | Target |
|---|---|---|
| purchaseBill | belongsTo | PurchaseBill |
| product | belongsTo | Product (withTrashed) |
| warehouseProduct | belongsTo | WarehouseProduct (withTrashed) |
| tax | belongsTo | Tax (withTrashed) |

---

## [Model]BillPaymentReceipt (pivot)

**Table:** `bills_payment_receipts`  
Links `PurchaseBill` ↔ `SupplierPaymentReceipt` with `allocated_amount`. Auditable, SoftDeletes.

| Relation | Type | Target |
|---|---|---|
| bill | hasOne | PurchaseBill |
| receipt | hasOne | SupplierPaymentReceipt |
| trashedReceipt | hasOne | SupplierPaymentReceipt (withTrashed) |

---

## [Model]PurchaseBillAttachment

**Table:** `purchase_bill_attachments` — `UPLOAD_PATH = 'purchase_bills'`  
Appends: `file_path`
