Browse Source

fix: report filter

Muhammad Iqbal Afandi 3 years ago
parent
commit
676d02c0d5

+ 3
- 3
app/Http/Controllers/ReportMutationController.php View File

@@ -31,6 +31,9 @@ class ReportMutationController extends Controller
31 31
             'filters' => request()->all('startDate', 'endDate', 'outlet'),
32 32
             'mutations' => Inertia::lazy(
33 33
                 fn() => [
34
+                    'totalIncome' => (new MutationService)->totalIncomeAsString($mutations->get()),
35
+                    'totalExpense' => (new MutationService)->totalExpenseAsString($mutations->get()),
36
+                    'totalAmount' => (new MutationService)->totalAmountAsString($mutations->get()),
34 37
                     'details' => $mutations
35 38
                         ->latest()
36 39
                         ->paginate(10)
@@ -43,9 +46,6 @@ class ReportMutationController extends Controller
43 46
                             'transactionId' => $mutation->transaction_id,
44 47
                             'expenseId' => $mutation->expense_id,
45 48
                         ]),
46
-                    'totalIncome' => (new MutationService)->totalIncomeAsString($mutations->get()),
47
-                    'totalExpense' => (new MutationService)->totalExpenseAsString($mutations->get()),
48
-                    'totalAmount' => (new MutationService)->totalAmountAsString($mutations->get()),
49 49
                 ]
50 50
             ),
51 51
             'outlets' => Outlet::all()

+ 1
- 1
app/Http/Controllers/ReportTransactionController.php View File

@@ -43,9 +43,9 @@ class ReportTransactionController extends Controller
43 43
             'filters' => request()->all('startDate', 'endDate', 'outlet'),
44 44
             'transactions' => Inertia::lazy(
45 45
                 fn() => [
46
-                    'details' => $transaction,
47 46
                     'totalTransaction' => $transactions->count(),
48 47
                     'totalAmount' => (new TransactionService)->totalPriceGroupAsString($transactions),
48
+                    'details' => $transaction,
49 49
                 ]
50 50
             ),
51 51
             'outlets' => Outlet::all()

+ 5
- 1
app/Services/ExpenseService.php View File

@@ -14,7 +14,11 @@ class ExpenseService extends CurrencyFormatService
14 14
 
15 15
     public function totalPriceAsString(EloquentCollection $collection)
16 16
     {
17
-        return $this->setRupiahFormat($this->totalPrice($collection), true);
17
+        if ($collection->count()) {
18
+            return $this->setRupiahFormat($this->totalPrice($collection), true);
19
+        } else {
20
+            return $this->setRupiahFormat(0, true);
21
+        }
18 22
     }
19 23
 
20 24
     public function totalPerMonth(EloquentCollection $collections)

+ 16
- 3
app/Services/MutationService.php View File

@@ -31,17 +31,30 @@ class MutationService extends CurrencyFormatService
31 31
 
32 32
     public function totalIncomeAsString(EloquentCollection $collections)
33 33
     {
34
-        return $this->setRupiahFormat($this->totalIncome($collections), true);
34
+        if ($collections->count()) {
35
+            return $this->setRupiahFormat($this->totalIncome($collections), true);
36
+        } else {
37
+            return $this->setRupiahFormat(0, true);
38
+        }
35 39
     }
36 40
 
37 41
     public function totalExpenseAsString(EloquentCollection $collections)
38 42
     {
39
-        return $this->setRupiahFormat($this->totalExpense($collections), true);
43
+        if ($collections->count()) {
44
+            return $this->setRupiahFormat($this->totalExpense($collections), true);
45
+        } else {
46
+            return $this->setRupiahFormat(0, true);
47
+        }
40 48
     }
41 49
 
42 50
     public function totalAmountAsString(EloquentCollection $collections)
43 51
     {
44
-        $amount = $this->totalIncome($collections) - $this->totalExpense($collections);
52
+        if ($collections->count()) {
53
+            $amount = $this->totalIncome($collections) - $this->totalExpense($collections);
54
+        } else {
55
+            $amount = 0;
56
+        }
57
+
45 58
         return $this->setRupiahFormat($amount, true);
46 59
     }
47 60
 

+ 10
- 2
app/Services/TransactionService.php View File

@@ -35,7 +35,11 @@ class TransactionService extends CurrencyFormatService
35 35
 
36 36
     public function totalPriceGroupAsString(EloquentCollection $collections)
37 37
     {
38
-        return $this->setRupiahFormat($this->totalPriceGroup($collections), true);
38
+        if ($collections->count()) {
39
+            return $this->setRupiahFormat($this->totalPriceGroup($collections), true);
40
+        } else {
41
+            return $this->setRupiahFormat(0, true);
42
+        }
39 43
     }
40 44
 
41 45
     public function totalDiscountGiven(EloquentCollection $collections)
@@ -50,7 +54,11 @@ class TransactionService extends CurrencyFormatService
50 54
 
51 55
     public function totalDiscountGivenGroupAsString(EloquentCollection $collections)
52 56
     {
53
-        return $this->setRupiahFormat($this->totalDiscountGivenGroup($collections), true);
57
+        if ($collections->count()) {
58
+            return $this->setRupiahFormat($this->totalDiscountGivenGroup($collections), true);
59
+        } else {
60
+            return $this->setRupiahFormat(0, true);
61
+        }
54 62
     }
55 63
 
56 64
     public function totalPerMonth(EloquentCollection $collections)