Set invoice

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2013-03-24

@param  \HarvestCloud\CoreBundle\Entity\Invoice\Invoice $invoice

@return InvoicePaymentLineItem
516784
public function setInvoice(\HarvestCloud\CoreBundle\Entity\Invoice\Invoice $invoice = null)
    {
        $this->invoice = $invoice;

        return $this;
    }
1335800
public function unit($invoiceLineHandle, $unit)
    {
        $units      = new Unit($this->client_raw);
        $unitHandle = $units->getHandle($unit);

        $this->client
            ->CurrentInvoiceLine_SetUnit(
                array(
                    'currentInvoiceLineHandle' => $invoiceLineHandle,
                    'valueHandle'              => $unitHandle
                )
            );

        return true;
    }
507103
public function registerPayment(SalesInvoicePayment $salesInvoicePayment)
    {
        if (! isset($salesInvoicePayment->payment_date)) {
            throw new ApiException('Required [payment_date] is missing');
        }

        if (! isset($salesInvoicePayment->price)) {
            throw new ApiException('Required [price] is missing');
        }

        $this->connection()->post($this->endpoint . '/' . $this->id . '/payments',
            $salesInvoicePayment->jsonWithNamespace()
        );

        return $this;
    }
777789
public function removeInvoiceAsVendor(\HarvestCloud\CoreBundle\Entity\Invoice\Invoice $invoiceAsVendor)
    {
        $this->invoicesAsVendor->removeElement($invoiceAsVendor);
    }
585743
public function update(int $invoice, array $data)
    {
        $response = $this->httpPut('/3/invoices/'.$invoice, ['Invoice' => $data]);

        if (!$this->hydrator) {
            return $response;
        }

        // Use any valid status code here
        if (200 !== $response->getStatusCode()) {
            $this->handleErrors($response);
        }

        return $this->hydrator->hydrate($response, Model::class);
    }
144697
public function setNextInvoiceDate($date)
    {
        $date = DateTime::createFromFormat('Y-m-d', $date);

        $this->next_invoice_date = new stdClass();
        $this->next_invoice_date->day = $date->format('d');
        $this->next_invoice_date->month = $date->format('m');
        $this->next_invoice_date->year = $date->format('Y');

        return $this;
    }
472924
public function writeOff()
    {
        if (!empty($this->iId)) {
            $oInvoiceModel = Factory::model('Invoice', 'nails/module-invoice');
            if (!$oInvoiceModel->setWrittenOff($this->iId)) {
                throw new InvoiceException('Failed to write off invoice.');
            }
        }

        return $this;
    }
560067
public function findByInvoiceId($invoiceId)
    {
        $result = $this->connection()->get($this->getEndpoint() . '/find_by_invoice_id/' . urlencode($invoiceId));

        return $this->makeFromResponse($result);
    }
625226
public function addJournal(\HarvestCloud\CoreBundle\Entity\InvoiceJournal $journal)
    {
        $this->journals[] = $journal;

        $journal->setInvoice($this);

        return $this;
    }
85588
public function remind(Invoice $invoice, InvoiceEnvelope $envelope)
    {
        $envelope->setData(array(
            'invoiceId' => $invoice->getId()
        ));

        $response = $this->request(
            $this->buildUrl($invoice, null, '/send_reminder'), 'PUT', $this->mapper->mapToStorage($envelope)
        );

        return $this->mapper->mapFromStorage($response);
    }
601558
public function removeInvoiceAsCustomer(\HarvestCloud\CoreBundle\Entity\Invoice\Invoice $invoiceAsCustomer)
    {
        $this->invoicesAsCustomer->removeElement($invoiceAsCustomer);
    }
590799
public static function generate(Invoice $invoice, $template = 'default')
    {
        $template = strtolower($template);

        $options = new Options();

        $options->set('isRemoteEnabled', true);

        $pdf = new Dompdf($options);

        $context = stream_context_create([
            'ssl' => [
                'verify_peer'      => false,
                'verify_peer_name' => false,
                'allow_self_signed'=> true,
            ],
        ]);

        $pdf->setHttpContext($context);

        $pdf->loadHtml(View::make('invoices::'.$template, ['invoice' => $invoice]));
        $pdf->render();

        return $pdf;
    }
1006601
protected function setInvoiceSource($invoiceSource)
    {
        $this->invoiceSource = $invoiceSource;
        if (!in_array($invoiceSource->getType(), array(Source::Order, Source::CreditNote))) {
            $this->log->error('Creator::setSource(): unknown source type %s', $this->invoiceSource->getType());
        };
    }
159066
public function setInvoice(\AgentSIB\Diadoc\Api\Proto\Recognition\RecognizedInvoice $value = null)
    {
        $this->Invoice = $value;
    }
465054
public function setOrderInvoice(\HarvestCloud\CoreBundle\Entity\Invoice\OrderInvoice $invoice = null)
    {
        $this->orderInvoice = $invoice;

        return $this;
    }
352094
public function odpocetZDD($invoice, $odpocet = [])
    {
        if (!isset($odpocet['castkaZaklMen'])) {
            $odpocet['castkaZaklMen'] = $invoice->getDataValue('sumZklZakl');
        }
        if (!isset($odpocet['castkaSnizMen'])) {
            $odpocet['castkaSnizMen'] = $invoice->getDataValue('sumZklSniz');
        }
        if (!isset($odpocet['castkaSniz2Men'])) {
            $odpocet['castkaSniz2Men'] = $invoice->getDataValue('sumZklSniz2');
        }
        if (!isset($odpocet['castkaOsvMen'])) {
            $odpocet['castkaOsvMen'] = $invoice->getDataValue('sumOsv');
        }
        if (!isset($odpocet['id'])) {
            $odpocet['id'] = 'ext:odpocet1';
        }
        $odpocet['doklad'] = $invoice;

        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
        $this->insertToFlexiBee();
        return $this->lastResponseCode == 201;
    }
138921
protected function sendInvoice($oInvoice)
    {
        if (empty($oInvoice)) {
            return false;
        }

        $sInvoiceClass = get_class($this->oInvoiceModel);

        if ($oInvoice->state->id !== $sInvoiceClass::STATE_OPEN) {
            return false;
        }

        $oNow   = Factory::factory('DateTime');
        $oDated = new \DateTime($oInvoice->dated->raw);

        if ($oNow->format('Y-m-d') != $oDated->format('Y-m-d')) {
            return false;
        }

        return $this->oInvoiceModel->send($oInvoice->id);
    }