-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
67 lines (54 loc) · 2.25 KB
/
Copy pathtest.php
File metadata and controls
67 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Classes\CashIn\CashIn;
//use Classes\CashOut\CashOut;
use Classes\Currency\Currency;
use Classes\CsvReader\CsvReader;
use Classes\Transaction\Transaction;
// Reading data from file
$csv_file = __DIR__ . "/data.csv";
$csv = new CsvReader($csv_file);
// Testing if CashIn Class works properly.
$c = new CashIn;
$res = $c->commision(2000.00);
echo $res . PHP_EOL;
// Testing if CashOut Class works properly.
$c2 = new Currency;
$res3 = $c2->conversion(1548, "JPY");
echo $res3 . PHP_EOL;
echo "-------------------------------" . PHP_EOL;
// Cycling the data and perform payouts.
$totalPerWeek = array();
foreach ($csv->getData() as $trn)
{
// If we have had set our dates for at least two transactions, we calculate if we match the 1000 per WEEK rule.
if (!empty($totalPerWeek[$trn[1]]['firstTransaction']) && !empty($totalPerWeek[$trn[1]]['secondTransaction']))
{
$datetime1 = new \DateTime($totalPerWeek[$trn[1]]['firstTransaction']);
$datetime2 = new \DateTime($totalPerWeek[$trn[1]]['secondTransaction']);
$interval = $datetime1->diff($datetime2);
$timeDiff = $interval->days;
}
$transaction = new Transaction($trn);
if ($transaction->trn->operationType == "cash_out")
{
// If we didn`t set first Transaction date, we assume this is FIRST transaction
if (empty($totalPerWeek[$trn[1]]['firstTransaction']))
{
$totalPerWeek[$trn[1]]['firstTransaction'] = $transaction->trn->date;
}
// Otherwise, we set the second and check if we have two dates, to check if transactions are in the week.
else
{
$totalPerWeek[$trn[1]]['secondTransaction'] = $transaction->trn->date;
}
if (!empty($transaction->trn->timeBetweenPreviousTransaction) && $transaction->trn->timeBetweenPreviousTransaction < 7 )
{
$transaction->trn->totalPerWeek = $totalPerWeek[$trn[1]]['amount'];
$totalPerWeek[$trn[1]]['amount'] += $transaction->trn->currencyConverted;
}
$transaction->trn->timeBetweenPreviousTransaction = (!empty($timeDiff)) ? $timeDiff : '';
}
$res4 = $transaction->getCommision();
echo $res4 . PHP_EOL;
}