This commit is contained in:
2026-07-12 19:21:35 +02:00
parent f2d944b117
commit 41cb412cb0
49 changed files with 3170 additions and 52 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Models;
use CodeIgniter\Model;
class ReceiptModel extends Model
{
protected $table = 'receipts';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useTimestamps = true;
protected $allowedFields = [
'file_path', 'original_name', 'mime', 'merchant',
'receipt_date', 'total', 'status', 'raw_json', 'error_msg',
];
public function hasOriginalName(string $name): bool
{
return $this->where('original_name', $name)->countAllResults() > 0;
}
/**
* Lista paragonow do historii, z liczba pozycji i utworzonych operacji.
*/
public function withCounts(): array
{
return $this->db->table('receipts r')
->select('r.*')
->select('(SELECT COUNT(*) FROM receipt_items ri WHERE ri.receipt_id = r.id) AS items_count', false)
->select('(SELECT COUNT(*) FROM operations o WHERE o.receipt_id = r.id) AS operations_count', false)
->orderBy('r.id', 'DESC')
->get()->getResultArray();
}
}