Add reference_jo_id field to hold the job order id for reference orders. Add a command to decouple reference job order from job order. #762
This commit is contained in:
parent
ca09d6fc2e
commit
a437a1f74e
2 changed files with 71 additions and 1 deletions
53
src/Command/SetJobOrderReferenceJOIdCommand.php
Normal file
53
src/Command/SetJobOrderReferenceJOIdCommand.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class SetJobOrderReferenceJOIdCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:setreferencejoid')
|
||||
->setDescription('Set job order reference jo id for existing job orders.')
|
||||
->setHelp('Set job order reference jo id for existing job orders. Decoupling job order from reference job order.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// get the job orders where ref_jo is not null
|
||||
$query = $this->em->createQuery('SELECT jo FROM App\Entity\JobOrder jo WHERE jo.ref_jo IS NOT NULL');
|
||||
|
||||
$jos = $query->getResult();
|
||||
|
||||
foreach ($jos as $jo)
|
||||
{
|
||||
$ref_jo_id = $jo->getReferenceJO()->getID();
|
||||
|
||||
error_log('Setting reference jo id ' . $ref_jo_id . ' for job order ' . $jo->getID());
|
||||
|
||||
$jo->setReferenceJOId($ref_jo_id);
|
||||
|
||||
// set the ref_jo to null to decouple ref jo and jo
|
||||
$jo->setReferenceJO(null);
|
||||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -441,6 +441,12 @@ class JobOrder
|
|||
*/
|
||||
protected $flag_cust_new;
|
||||
|
||||
// reference JO id. We are now decoupling job order from itself
|
||||
/**
|
||||
* @ORM\Column(type="integer", nullable=true)
|
||||
*/
|
||||
protected $reference_jo_id;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->date_create = new DateTime();
|
||||
|
|
@ -792,7 +798,7 @@ class JobOrder
|
|||
return $this->tickets;
|
||||
}
|
||||
|
||||
public function setReferenceJO(JobOrder $ref_jo)
|
||||
public function setReferenceJO(JobOrder $ref_jo = null)
|
||||
{
|
||||
$this->ref_jo = $ref_jo;
|
||||
return $this;
|
||||
|
|
@ -1256,4 +1262,15 @@ class JobOrder
|
|||
return $this->flag_cust_new;
|
||||
}
|
||||
|
||||
public function setReferenceJOId($reference_jo_id)
|
||||
{
|
||||
$this->reference_jo_id = $reference_jo_id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReferenceJOId()
|
||||
{
|
||||
return $this->reference_jo_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue