Remove invoiceAsVendor

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

@param  \HarvestCloud\CoreBundle\Entity\Invoice\Invoice $invoiceAsVendor
777789
public function removeInvoiceAsVendor(\HarvestCloud\CoreBundle\Entity\Invoice\Invoice $invoiceAsVendor)
    {
        $this->invoicesAsVendor->removeElement($invoiceAsVendor);
    }
43609
private function processInvoices(array $invoices, DateTime $cycleDate)
    {

        $operations = array();

        foreach ($invoices as $invoice) {

            $this->logger->debug(
                "ShopId : " . $invoice['shop_id'],
                array('miraklId' => $invoice['shop_id'], "action" => "Operations creation")
            );

            $vendor = $this->vendorManager->findByMiraklId($invoice['shop_id']);

            if (!$this->vendorEnabled($vendor)) {
                $this->logger->info(
                    "Operation wasn't created because vendor doesn't exit in database or vendor is disabled " .
                    " (verify HiPay process value in Mirakl BO)",
                    array('miraklId' => $invoice['shop_id'], "action" => "Operations creation")
                );
            } else {
                $operationsFromInvoice = $this->createOperationsFromInvoice($invoice, $vendor, $cycleDate);
                if ($operationsFromInvoice) {
                    $operations = array_merge($operations, $operationsFromInvoice);
                } else {
                    //something went wrong
                    $title = "The operations for invoice n° " . $invoice['invoice_id'] . " are wrong";
                    $message = $this->formatNotification->formatMessage($title);
                    $this->logger->error($message, array('miraklId' => null, "action" => "Operations creation"));
                }
            }
        }

        return $operations;
    }
1327939
public function onDeleteVendor($vendor)
    {
        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $vendorId = $vendor->getId();
        $database->execute("delete from oxseo where oxobjectid = ? and oxtype = 'oxvendor'", [$vendorId]);
        $database->execute("delete from oxobject2seodata where oxobjectid = ?", [$vendorId]);
        $database->execute("delete from oxseohistory where oxobjectid = ?", [$vendorId]);
    }
910467
public function setInvoice(\Core\Entity\Invoice $invoice = null) {
        $this->invoice = $invoice;

        return $this;
    }
117488
public function settle(IncomingInvoice $invoiceA, IncomingInvoice $invoiceB)
    {
        return $this->connector->settle($invoiceA, $invoiceB);
    }
560067
public function findByInvoiceId($invoiceId)
    {
        $result = $this->connection()->get($this->getEndpoint() . '/find_by_invoice_id/' . urlencode($invoiceId));

        return $this->makeFromResponse($result);
    }
1313703
protected function triggerInvoiceCreated(array &$invoice, Source $invoiceSource, Result $localResult)
    {
	    $route = 'model/' . Registry::getInstance()->getLocation() . '/invoiceCreated/after';
        $args = array('invoice' => &$invoice, 'source' => $invoiceSource, 'localResult' => $localResult);
	    $this->getEvent()->trigger($route, array(&$route, $args));
    }
30600
public function sendPurchaseNotification($invoice)
    {
        $templateName = 'PaymentBundle:Email:sale.notification.admin.html.twig';

        if($invoice->getTransaction()->getItems()->first()->getProduct() instanceof Product){
            $product = $invoice->getTransaction()->getItems()->first()->getProduct();
        }
        
        $sellerEmails = array();
        if($invoice->getTransaction()->getItems()->first()->getProduct()->getActor() instanceof Actor){
            $sellerEmails[] = $invoice->getTransaction()->getItems()->first()->getProduct()->getActor()->getEmail();
        } 
            
        $context = array(
            'order_number'    => $invoice->getTransaction()->getTransactionKey(),
            'invoice_date'      => $invoice->getCreated(),
            'user_email'        => $invoice->getTransaction()->getActor()->getEmail(),
            'seller_email'        => implode(',', $sellerEmails),
            'order_details_url' => $this->router->generate('payment_checkout_showinvoice', array('number' => $invoice->getInvoiceNumber()), UrlGeneratorInterface::ABSOLUTE_URL),
        );

        $this->sendMessage($templateName, $context, $this->twigGlobal->getParameter('admin_email'), $this->twigGlobal->getParameter('admin_email'));
    }
