/** * Add userPaidExpenses * * @param \Opit\OpitHrm\TravelBundle\Entity\TEUserPaidExpense $userPaidExpenses * @return TravelExpense */ public function addUserPaidExpense(\Opit\OpitHrm\TravelBundle\Entity\TEUserPaidExpense $userPaidExpenses) { $this->userPaidExpenses[] = $userPaidExpenses; $userPaidExpenses->setTravelExpense($this); // synchronously updating inverse side return $this; }
/** * {@inheritDoc} */ public function doLoad(ObjectManager $manager) { // Test for required user/status references first if (!$this->hasReference('travel-request-approved')) { throw new \RuntimeException('Leave expense fixtures require travel request fixtures.'); } $travelRequest = $this->getReference('travel-request-approved'); $employee = $travelRequest->getUser()->getEmployee(); // First travel expense // Set values from travel request where needed $travelExpense1 = new TravelExpense(); $travelExpense1->setUser($travelRequest->getUser()); $travelExpense1->setTaxIdentification($employee->getTaxIdentification()); $travelExpense1->setRechargeable(false); $travelExpense1->setPayInEuro(true); $travelExpense1->setBankName($employee->getBankName()); $travelExpense1->setBankAccountNumber($employee->getBankAccountNumber()); $travelExpense1->setDepartureCountry('Hungary'); $travelExpense1->setArrivalCountry('UK'); $travelExpense1->setDepartureDateTime($travelRequest->getDepartureDate()); $travelExpense1->setArrivalDateTime($travelRequest->getArrivalDate()); // Add expenses paid by me/company if ($this->hasReference('currency-gbp') && $this->hasReference('expense-type-tickets')) { $expense1 = new TEUserPaidExpense(); $expense1->setDescription('London weekly pass'); $expense1->setDate($travelRequest->getDepartureDate()); $expense1->setExpenseType($this->getReference('expense-type-tickets')); $expense1->setAmount(16.5); $expense1->setCurrency($this->getReference('currency-gbp')); $expense1->setDestination('London'); $travelExpense1->addUserPaidExpense($expense1); $expense2 = new TEUserPaidExpense(); $expense2->setDescription('Taxi to hotel'); $expense2->setDate($travelRequest->getDepartureDate()); $expense2->setExpenseType($this->getReference('expense-type-taxi')); $expense2->setAmount(35); $expense2->setCurrency($this->getReference('currency-gbp')); $expense2->setDestination('London'); $travelExpense1->addUserPaidExpense($expense2); $trStatusApproved = $this->getReference('travel-request-status-approved'); $expense3 = new TECompanyPaidExpense(); $expense3->setDescription('Westpoint Hotel'); $expense3->setDate($trStatusApproved->getCreated()); $expense3->setExpenseType($this->getReference('expense-type-hotel')); $expense3->setAmount(753); $expense3->setCurrency($this->getReference('currency-gbp')); $expense3->setDestination('London'); $travelExpense1->addCompanyPaidExpense($expense3); } if ($this->hasReference('currency-huf') && $this->hasReference('expense-type-tickets')) { $expense4 = new TECompanyPaidExpense(); $expense4->setDescription('Flight tickets'); $expense4->setDate($trStatusApproved->getCreated()); $expense4->setExpenseType($this->getReference('expense-type-tickets')); $expense4->setAmount(112500); $expense4->setCurrency($this->getReference('currency-huf')); $expense4->setDestination('London'); $travelExpense1->addCompanyPaidExpense($expense4); } // Add travel expense states if ($this->hasReference('user') && $this->hasReference('created')) { $travelRequest1Status = new StatesTravelExpenses($this->getReference('created')); $travelRequest1Status->setCreatedUser($this->getReference('user')); $travelExpense1->addState($travelRequest1Status); } $travelExpense1->setTravelRequest($travelRequest); $manager->persist($travelExpense1); $manager->flush(); }