feat: generate draft assignments from a staffing matrix
This commit is contained in:
1 parent
3116d23199
commit
2fc9806c69
41 files changed
+2618
No files matched your search
@@ -4,6 +4,7 @@ namespace App\Repository;
|
||||
|
||||
use App\Entity\Application;
|
||||
use App\Entity\Assignment;
|
||||
use App\Entity\Destination;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\JobProfile;
|
||||
use App\Entity\Teamer;
|
||||
@@ -405,4 +406,29 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
->getQuery()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which of these destinations have ever had an assignment - soft-deleted and called-off ones
|
||||
* included, because a draft the office deleted must not be generated again.
|
||||
*
|
||||
* @param list<Destination> $destinations
|
||||
*
|
||||
* @return list<int> destination ids
|
||||
*/
|
||||
public function getDestinationIdsWithAnyAssignment(array $destinations): array
|
||||
{
|
||||
if ([] === $destinations) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder('assignment');
|
||||
|
||||
return array_map('intval', $qb
|
||||
->select('DISTINCT IDENTITY(assignment.destination)')
|
||||
->where($qb->expr()->in('assignment.destination', ':destinations'))
|
||||
->setParameter('destinations', $destinations)
|
||||
->getQuery()
|
||||
->getSingleColumnResult()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -124,4 +124,41 @@ class DestinationRepository extends ServiceEntityRepository
|
||||
->getArrayResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dates the staffing matrix applies to: live, starting after $today, of one of the
|
||||
* matrix's products, and reported by the latest import. The last condition keeps out dates
|
||||
* cancelled upstream - the import never deletes, so a vanished date keeps its row and its
|
||||
* product code, but not a current importedAt.
|
||||
*
|
||||
* @param list<string> $productCodes
|
||||
*
|
||||
* @return list<Destination>
|
||||
*/
|
||||
public function getStaffingCandidates(array $productCodes, \DateTimeImmutable $today): array
|
||||
{
|
||||
if ([] === $productCodes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$qb = $this->createQueryBuilder('destination');
|
||||
|
||||
return $qb
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->isNull('destination.deletedAt'),
|
||||
$qb->expr()->in('destination.productCode', ':productCodes'),
|
||||
$qb->expr()->gt('destination.dateFrom', ':today'),
|
||||
$qb->expr()->eq(
|
||||
'destination.importedAt',
|
||||
'(SELECT MAX(latest.importedAt) FROM '.Destination::class.' latest)',
|
||||
),
|
||||
))
|
||||
->setParameter('productCodes', $productCodes)
|
||||
->setParameter('today', $today->format('Y-m-d'))
|
||||
->orderBy('destination.dateFrom', \SortDirection::Ascending)
|
||||
->addOrderBy('destination.productCode', \SortDirection::Ascending)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\StaffingRule;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<StaffingRule>
|
||||
*
|
||||
* @method StaffingRule|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method StaffingRule|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method StaffingRule[] findAll()
|
||||
* @method StaffingRule[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class StaffingRuleRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, StaffingRule::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<StaffingRule>
|
||||
*/
|
||||
public function getList(): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('staffing_rule');
|
||||
|
||||
return $qb
|
||||
->where($qb->expr()->isNull('staffing_rule.deletedAt'))
|
||||
->orderBy('staffing_rule.productCode', \SortDirection::Ascending)
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* For UniqueEntity: a soft-deleted row keeps its code and must not block a new one.
|
||||
*
|
||||
* @return list<StaffingRule>
|
||||
*/
|
||||
public function findLiveByProductCode(array $fields): array
|
||||
{
|
||||
$qb = $this->createQueryBuilder('staffing_rule');
|
||||
|
||||
return $qb
|
||||
->where($qb->expr()->andX(
|
||||
$qb->expr()->eq('staffing_rule.productCode', ':productCode'),
|
||||
$qb->expr()->isNull('staffing_rule.deletedAt'),
|
||||
))
|
||||
->setParameter('productCode', $fields['productCode'])
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user