1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Speicher210\FastbillBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6
|
|
|
use Symfony\Component\Console\Helper\Table; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Command for listing customers. |
13
|
|
|
*/ |
14
|
|
|
class SubscriptionCommand extends ContainerAwareCommand |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* {@inheritdoc} |
18
|
|
|
*/ |
19
|
|
|
protected function configure() |
20
|
|
|
{ |
21
|
|
|
$this |
22
|
|
|
->setName('sp210:fastbill:subscription') |
23
|
|
|
->setDescription('List information about the subscriptions.') |
24
|
|
|
->addOption('customer-id', null, InputOption::VALUE_REQUIRED, 'Optional Fastbill customer ID') |
25
|
|
|
->addOption('customer-ext-id', null, InputOption::VALUE_REQUIRED, 'Optional customer external ID') |
26
|
|
|
->addOption('subscription-id', null, InputOption::VALUE_REQUIRED, 'Optional subscription ID') |
27
|
|
|
->addOption('subscription-ext-id', null, InputOption::VALUE_REQUIRED, 'Optional subscription external ID'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
34
|
|
|
{ |
35
|
|
|
/** @var \Speicher210\Fastbill\Api\Service\Subscription\SubscriptionService $subscriptionService */ |
36
|
|
|
$subscriptionService = $this->getContainer()->get('speicher210_fastbill.service.subscription'); |
37
|
|
|
|
38
|
|
|
$apiResponse = $subscriptionService->getSubscriptions( |
39
|
|
|
$input->getOption('customer-id'), |
40
|
|
|
$input->getOption('customer-ext-id'), |
41
|
|
|
$input->getOption('subscription-ext-id'), |
42
|
|
|
$input->getOption('subscription-id') |
43
|
|
|
); |
44
|
|
|
$subscriptions = $apiResponse->getResponse()->getSubscriptions(); |
45
|
|
|
|
46
|
|
|
$table = new Table($output); |
47
|
|
|
$table->setHeaders( |
48
|
|
|
array( |
49
|
|
|
'ID', |
50
|
|
|
'External ID', |
51
|
|
|
'Start data', |
52
|
|
|
'Expiration date', |
53
|
|
|
'Next event', |
54
|
|
|
'Status', |
55
|
|
|
'Article number', |
56
|
|
|
'Customer ID', |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
foreach ($subscriptions as $subscription) { |
61
|
|
|
$table->addRow( |
62
|
|
|
array( |
63
|
|
|
$subscription->getSubscriptionId(), |
64
|
|
|
$subscription->getSubscriptionExternalId(), |
65
|
|
|
$subscription->getSubscriptionStart()->format(\DateTime::W3C), |
66
|
|
|
$subscription->getExpirationDate()->format(\DateTime::W3C), |
67
|
|
|
$subscription->getNextEvent() ? $subscription->getNextEvent()->format(\DateTime::W3C) : null, |
68
|
|
|
$subscription->getStatus(), |
69
|
|
|
$subscription->getArticleNumber(), |
70
|
|
|
$subscription->getCustomerId(), |
71
|
|
|
) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$table->render(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|