35 lines
898 B
PHP
35 lines
898 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Invoices;
|
|
|
|
use App\Models\BaseModel;
|
|
|
|
final class InvoiceModel extends BaseModel
|
|
{
|
|
protected string $table = 'invoices';
|
|
|
|
public function findByTenant(string $tenantId): array
|
|
{
|
|
$stmt = $this->db()->prepare("SELECT * FROM {$this->table} WHERE tenant_id = ? AND deleted_at IS NULL ORDER BY created_at DESC");
|
|
$stmt->execute([$tenantId]);
|
|
return $stmt->fetchAll();
|
|
}
|
|
|
|
public function findByStatus(string $status, ?string $tenantId = null): array
|
|
{
|
|
$sql = "SELECT * FROM {$this->table} WHERE status = ? AND deleted_at IS NULL";
|
|
$params = [$status];
|
|
|
|
if ($tenantId) {
|
|
$sql .= " AND tenant_id = ?";
|
|
$params[] = $tenantId;
|
|
}
|
|
|
|
$stmt = $this->db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
return $stmt->fetchAll();
|
|
}
|
|
}
|