<?php
namespace App\Command\Leave;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputArgument;
use App\Service\LeaveService;
class LeaveFindCommand extends Command{
protected static $defaultName = 'app:leavefind';
private $entityManager;
private $leaveService;
private $year;
protected function configure(): void
{
$this
// ...
->addArgument('year', $this->year ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'Year')
;
}
public function __construct(?String $year = null,EntityManagerInterface $entityManager,LeaveService $leaveService){
parent::__construct();
$this->entityManager = $entityManager;
$this->leaveService = $leaveService;
if(is_null($year)){$year=date('Y');}
$this->year=$year;
}
protected function execute(InputInterface $input, OutputInterface $output): int{
$io = new SymfonyStyle($input, $output);
$usr = array();
$usrkey=array();
$lrq = $this->entityManager->getRepository(\App\Entity\LeaveRequest::class)->findBy(array('leaveType'=>'4'));
$output->writeln('year Leave');
$c=count($lrq);
$bar1 = new ProgressBar($output, $c);;
$bar1->setEmptyBarCharacter('░'); // light shade character \u2591
$bar1->setProgressCharacter('');
$bar1->setBarCharacter('▓'); // dark shade character \u2593
$bar1->start();
$i=1;
foreach($lrq as $l){
if(!isset($usr['u'.$l->getUser()->getId()])){
$usr['u'.$l->getUser()->getId()]=0;
array_push($usrkey,$l->getUser());
}
$al=$l->getAlocation();
if(!is_null($al)){
if(isset($al['child'])){
if(is_array($al['child'])){
if(isset($al['child']['y2022'])){
foreach($al['child']['y2022'] as $k=>$v){
$usr['u'.$l->getUser()->getId()]+=$v;
}
}
}
}
}
$i++;
$bar1->advance();
}
$datasm=array();
$lrq=$this->entityManager->getRepository(\App\Entity\LeaveEntitlement::class)->findBy(array('leaveType'=>'5','user'=>$usrkey,'year'=>'2022'));
foreach($lrq as $l){
$uid=$l->getUser()->getId();
if(!isset($datasm['u'.$uid])){
if(isset($usr['u'.$uid])){
$datasm['u'.$uid]=array();
$datasm['u'.$uid]['id']=$uid;
$datasm['u'.$uid]['total']=$l->getLeaveEntitlements();
$datasm['u'.$uid]['left']=$l->getLeaveLeft();
$datasm['u'.$uid]['use']=$datasm['u'.$uid]['total']-$datasm['u'.$uid]['left'];
$datasm['u'.$uid]['data']=$usr['u'.$uid];
}
}
}
print "\n";
print_r($datasm);
print "\n";
return (int) true;
}
}