| @@ 62-92 (lines=31) @@ | ||
| 59 | return $fees; |
|
| 60 | } |
|
| 61 | ||
| 62 | public function calculateExpectedFeesPerMonth(DateTime $from, DateTime $to) |
|
| 63 | { |
|
| 64 | $to = $to->modify('last day of this month'); |
|
| 65 | ||
| 66 | $report = new ExpectedFeesPerMonthReport($from, $to); |
|
| 67 | ||
| 68 | $res = DB::select( |
|
| 69 | ' |
|
| 70 | SELECT concat(YEAR, \'-\', lpad(cast(MONTH AS CHAR(2)), 2, \'0\')) AS month, |
|
| 71 | count(*) AS count |
|
| 72 | FROM |
|
| 73 | (SELECT extract(MONTH |
|
| 74 | FROM to_date) AS MONTH, |
|
| 75 | extract(YEAR |
|
| 76 | FROM to_date) AS YEAR |
|
| 77 | FROM |
|
| 78 | (SELECT to_date |
|
| 79 | FROM fees |
|
| 80 | WHERE to_date BETWEEN ? AND ?) tbl1) tbl2 |
|
| 81 | GROUP BY concat(MONTH, YEAR), MONTH, YEAR |
|
| 82 | ORDER BY YEAR, MONTH |
|
| 83 | ', [$from->toDateString(), $to->toDateString()] |
|
| 84 | ); |
|
| 85 | ||
| 86 | /** @todo Similar code is duplicated across the project */ |
|
| 87 | foreach ($res as &$crnt) { |
|
| 88 | $report->addMonth($crnt->month, (int) $crnt->count); |
|
| 89 | } |
|
| 90 | ||
| 91 | return $report; |
|
| 92 | } |
|
| 93 | ||
| 94 | /** |
|
| 95 | * /\ |
|
| @@ 100-128 (lines=29) @@ | ||
| 97 | * \/ |
|
| 98 | */ |
|
| 99 | ||
| 100 | public function calculatePaidFeesPerMonth(DateTime $from, DateTime $to) |
|
| 101 | { |
|
| 102 | $report = new PaidFeesPerMonthReport($from, $to); |
|
| 103 | ||
| 104 | $res = DB::select( |
|
| 105 | ' |
|
| 106 | SELECT concat(YEAR, \'-\', lpad(cast(MONTH AS CHAR(2)), 2, \'0\')) AS month, |
|
| 107 | count(*) AS count |
|
| 108 | FROM |
|
| 109 | (SELECT extract(MONTH |
|
| 110 | FROM from_date) AS MONTH, |
|
| 111 | extract(YEAR |
|
| 112 | FROM from_date) AS YEAR |
|
| 113 | FROM |
|
| 114 | (SELECT from_date |
|
| 115 | FROM fees |
|
| 116 | WHERE from_date BETWEEN ? AND ?) tbl1) tbl2 |
|
| 117 | GROUP BY concat(MONTH, YEAR), MONTH, YEAR |
|
| 118 | ORDER BY YEAR, MONTH |
|
| 119 | ||
| 120 | ', [$from->toDateString(), $to->toDateString()] |
|
| 121 | ); |
|
| 122 | ||
| 123 | foreach ($res as &$crnt) { |
|
| 124 | $report->addMonth($crnt->month, (int) $crnt->count); |
|
| 125 | } |
|
| 126 | ||
| 127 | return $report; |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||