update
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user