changes
This commit is contained in:
@@ -415,6 +415,15 @@ public function missingContracts(Import $import)
|
||||
->where('client_cases.client_id', $import->client_id)
|
||||
->where('contracts.active', 1)
|
||||
->whereNull('contracts.deleted_at')
|
||||
// Exclude contracts that have any ACTIVE segment marked as excluded
|
||||
->whereNotExists(function ($sq) {
|
||||
$sq->select(\DB::raw(1))
|
||||
->from('contract_segment')
|
||||
->join('segments', 'segments.id', '=', 'contract_segment.segment_id')
|
||||
->whereColumn('contract_segment.contract_id', 'contracts.id')
|
||||
->where('contract_segment.active', true)
|
||||
->where('segments.exclude', true);
|
||||
})
|
||||
->when(count($present) > 0, function ($q) use ($present) {
|
||||
$q->whereNotIn('contracts.reference', $present);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user