/** * @return bool|TblStudent */ public function getServiceManagementStudent() { if (null === $this->serviceManagement_Student) { return false; } else { return Management::serviceStudent()->entityStudentByNumber($this->serviceManagement_Student); //todo } }
/** * @param TblBasket $tblBasket * @param $Date * * @return bool */ public function actionCreateInvoiceListFromBasket(TblBasket $tblBasket, $Date) { $Manager = $this->Connection->getEntityManager(); $tblTempInvoiceList = $this->entityTempInvoiceAllByBasket($tblBasket); /**@var TblTempInvoice $tblTempInvoice */ foreach ($tblTempInvoiceList as $tblTempInvoice) { $tblDebtor = $tblTempInvoice->getServiceBillingDebtor(); $tblPersonDebtor = Management::servicePerson()->entityPersonById($tblDebtor->getServiceManagementPerson()); $tblPerson = $tblTempInvoice->getServiceManagementPerson(); $Entity = new TblInvoice(); $Entity->setIsPaid(false); $Entity->setIsVoid(false); $Entity->setNumber("40000000"); $Entity->setBasketName($tblBasket->getName()); $Entity->setServiceBillingBankingPaymentType($tblDebtor->getPaymentType()); $leadTimeByDebtor = Banking::useService()->entityLeadTimeByDebtor($tblDebtor); $invoiceDate = (new \DateTime($Date))->sub(new \DateInterval('P' . $leadTimeByDebtor . 'D')); $now = new \DateTime(); if ($invoiceDate->format('y.m.d') >= $now->format('y.m.d')) { $Entity->setInvoiceDate($invoiceDate); $Entity->setPaymentDate(new \DateTime($Date)); $Entity->setIsPaymentDateModified(false); } else { $Entity->setInvoiceDate(new \DateTime('now')); $Entity->setPaymentDate($now->add(new \DateInterval('P' . $leadTimeByDebtor . 'D'))); $Entity->setIsPaymentDateModified(true); } $Entity->setDiscount(0); $Entity->setDebtorFirstName($tblPersonDebtor->getFirstName()); $Entity->setDebtorLastName($tblPersonDebtor->getLastName()); $Entity->setDebtorSalutation($tblPersonDebtor->getTblPersonSalutation()->getName()); $Entity->setDebtorNumber($tblDebtor->getDebtorNumber()); $Entity->setServiceManagementPerson($tblPerson); if ($address = Management::servicePerson()->entityAddressAllByPerson($tblPersonDebtor)) { // TODO address type invoice $Entity->setServiceManagementAddress($address[0]); } $Manager->saveEntity($Entity); $Entity->setNumber((int) $Entity->getNumber() + $Entity->getId()); $Manager->saveEntity($Entity); Protocol::useService()->createInsertEntry($this->Connection->getDatabase(), $Entity); $tblTempInvoiceCommodityList = $this->entityTempInvoiceCommodityAllByTempInvoice($tblTempInvoice); foreach ($tblTempInvoiceCommodityList as $tblTempInvoiceCommodity) { $tblCommodity = $tblTempInvoiceCommodity->getServiceBillingCommodity(); $tblBasketItemAllByBasketAndCommodity = Basket::useService()->entityBasketItemAllByBasketAndCommodity($tblBasket, $tblCommodity); /**@var TblBasketItem $tblBasketItem */ foreach ($tblBasketItemAllByBasketAndCommodity as $tblBasketItem) { $tblItem = $tblBasketItem->getServiceBillingCommodityItem()->getTblItem(); if (!$tblItem->getServiceManagementCourse() && !$tblItem->getServiceManagementStudentChildRank()) { $this->actionCreateInvoiceItem($tblCommodity, $tblItem, $tblBasket, $tblBasketItem, $Entity); } else { if ($tblItem->getServiceManagementCourse() && !$tblItem->getServiceManagementStudentChildRank()) { if (($tblStudent = Management::serviceStudent()->entityStudentByPerson($tblPerson)) && $tblItem->getServiceManagementCourse()->getId() == $tblStudent->getServiceManagementCourse()->getId()) { $this->actionCreateInvoiceItem($tblCommodity, $tblItem, $tblBasket, $tblBasketItem, $Entity); } } else { if (!$tblItem->getServiceManagementCourse() && $tblItem->getServiceManagementStudentChildRank()) { if (($tblStudent = Management::serviceStudent()->entityStudentByPerson($tblPerson)) && $tblItem->getServiceManagementStudentChildRank()->getId() == $tblStudent->getTblChildRank()->getId()) { $this->actionCreateInvoiceItem($tblCommodity, $tblItem, $tblBasket, $tblBasketItem, $Entity); } } else { if ($tblItem->getServiceManagementCourse() && $tblItem->getServiceManagementStudentChildRank()) { if (($tblStudent = Management::serviceStudent()->entityStudentByPerson($tblPerson)) && $tblItem->getServiceManagementCourse()->getId() == $tblStudent->getServiceManagementCourse()->getId() && $tblItem->getServiceManagementStudentChildRank()->getId() == $tblStudent->getTblChildRank()->getId()) { $this->actionCreateInvoiceItem($tblCommodity, $tblItem, $tblBasket, $tblBasketItem, $Entity); } } } } } } } } return true; }
/** * @return bool|TblChildRank */ public function getServiceManagementStudentChildRank() { if (null === $this->serviceManagement_Student_ChildRank) { return false; } else { return Management::serviceStudent()->entityChildRankById($this->serviceManagement_Student_ChildRank); // todo } }