refactor(inco): simplify base query by using subquery for family label
Improves readability and maintainability of the query logic.
This commit is contained in:
parent
8c13ab5236
commit
f1c3100ef5
1 changed files with 8 additions and 7 deletions
|
|
@ -126,16 +126,17 @@ final class ArcadiaIncoSheetDirectory implements IncoSheetDirectory
|
|||
$articleRefTable = ArticleRefTable::table($this->connection);
|
||||
$famVenteTable = FamVenteTable::table($this->connection);
|
||||
|
||||
$articleRefSubQuery = $this->connection
|
||||
->table($articleRefTable)
|
||||
->select(['NO_ART', $this->connection->raw('MIN(COD_FAMVTE) as COD_FAMVTE')])
|
||||
->groupBy('NO_ART');
|
||||
$familleSubQuery = $this->connection
|
||||
->table($famVenteTable, 'fv')
|
||||
->join($articleRefTable . ' as ar', 'ar.COD_FAMVTE', '=', 'fv.COD_FAMVTE')
|
||||
->whereColumn('ar.NO_ART', '=', 'INCO.NO_ART')
|
||||
->select('fv.LIB_FAMVTE')
|
||||
->limit(1);
|
||||
|
||||
return $this->connection
|
||||
->table($incoTable)
|
||||
->leftJoinSub($articleRefSubQuery, 'ARTICLE_REF', 'INCO.NO_ART', '=', 'ARTICLE_REF.NO_ART')
|
||||
->leftJoin($famVenteTable, 'ARTICLE_REF.COD_FAMVTE', '=', 'FAM_VENTE.COD_FAMVTE')
|
||||
->select(['INCO.*', 'FAM_VENTE.LIB_FAMVTE as FAMILLE_VTE_LIBELLE']);
|
||||
->select(['INCO.*'])
|
||||
->selectSub($familleSubQuery, 'FAMILLE_VTE_LIBELLE');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue