From a437a1f74e30a275904530abb7d91270fbfe8be2 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 28 Sep 2023 14:15:41 +0800 Subject: [PATCH] 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 --- .../SetJobOrderReferenceJOIdCommand.php | 53 +++++++++++++++++++ src/Entity/JobOrder.php | 19 ++++++- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/Command/SetJobOrderReferenceJOIdCommand.php diff --git a/src/Command/SetJobOrderReferenceJOIdCommand.php b/src/Command/SetJobOrderReferenceJOIdCommand.php new file mode 100644 index 00000000..20ee236a --- /dev/null +++ b/src/Command/SetJobOrderReferenceJOIdCommand.php @@ -0,0 +1,53 @@ +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; + } +} diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 885bc295..9229eed9 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -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; + } + }