/**
  * Get once customer by the external ID.
  *
  * @param string $customerExternalUid The external customer ID.
  * @return Customer|null
  */
 public function getCustomerByExternalUid($customerExternalUid)
 {
     $requestData = new Get\RequestData();
     $requestData->setCustomerExternalUid($customerExternalUid);
     $customers = $this->getCustomers($requestData)->getResponse()->getCustomers();
     return isset($customers[0]) ? $customers[0] : null;
 }
 /**
  * Reset all customers including subscriptions, but not invoices.
  */
 protected function resetCustomers()
 {
     /** @var \Speicher210\Fastbill\Api\Service\Customer\CustomerService $customerService */
     $customerService = $this->getContainer()->get('speicher210_fastbill.service.customer');
     $requestData = new RequestData();
     $requestData->setCustomerId($this->input->getOption('id'));
     $requestData->setCustomerExternalUid($this->input->getOption('ext-id'));
     $apiResponse = $customerService->getCustomers($requestData);
     $customers = $apiResponse->getResponse()->getCustomers();
     $idsToSkip = $this->input->getOption('skip-id');
     $externalIdsToSkip = $this->input->getOption('skip-ext-id');
     if (count($customers) === 0) {
         $this->output->writeln('<info>No customers to reset.</info>');
         return;
     }
     foreach ($customers as $customer) {
         if (in_array($customer->getCustomerId(), $idsToSkip) || in_array($customer->getCustomerExternalUid(), $externalIdsToSkip)) {
             $infoMsg = sprintf('<info>Skipping resetting customer %s (ext. id: %s)</info>', $customer->getCustomerId(), $customer->getCustomerExternalUid());
             $this->output->writeln($infoMsg);
             continue;
         }
         $infoMsg = sprintf('<info>Deleting customer %s (ext. id: %s)</info>', $customer->getCustomerId(), $customer->getCustomerExternalUid());
         $this->output->writeln($infoMsg);
         $customerService->deleteCustomer($customer->getCustomerId());
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Speicher210\Fastbill\Api\Service\Customer\CustomerService $customerService */
     $customerService = $this->getContainer()->get('speicher210_fastbill.service.customer');
     $requestData = new RequestData();
     $requestData->setCustomerId($input->getOption('id'));
     $requestData->setCustomerExternalUid($input->getOption('ext-id'));
     $apiResponse = $customerService->getCustomers($requestData);
     $customers = $apiResponse->getResponse()->getCustomers();
     $table = new Table($output);
     $table->setHeaders(array('ID', 'External ID', 'Create data', 'Name', 'Organization', 'Email', 'Phone', 'Comment', 'Last update'));
     foreach ($customers as $customer) {
         $table->addRow(array($customer->getCustomerId(), $customer->getCustomerExternalUid(), $customer->getCreated() ? $customer->getCreated()->format(\DateTime::W3C) : null, $customer->getFirstName() . ' ' . $customer->getLastName(), $customer->getOrganization(), $customer->getEmail(), $customer->getPhone(), $customer->getComment(), $customer->getLastUpdate() ? $customer->getLastUpdate()->format(\DateTime::W3C) : null));
     }
     $table->render();
 }