{"id":51045320,"url":"https://github.com/whilesmartphp/eloquent-invoices","last_synced_at":"2026-06-22T13:02:29.213Z","repository":{"id":353782600,"uuid":"1203549646","full_name":"whilesmartphp/eloquent-invoices","owner":"whilesmartphp","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-10T13:15:08.000Z","size":22,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"dev","last_synced_at":"2026-06-10T13:16:48.848Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whilesmartphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-07T06:22:46.000Z","updated_at":"2026-04-25T13:48:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/whilesmartphp/eloquent-invoices","commit_stats":null,"previous_names":["whilesmartphp/eloquent-invoices"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/whilesmartphp/eloquent-invoices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-invoices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-invoices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-invoices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-invoices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whilesmartphp","download_url":"https://codeload.github.com/whilesmartphp/eloquent-invoices/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whilesmartphp%2Feloquent-invoices/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34649822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-22T13:02:28.580Z","updated_at":"2026-06-22T13:02:29.207Z","avatar_url":"https://github.com/whilesmartphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# whilesmart/eloquent-invoices\n\nPolymorphic invoice management with line items for Laravel applications. Designed to pair with `whilesmart/eloquent-customers`.\n\n## Install\n\n```bash\ncomposer require whilesmart/eloquent-invoices\nphp artisan migrate\n```\n\nThe customers package is a hard dependency — composer will pull it in automatically.\n\n## Use\n\nAdd `HasInvoices` to any model that should own invoices (Workspace, Organization, User, etc.):\n\n```php\nuse Whilesmart\\Invoices\\Traits\\HasInvoices;\n\nclass Workspace extends Model\n{\n    use HasInvoices;\n}\n```\n\nThe trait gives you a `morphMany` relation:\n\n```php\n$invoice = $workspace-\u003einvoices()-\u003ecreate([\n    'customer_id' =\u003e $customer-\u003eid,\n    'number' =\u003e 'INV-2026-0001',\n    'issue_date' =\u003e today(),\n    'due_date' =\u003e today()-\u003eaddDays(30),\n    'currency' =\u003e 'USD',\n]);\n\n$invoice-\u003elineItems()-\u003ecreate([\n    'description' =\u003e 'Roofing labour',\n    'quantity' =\u003e 8,\n    'unit' =\u003e 'hour',\n    'unit_price_cents' =\u003e 7500,\n]);\n\n$invoice-\u003erecalculate()-\u003esave();\n```\n\n`recalculate()` reads the line items and computes `subtotal_cents`, then applies `discount_cents` and `tax_cents` to set `total_cents`. `balanceCents()` returns the unpaid remainder (`total - amount_paid`).\n\n## Endpoints\n\n| Verb | Path | Notes |\n|---|---|---|\n| `GET` | `/api/invoices` | List, filter by `owner_type`+`owner_id`, `status`, `customer_id` |\n| `POST` | `/api/invoices` | Create (with optional nested `line_items`) |\n| `GET` | `/api/invoices/{id}` | Show with customer + line items |\n| `PUT` | `/api/invoices/{id}` | Update header fields |\n| `DELETE` | `/api/invoices/{id}` | Soft delete |\n| `POST` | `/api/invoices/{id}/send` | Mark as sent, set `sent_at` |\n| `POST` | `/api/invoices/{id}/mark-paid` | Apply payment (`amount_cents`), advance status to `partially_paid` or `paid` |\n| `POST` | `/api/invoices/{id}/void` | Mark as void |\n\n## Polymorphic line items\n\nLine items can either be **freehand** (you supply description / quantity / unit_price_cents directly) or **bound to an invoiceable model** via a `morphTo` relation. Any model that implements `Whilesmart\\Invoices\\Contracts\\Invoiceable` (or uses the `IsInvoiceable` trait) can be referenced.\n\n```php\nuse Whilesmart\\Invoices\\Traits\\IsInvoiceable;\n\nclass LabourRate extends Model\n{\n    use IsInvoiceable;\n    // expose `name`, `default_unit`, `default_price_cents` and the trait does the rest\n}\n```\n\nThen create an invoice line item by reference:\n\n```php\n$invoice-\u003elineItems()-\u003ecreate([\n    'invoiceable_type' =\u003e LabourRate::class,\n    'invoiceable_id'   =\u003e $rate-\u003eid,\n    'quantity'         =\u003e 8,\n    // description / unit / unit_price_cents are pulled from the rate and snapshotted\n]);\n```\n\nOr via the API:\n\n```json\nPOST /api/invoices\n{\n  \"owner_type\": \"App\\\\Models\\\\Workspace\",\n  \"owner_id\": 12,\n  \"number\": \"INV-2026-0001\",\n  \"issue_date\": \"2026-04-07\",\n  \"line_items\": [\n    { \"invoiceable_type\": \"App\\\\Models\\\\LabourRate\", \"invoiceable_id\": 5, \"quantity\": 8 },\n    { \"description\": \"Site cleanup\", \"quantity\": 1, \"unit_price_cents\": 12000 }\n  ]\n}\n```\n\nSnapshot semantics: when a line item is created from an invoiceable, description / unit / price are **copied** at create time. Later edits to the source model never mutate historical invoices.\n\nPair with `whilesmart/eloquent-products` for a generic SKU catalog as the first concrete `Invoiceable`.\n\n## Status enum\n\n`Whilesmart\\Invoices\\Enums\\InvoiceStatus`: `draft`, `sent`, `partially_paid`, `paid`, `overdue`, `void`.\n\n## Schema\n\n`invoices` table:\n\n| column | type |\n|---|---|\n| id | bigint |\n| owner_type / owner_id | morphs |\n| customer_id | foreignId nullable → customers |\n| number | unique string |\n| status | string (enum) |\n| issue_date / due_date / sent_at / paid_at | date |\n| currency | char(3) |\n| subtotal_cents / discount_cents / tax_cents / total_cents / amount_paid_cents | bigint |\n| notes / terms | text |\n| metadata | json |\n| timestamps + soft deletes | |\n\n`invoice_line_items` table:\n\n| column | type |\n|---|---|\n| id | bigint |\n| invoice_id | foreignId → invoices |\n| position | unsigned int |\n| description | string |\n| quantity | decimal(12,4) |\n| unit | nullable string |\n| unit_price_cents / amount_cents | bigint |\n| metadata | json |\n| timestamps | |\n\n`amount_cents` is auto-computed from `quantity * unit_price_cents` on save.\n\n## Config\n\nPublish with `php artisan vendor:publish --tag=invoices-config`. Override `register_routes`, `route_prefix`, `route_middleware`, table names, and `number_prefix` via env or the published config file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhilesmartphp%2Feloquent-invoices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhilesmartphp%2Feloquent-invoices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhilesmartphp%2Feloquent-invoices/lists"}