diff --git a/app/Models/mBills.php b/app/Models/mBills.php index 4bc2b28..bfd88b2 100644 --- a/app/Models/mBills.php +++ b/app/Models/mBills.php @@ -27,18 +27,30 @@ class mBills extends Model { $quelle = model('App\Models\mAccounts'); $this->where('datum >=', date( 'Y-m-d', strtotime($start))); $this->where('datum <=', date( 'Y-m-d', strtotime($ende))); + // alle Detailsbuchungen wo account id übereinstimmt if ($source > 0) { $subs = $details->select('bill_id')->where('account_id',$source)->findAll(); - $keys=array(); - foreach ($subs as $value) { - $keys[] = intval($value->bill_id); +// log_message('error', 'Get Entries Det {msg}', ['msg'=>(string)$this->db->getLastQuery()]); + if (0 < sizeof($subs)){ + $keys=array(); + foreach ($subs as $value) { + $keys[] = intval($value->bill_id); + } + $this->groupStart(); + $this->where('source_id', $source ); + $this->orWhereIn('id', $keys ); + $this->groupEnd(); + + } else { + $this->where('source_id', $source ); } - $this->groupStart(); - $this->where('source_id', $source ); - $this->orWhereIn('id', $keys ); - $this->groupEnd(); } + $result = $this->orderBy('datum','desc')->where('lkz',null)->findAll(); + if (0 == sizeof($result)){ + return $result; + } + $keys=array(); foreach ($result as $value) { $keys[] = intval($value->id);