Skip to content

Commit 3203893

Browse files
committed
#35 - refactored system for non unique transactionId
1 parent 8252f81 commit 3203893

10 files changed

Lines changed: 68 additions & 38 deletions

File tree

app/Resources/views/transactions/detail.html.twig

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
{% block content %}
66
<h2>Transaction Details</h2>
7+
{% for transaction in transactions %}
78
<div class="aui-group">
89
<div class="aui-item">
910
<h3>{{ transaction.license.addon.addonName }}</h3>
@@ -69,18 +70,6 @@
6970
<td>{{ transaction.license.company.getCompanyTitleFixed() }}</td>
7071
</tr>
7172

72-
{# TODO: not sure how to handle this #}
73-
{#<tr>#}
74-
{#<td><h6>DISCOUNT</h6></td>#}
75-
{#<td>#}
76-
{#{% if sale.discounted == null %}#}
77-
{#No discount available#}
78-
{#{% else %}#}
79-
{#{{ sale.discounted }}#}
80-
{#{% endif %}#}
81-
{#</td>#}
82-
{#</tr>#}
83-
8473
<tr>
8574
<td><h6>PURCHASE PRICE</h6></td>
8675
<td>{{ transaction.purchasePrice }}</td>
@@ -90,5 +79,5 @@
9079
</table>
9180
</div>
9281
</div>
93-
82+
{% endfor %}
9483
{% endblock %}

src/AppBundle/Command/ImportLicenseCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9393
$output->writeln(sprintf('Imported %s licenses', count($licenses)));
9494

9595
$this->getContainer()->get("app.status")->importLicenseDone();
96+
$output->writeln("Command completed successfully");
9697
}
9798

9899
private function getLocalFile()

src/AppBundle/Command/ImportTransactionCommand.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080

8181
$output->writeln(sprintf('Imported %s transactions', $offset));
8282
$this->getContainer()->get("app.status")->importTransactionDone();
83+
$output->writeln("Command completed successfully");
8384
}
8485

8586

@@ -111,26 +112,27 @@ private function saveTransactions($jsonTransactions)
111112
$newCnt = 0;
112113

113114
foreach ($jsonTransactions as $jsonTransaction) {
114-
if ($transaction = $transactionRepository->findOneBy(["transactionId"=>$jsonTransaction['transactionId']])) {
115+
if($license = $licenseRepository->findOneBy(["addonLicenseId"=>$jsonTransaction["addonLicenseId"]])) {
116+
$this->locatedExistingLicense = true;
117+
// TODO: check if license info is changed
118+
} else {
119+
if($this->locatedExistingLicense) {
120+
// Something weird happens. We already located transaction with existing licence. So either transactions is incorrectly ordered, OR we have bug
121+
// TODO: set flag
122+
throw new \Exception("Lost license for transaction #".$jsonTransaction['transactionId']);
123+
}
124+
continue;
125+
}
126+
if ($transaction = $transactionRepository->findOneBy(["license"=>$license, "transactionId"=>$jsonTransaction['transactionId']])) {
115127
// TODO: check if transaction is changed.
116128
} else {
117129
$newCnt++;
118130
$transaction = new Transaction();
119131
$transaction->setTransactionId($jsonTransaction['transactionId']);
132+
$transaction->setLicense($license);
120133
$this->em->persist($transaction);
121134
$this->em->flush($transaction);
122-
if($license = $licenseRepository->findOneBy(["addonLicenseId"=>$jsonTransaction["addonLicenseId"]])) {
123-
$this->locatedExistingLicense = true;
124-
$transaction->setLicense($license);
125-
// TODO: check if license info is changed
126-
} else {
127-
if($this->locatedExistingLicense) {
128-
// Something weird happens. We already located transaction with existing licence. So either transactions is incorrectly ordered, OR we have bug
129-
// TODO: set flag
130-
throw new \Exception("Lost license for transaction #".$transaction->getTransactionId());
131-
}
132-
continue;
133-
}
135+
134136
Setter::set($jsonTransaction,$transaction,"transactionId");
135137
if(isset($jsonTransaction["customerDetails"]["company"])) {
136138
// Pretty weird, but Atlassian provide full company name in transactions list and brief company name for licenses list.

src/AppBundle/Controller/TransactionController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ public function indexAction(Request $request)
2828

2929
/**
3030
* @Route("/transaction/{transactionId}", name="transaction_detail")
31-
* @ParamConverter("transaction",class="AppBundle:Transaction")
3231
*/
33-
public function detailAction(Request $request, $transaction)
32+
public function detailAction(Request $request, $transactionId)
3433
{
3534
return $this->render(':transactions:detail.html.twig', [
36-
'transaction' => $transaction,
35+
'transactions' => $this->getDoctrine()->getRepository("AppBundle:Transaction")->findBy(["transactionId"=>$transactionId]),
3736
]);
3837
}
3938
}

src/AppBundle/DataFixtures/base.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ AppBundle\Entity\License:
9999
maintenanceStartDate: '<(new \DateTime("2016-11-01"))>'
100100
maintenanceEndDate: '<(new \DateTime("2016-12-21"))>'
101101
tier: Subscription
102+
License-6:
103+
addonLicenseId: '1111116'
104+
company: '@Company-3'
105+
addon: '@Addon-2'
106+
licenseType: EVALUATION
107+
maintenanceStartDate: '<(new \DateTime("2016-11-01"))>'
108+
maintenanceEndDate: '<(new \DateTime("2016-12-21"))>'
109+
tier: Subscription
102110
AppBundle\Entity\Transaction:
103111
Transaction-1:
104112
saleType: 1

src/AppBundle/Entity/Transaction.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
/**
88
* Transaction
99
*
10-
* @ORM\Table()
10+
* @ORM\Table(uniqueConstraints={
11+
* @ORM\UniqueConstraint(name="licence_transaction", columns={"transaction_id","license_id"})
12+
* })
1113
* @ORM\Entity(repositoryClass="AppBundle\Repository\TransactionRepository")
1214
*/
1315
class Transaction
@@ -56,7 +58,7 @@ class Transaction
5658
/**
5759
* @var string
5860
*
59-
* @ORM\Column(type="string", length=255, unique=true)
61+
* @ORM\Column(type="string", length=255)
6062
*/
6163
private $transactionId;
6264

src/AppBundle/Tests/Command/ImportLicenseCommandTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public function testExecute()
1919
$application->add(new ImportLicenseCommand());
2020
$licenseRepo = $this->getEntityManager()->getRepository("AppBundle:License");
2121
$companyRepo = $this->getEntityManager()->getRepository("AppBundle:Company");
22-
$this->assertEmpty($licenseRepo->findOneBy(["addonLicenseId"=>1111116]));
23-
$this->assertEmpty($companyRepo->findOneBy(["senId"=>"SEN-0000005"]));
22+
$this->assertEmpty($licenseRepo->findOneBy(["addonLicenseId"=>2111111]));
23+
$this->assertEmpty($companyRepo->findOneBy(["senId"=>"SEN-2000000"]));
2424

2525
$this->assertNotEmpty($fixturesLicense = $licenseRepo->findOneBy(["addonLicenseId"=>1111111]));
2626
$this->assertNotEmpty($fixturesLicenseCompany = $fixturesLicense->getCompany());
@@ -38,6 +38,8 @@ public function testExecute()
3838
]);
3939
$this->getEntityManager()->clear();
4040

41+
$this->assertContains("Command completed successfully",$commandTester->getDisplay());
42+
4143
// check fixtures license without contact info update
4244
$this->assertNotEmpty($existingLicense = $licenseRepo->findOneBy(["addonLicenseId"=>1111111]));
4345
$this->assertNotEmpty($existingLicenseCompany = $fixturesLicense->getCompany());
@@ -46,7 +48,7 @@ public function testExecute()
4648
$this->assertEquals("APAC-updated",$existingLicenseCompany->getRegion());
4749

4850
// check new license without contact info
49-
$this->assertNotEmpty($license = $licenseRepo->findOneBy(["addonLicenseId"=>1111116]));
51+
$this->assertNotEmpty($license = $licenseRepo->findOneBy(["addonLicenseId"=>2111111]));
5052
$this->assertEquals(0,count($license->getTransactions()));
5153

5254
$this->assertNotEmpty($company = $license->getCompany());

src/AppBundle/Tests/Command/ImportTransactionCommandTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function testExecute()
2222
$addonRepo = $this->getEntityManager()->getRepository("AppBundle:Addon");
2323
$licenseRepo = $this->getEntityManager()->getRepository("AppBundle:License");
2424

25-
$this->assertEmpty($transactionRepo->findOneBy(["transactionId"=>"AT-00000004"]));
25+
$this->assertGreaterThan(1,$transactionRepo->findBy(["transactionId"=>"AT-00000004"]));
2626
$this->assertEquals(3.75,$transactionRepo->findEstimatedIncome("2017-01-10","2017-01-30"));
2727

2828
$this->assertNotEmpty($company1 = $companyRepo->findOneBy(["senId"=>"SEN-0000003"]));
@@ -43,9 +43,14 @@ public function testExecute()
4343
'command' => $command->getName(),
4444
'file' => 'src/AppBundle/Tests/_json/transaction.json'
4545
]);
46+
47+
$this->assertContains("Command completed successfully",$commandTester->getDisplay());
4648
$this->getEntityManager()->clear();
4749

48-
$this->assertNotEmpty($newTransaction = $transactionRepo->findOneBy(["transactionId"=>"AT-00000004"]));
50+
// check for few transactions with the same AT-00000001
51+
$this->assertEquals(2,count($transactionRepo->findBy(["transactionId"=>"AT-00000001"])));
52+
53+
// $this->assertNotEmpty($newTransaction = $transactionRepo->findOneBy(["transactionId"=>"AT-00000004"]));
4954

5055
$this->assertNotEmpty($company1 = $companyRepo->findOneBy(["senId"=>"SEN-0000003"]));
5156
$this->assertNotEmpty($company1License = $licenseRepo->findOneBy(["addonLicenseId"=>"1111113"]));

src/AppBundle/Tests/_json/licenses_no_contacts.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
},
4545
{
4646
"_comment" : "Not existing in base.yml license with removed contacts",
47-
"addonLicenseId": "1111116",
48-
"hostLicenseId": "1111116",
47+
"addonLicenseId": "2111111",
48+
"hostLicenseId": "2111111",
4949
"licenseId": "SEN-0000005",
5050
"addonKey": "net.fake.addon3",
5151
"addonName": "Fake Addon #3 '%~!\"<>",

src/AppBundle/Tests/_json/transaction.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@
4141
"maintenanceEndDate": "2017-01-11"
4242
}
4343
},
44+
{
45+
"_comment": "existing transaction with new addon",
46+
"transactionId": "AT-00000001",
47+
"addonLicenseId": "1111116",
48+
"_comment_hostLicenseId": "hostLicenseId is not processed now, so its renamed",
49+
"licenseId": "SEN-0000003",
50+
"addonKey": "net.fake.addon2",
51+
"addonName": "Fake Addon #2",
52+
"lastUpdated": "2017-01-05",
53+
"purchaseDetails": {
54+
"saleDate": "2016-12-11",
55+
"tier": "15 Users",
56+
"licenseType": "COMMERCIAL",
57+
"hosting": "Cloud",
58+
"billingPeriod": "Monthly",
59+
"purchasePrice": 5.0,
60+
"vendorAmount": 3.75,
61+
"saleType": "New",
62+
"maintenanceStartDate": "2016-12-11",
63+
"maintenanceEndDate": "2017-01-11"
64+
}
65+
},
4466
{
4567
"_comment": "new transaction",
4668
"transactionId": "AT-00000004",

0 commit comments

Comments
 (0)