|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiBundle\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Speicher210\Fastbill\Api\Service\Customer\Get\RequestData; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
|
7
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Command for listing customers. |
|
14
|
|
|
*/ |
|
15
|
|
|
class CustomerCommand extends ContainerAwareCommand |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritdoc} |
|
19
|
|
|
*/ |
|
20
|
|
|
protected function configure() |
|
21
|
|
|
{ |
|
22
|
|
|
$this |
|
23
|
|
|
->setName('sp210:fastbill:customer') |
|
24
|
|
|
->setDescription('List information about the customers.') |
|
25
|
|
|
->addOption('id', null, InputOption::VALUE_REQUIRED, 'Optional Fastbill customer ID') |
|
26
|
|
|
->addOption('ext-id', null, InputOption::VALUE_REQUIRED, 'Optional external ID'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
33
|
|
|
{ |
|
34
|
|
|
/** @var \Speicher210\Fastbill\Api\Service\Customer\CustomerService $customerService */ |
|
35
|
|
|
$customerService = $this->getContainer()->get('speicher210_fastbill.service.customer'); |
|
36
|
|
|
|
|
37
|
|
|
$requestData = new RequestData(); |
|
38
|
|
|
$requestData->setCustomerId($input->getOption('id')); |
|
39
|
|
|
$requestData->setCustomerExternalUid($input->getOption('ext-id')); |
|
40
|
|
|
$apiResponse = $customerService->getCustomers($requestData); |
|
41
|
|
|
$customers = $apiResponse->getResponse()->getCustomers(); |
|
42
|
|
|
|
|
43
|
|
|
$table = new Table($output); |
|
44
|
|
|
$table->setHeaders( |
|
45
|
|
|
array( |
|
46
|
|
|
'ID', |
|
47
|
|
|
'External ID', |
|
48
|
|
|
'Create data', |
|
49
|
|
|
'Name', |
|
50
|
|
|
'Organization', |
|
51
|
|
|
'Email', |
|
52
|
|
|
'Phone', |
|
53
|
|
|
'Comment', |
|
54
|
|
|
'Last update', |
|
55
|
|
|
) |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
foreach ($customers as $customer) { |
|
59
|
|
|
$table->addRow( |
|
60
|
|
|
array( |
|
61
|
|
|
$customer->getCustomerId(), |
|
62
|
|
|
$customer->getCustomerExternalUid(), |
|
63
|
|
|
$customer->getCreated() ? $customer->getCreated()->format(\DateTime::W3C) : null, |
|
64
|
|
|
$customer->getFirstName().' '.$customer->getLastName(), |
|
65
|
|
|
$customer->getOrganization(), |
|
66
|
|
|
$customer->getEmail(), |
|
67
|
|
|
$customer->getPhone(), |
|
68
|
|
|
$customer->getComment(), |
|
69
|
|
|
$customer->getLastUpdate() ? $customer->getLastUpdate()->format(\DateTime::W3C) : null, |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$table->render(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|