841793
public function setInvoiceTable(\AgentSIB\Diadoc\Api\Proto\Invoicing\InvoiceTable $value = null)
    {
        $this->InvoiceTable = $value;
    }
88755
public function invoiceAddress($invNo)
    {
        $this->_checkInvNo($invNo);

        $digestSecret = self::digest(
            $this->colon($this->_eid, $invNo, $this->_secret)
        );
        $paramList = array(
            $this->_eid,
            $invNo,
            $digestSecret
        );

        self::printDebug('invoice_address', $paramList);

        $result = $this->xmlrpc_call('invoice_address', $paramList);

        $addr = new KlarnaAddr();
        if (strlen($result[0]) > 0) {
            $addr->isCompany = false;
            $addr->setFirstName($result[0]);
            $addr->setLastName($result[1]);
        } else {
            $addr->isCompany = true;
            $addr->setCompanyName($result[1]);
        }
        $addr->setStreet($result[2]);
        $addr->setZipCode($result[3]);
        $addr->setCity($result[4]);
        $addr->setCountry($result[5]);

        return $addr;
    }
935456
public function removeProductSubscriptionsAsBuyer(\HarvestCloud\CoreBundle\Entity\ProductSubscription $productSubscription)
    {
        $this->productSubscriptionsAsBuyer->removeElement($productSubscription);
    }
252722
public function removeSubscriber(\Enhavo\Bundle\NewsletterBundle\Entity\Subscriber $subscriber)
    {
        $this->subscriber->removeElement($subscriber);
    }
91565
public function deleteResult($deliveryResultIdentifier)
    {
        // remove variables
        $sql = 'DELETE FROM ' . self::VARIABLES_TABLENAME . '
            WHERE ' . self::VARIABLES_FK_COLUMN . ' = ?';

        if ($this->getPersistence()->exec($sql, array($deliveryResultIdentifier)) === false) {
            return false;
        }

        // remove results
        $sql = 'DELETE FROM ' . self::RESULTS_TABLENAME . '
            WHERE ' . self::RESULTS_TABLE_ID . ' = ?';

        if ($this->getPersistence()->exec($sql, array($deliveryResultIdentifier)) === false) {
            return false;
        }

        return true;
    }
515389
public function removeJournal(\HarvestCloud\CoreBundle\Entity\PaymentJournal $journal)
    {
        $this->journals->removeElement($journal);
    }
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);
    }
543507
public function getSoftDescriptor(\TdbShopOrder $order, $invoiceNumber = null)
    {
        $text = $this->getValue('softDescriptor');
        $data = $this->getTemplateDataFromOrder($order);
        $data['invoiceNumber'] = $invoiceNumber;

        return mb_substr($this->render($text, $data), 0, 16);
    }
1354745
public function delete()
    {
        if (!userHasPermission('admin:invoice:customer:delete')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oUri           = Factory::service('Uri');
        $oCustomerModel = Factory::model('Customer', 'nails/module-invoice');
        $oCustomer      = $oCustomerModel->getById(
            $oUri->segment(5),
            ['expand' => ['invoices']]
        );
        if (!$oCustomer) {
            show404();
        }

        if ($oCustomer->invoices->count) {

            $sStatus  = 'error';
            $sMessage = 'Cannot delete a customer who has invoices.';

        } else {

            if ($oCustomerModel->delete($oCustomer->id)) {

                $sStatus  = 'success';
                $sMessage = 'Invoice deleted successfully!';

            } else {

                $sStatus  = 'error';
                $sMessage = 'Invoice failed to delete. ' . $this->oInvoiceModel->lastError();
            }
        }

        $oSession = Factory::service('Session', 'nails/module-auth');
        $oSession->setFlashData($sStatus, $sMessage);
        redirect('admin/invoice/customer/index');
    }