Parcourir la source

fix: report filter

Muhammad Iqbal Afandi il y a 3 ans
Parent
révision
676d02c0d5

+ 3
- 3
app/Http/Controllers/ReportMutationController.php Voir le fichier

31
             'filters' => request()->all('startDate', 'endDate', 'outlet'),
31
             'filters' => request()->all('startDate', 'endDate', 'outlet'),
32
             'mutations' => Inertia::lazy(
32
             'mutations' => Inertia::lazy(
33
                 fn() => [
33
                 fn() => [
34
+                    'totalIncome' => (new MutationService)->totalIncomeAsString($mutations->get()),
35
+                    'totalExpense' => (new MutationService)->totalExpenseAsString($mutations->get()),
36
+                    'totalAmount' => (new MutationService)->totalAmountAsString($mutations->get()),
34
                     'details' => $mutations
37
                     'details' => $mutations
35
                         ->latest()
38
                         ->latest()
36
                         ->paginate(10)
39
                         ->paginate(10)
43
                             'transactionId' => $mutation->transaction_id,
46
                             'transactionId' => $mutation->transaction_id,
44
                             'expenseId' => $mutation->expense_id,
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
             'outlets' => Outlet::all()
51
             'outlets' => Outlet::all()

+ 1
- 1
app/Http/Controllers/ReportTransactionController.php Voir le fichier

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

+ 5
- 1
app/Services/ExpenseService.php Voir le fichier

14
 
14
 
15
     public function totalPriceAsString(EloquentCollection $collection)
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
     public function totalPerMonth(EloquentCollection $collections)
24
     public function totalPerMonth(EloquentCollection $collections)

+ 16
- 3
app/Services/MutationService.php Voir le fichier

31
 
31
 
32
     public function totalIncomeAsString(EloquentCollection $collections)
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
     public function totalExpenseAsString(EloquentCollection $collections)
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
     public function totalAmountAsString(EloquentCollection $collections)
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
         return $this->setRupiahFormat($amount, true);
58
         return $this->setRupiahFormat($amount, true);
46
     }
59
     }
47
 
60
 

+ 10
- 2
app/Services/TransactionService.php Voir le fichier

35
 
35
 
36
     public function totalPriceGroupAsString(EloquentCollection $collections)
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
     public function totalDiscountGiven(EloquentCollection $collections)
45
     public function totalDiscountGiven(EloquentCollection $collections)
50
 
54
 
51
     public function totalDiscountGivenGroupAsString(EloquentCollection $collections)
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
     public function totalPerMonth(EloquentCollection $collections)
64
     public function totalPerMonth(EloquentCollection $collections)