/** * @return bool|TblInvoice */ public function getServiceBillingInvoice() { if (null === $this->serviceBilling_Invoice) { return false; } else { return Invoice::useService()->entityInvoiceById($this->serviceBilling_Invoice); } }
/** * @return bool|TblTempInvoice */ public function getTblTempInvoice() { if (null === $this->tblTempInvoice) { return false; } else { return Invoice::useService()->entityTempInvoiceById($this->tblTempInvoice); } }
/** * @return bool|TblInvoice[] */ public function entityInvoiceHasFullPaymentAll() { $invoiceHasFullPaymentAll = array(); $balanceAll = $this->entityBalanceAll(); if ($balanceAll) { foreach ($balanceAll as $balance) { $invoice = $balance->getServiceBillingInvoice(); $sumInvoicePrice = Invoice::useService()->sumPriceItemAllByInvoice($invoice); $sumPaymentPrice = $this->sumPriceItemByBalance($balance); $sumInvoicePrice = round($sumInvoicePrice, 2); $sumPaymentPrice = round($sumPaymentPrice, 2); if ($sumInvoicePrice <= $sumPaymentPrice) { $invoiceHasFullPaymentAll[] = $invoice; } } } return empty($invoiceHasFullPaymentAll) ? false : $invoiceHasFullPaymentAll; }
/** * @return Stage */ public function frontendBalance() { $Stage = new Stage(); $Stage->setTitle('Posten'); $Stage->setDescription('Offen'); $invoiceAllByIsConfirmedState = Invoice::useService()->entityInvoiceAllByIsConfirmedState(true); $invoiceAllByIsVoidState = Invoice::useService()->entityInvoiceAllByIsVoidState(true); $invoiceAllByIsPaidState = Invoice::useService()->entityInvoiceAllByIsPaidState(true); $invoiceHasFullPaymentAll = Balance::useService()->entityInvoiceHasFullPaymentAll(); if ($invoiceAllByIsConfirmedState && $invoiceAllByIsVoidState) { $invoiceAllByIsConfirmedState = array_udiff($invoiceAllByIsConfirmedState, $invoiceAllByIsVoidState, function (TblInvoice $invoiceA, TblInvoice $invoiceB) { return $invoiceA->getId() - $invoiceB->getId(); }); } if ($invoiceAllByIsConfirmedState && $invoiceAllByIsPaidState) { $invoiceAllByIsConfirmedState = array_udiff($invoiceAllByIsConfirmedState, $invoiceAllByIsPaidState, function (TblInvoice $invoiceA, TblInvoice $invoiceB) { return $invoiceA->getId() - $invoiceB->getId(); }); } if ($invoiceAllByIsConfirmedState && $invoiceHasFullPaymentAll) { $invoiceAllByIsConfirmedState = array_udiff($invoiceAllByIsConfirmedState, $invoiceHasFullPaymentAll, function (TblInvoice $invoiceA, TblInvoice $invoiceB) { return $invoiceA->getId() - $invoiceB->getId(); }); } if (!empty($invoiceAllByIsConfirmedState)) { /** @var TblInvoice $invoiceByIsConfirmedState */ foreach ($invoiceAllByIsConfirmedState as $invoiceByIsConfirmedState) { $tblBalance = Balance::useService()->entityBalanceByInvoice($invoiceByIsConfirmedState); $AdditionInvoice = Invoice::useService()->sumPriceItemAllStringByInvoice($invoiceByIsConfirmedState); $AdditionPayment = Balance::useService()->sumPriceItemStringByBalance($tblBalance); $invoiceByIsConfirmedState->FullName = $invoiceByIsConfirmedState->getDebtorFullName(); $invoiceByIsConfirmedState->PaidPayment = $AdditionPayment; $invoiceByIsConfirmedState->PaidInvoice = $AdditionInvoice; $invoiceByIsConfirmedState->Option = new Primary('Bezahlt', '/Billing/Bookkeeping/Invoice/Pay', new Ok(), array('Id' => $invoiceByIsConfirmedState->getId())); } } $Stage->setContent(new TableData($invoiceAllByIsConfirmedState, null, array('Number' => 'Nummer', 'InvoiceDate' => 'Rechnungsdatum', 'PaymentDate' => 'Zahlungsdatum', 'FullName' => 'Debitor', 'DebtorNumber' => 'Debitorennummer', 'PaidPayment' => 'Bezahlt', 'PaidInvoice' => 'Gesamt', 'Option' => 'Option'))); return $Stage; }
/** * @param IFormInterface $Stage * @param $Id * @param $Date * @param $Data * @param $Save * * @return IFormInterface|string */ public function executeCheckDebtors(IFormInterface &$Stage = null, $Id, $Date, $Data, $Save) { /** * Skip to Frontend */ if (null === $Data && null === $Save) { return $Stage; } $isSave = $Save == 2; $tblBasket = Basket::useService()->entityBasketById($Id); if ((new Data($this->Binding))->checkDebtors($tblBasket, $Data, $isSave)) { if (Invoice::useService()->executeCreateInvoiceListFromBasket($tblBasket, $Date)) { $Stage .= new Success('Die Rechnungen wurden erfolgreich erstellt') . new Redirect('/Billing/Bookkeeping/Invoice/IsNotConfirmed', 2); } else { $Stage .= new Success('Die Rechnungen konnten nicht erstellt werden') . new Redirect('/Billing/Accounting/Basket', 2); } } return $Stage; }
/** * @param $Id * * @return Stage */ public function frontendInvoiceItemRemove($Id) { $Stage = new Stage(); $Stage->setTitle('Rechnung'); $Stage->setDescription('Artikel Entfernen'); $tblInvoiceItem = Invoice::useService()->entityInvoiceItemById($Id); $Stage->setContent(Invoice::useService()->executeRemoveInvoiceItem($tblInvoiceItem)); return $Stage; }
/** * @param TblDebtor $tblDebtor * * @return int */ public function entityLeadTimeByDebtor(TblDebtor $tblDebtor) { if (Invoice::useService()->checkInvoiceFromDebtorIsPaidByDebtor($tblDebtor) || Balance::useService()->checkPaymentFromDebtorExistsByDebtor($tblDebtor)) { return $tblDebtor->getLeadTimeFollow(); } else { return $tblDebtor->getLeadTimeFirst(); } }
/** * @param TblBasket $tblBasket * @param $Data * @param $IsSave * * @return bool */ public function checkDebtors(TblBasket $tblBasket, $Data, $IsSave = false) { if ($Data !== null) { foreach ($Data as $Key => $Value) { $tblBasketCommodity = $this->entityBasketCommodityById($Key); $tblBasketCommodityDebtor = $this->entityBasketCommodityDebtorById($Value); $tblTempInvoice = Invoice::useService()->executeCreateTempInvoice($tblBasket, $tblBasketCommodity->getServiceManagementPerson(), $tblBasketCommodityDebtor->getServiceBillingDebtor()); Invoice::useService()->executeCreateTempInvoiceCommodity($tblTempInvoice, $tblBasketCommodity->getServiceBillingCommodity()); // auto add DebtorCommodity if ($IsSave) { Banking::useService()->executeAddDebtorCommodity($tblBasketCommodityDebtor->getServiceBillingDebtor(), $tblBasketCommodity->getServiceBillingCommodity()); } } return true; } $tblCommodityAllByBasket = Basket::useService()->entityCommodityAllByBasket($tblBasket); $tblBasketPersonAllByBasket = Basket::useService()->entityBasketPersonAllByBasket($tblBasket); if (!empty($tblBasketPersonAllByBasket)) { /** @var TblBasketPerson $tblBasketPerson */ foreach ($tblBasketPersonAllByBasket as $tblBasketPerson) { $tblPerson = $tblBasketPerson->getServiceManagementPerson(); foreach ($tblCommodityAllByBasket as $tblCommodity) { /** @var TblDebtorCommodity[] $tblDebtorCommodityListByPersonAndCommodity */ $tblDebtorCommodityListByPersonAndCommodity = array(); /** @var TblDebtor[] $tblDebtorListByPerson */ $tblDebtorListByPerson = array(); $debtorPersonAll = Banking::useService()->entityDebtorAllByPerson($tblPerson); if (!empty($debtorPersonAll)) { foreach ($debtorPersonAll as $tblDebtor) { $tblDebtorCommodityList = Banking::useService()->entityDebtorCommodityAllByDebtorAndCommodity($tblDebtor, $tblCommodity); if (!empty($tblDebtorCommodityList)) { foreach ($tblDebtorCommodityList as $tblDebtorCommodity) { $tblDebtorCommodityListByPersonAndCommodity[] = $tblDebtorCommodity; } } $tblDebtorListByPerson[] = $tblDebtor; } } $tblPersonRelationshipList = Management::servicePerson()->entityPersonRelationshipAllByPerson($tblPerson); if (!empty($tblPersonRelationshipList)) { foreach ($tblPersonRelationshipList as $tblPersonRelationship) { if ($tblPerson->getId() === $tblPersonRelationship->getTblPersonA()->getId()) { $tblDebtorList = Banking::useService()->entityDebtorAllByPerson($tblPersonRelationship->getTblPersonB()); } else { $tblDebtorList = Banking::useService()->entityDebtorAllByPerson($tblPersonRelationship->getTblPersonA()); } if (!empty($tblDebtorList)) { foreach ($tblDebtorList as $tblDebtor) { $tblDebtorCommodityList = Banking::useService()->entityDebtorCommodityAllByDebtorAndCommodity($tblDebtor, $tblCommodity); if (!empty($tblDebtorCommodityList)) { foreach ($tblDebtorCommodityList as $tblDebtorCommodity) { $tblDebtorCommodityListByPersonAndCommodity[] = $tblDebtorCommodity; } } $tblDebtorListByPerson[] = $tblDebtor; } } } } if (count($tblDebtorListByPerson) == 1) { $tblDebtor = Banking::useService()->entityDebtorById($tblDebtorListByPerson[0]->getId()); $tblTempInvoice = Invoice::useService()->executeCreateTempInvoice($tblBasket, $tblPerson, $tblDebtor); Invoice::useService()->executeCreateTempInvoiceCommodity($tblTempInvoice, $tblCommodity); } else { if (empty($tblDebtorCommodityListByPersonAndCommodity)) { $tblBasketCommodity = $this->actionCreateBasketCommodity($tblBasket, $tblPerson, $tblCommodity); foreach ($tblDebtorListByPerson as $tblDebtor) { $this->actionCreateBasketCommodityDebtor($tblBasketCommodity, $tblDebtor); } } else { if (count($tblDebtorCommodityListByPersonAndCommodity) == 1) { $tblDebtor = Banking::useService()->entityDebtorById($tblDebtorCommodityListByPersonAndCommodity[0]->getId()); $tblTempInvoice = Invoice::useService()->executeCreateTempInvoice($tblBasket, $tblPerson, $tblDebtor); Invoice::useService()->executeCreateTempInvoiceCommodity($tblTempInvoice, $tblCommodity); } else { $tblBasketCommodity = $this->actionCreateBasketCommodity($tblBasket, $tblPerson, $tblCommodity); foreach ($tblDebtorCommodityListByPersonAndCommodity as $tblDebtorCommodity) { $this->actionCreateBasketCommodityDebtor($tblBasketCommodity, $tblDebtorCommodity->getTblDebtor()); } } } } } } } $tblBasketCommodity = $this->entityBasketCommodityAllByBasket($tblBasket); return empty($tblBasketCommodity); }