@mgsmus
Özür dilerim tekrar rahatsız ediyorum🙁
public function notPlanned(Request $request)
{
$dataList = User::select([
'users.id AS id',
'users.name AS name',
DB::raw("SUM(installments.amount) AS totalInstallments"),
DB::raw("SUM(transactions.amount) AS totalTransactions"),
])
->join('installments', function ($join) {
$join
->on('users.id', '=', 'installments.customer_id');
})
->join('transactions', function ($join) {
$join
->on('users.id', '=', 'transactions.customer_id')
->where('transactions.payment_type', 'ALACAK');
})
->groupBy([
'id',
'name'
])
->havingRaw('totalInstallments <> totalTransactions')
->orderBy('id')
->paginate()
->withQueryString();
return view('dashboard.reports.not-planned', compact('dataList'));
}
Bu işlemde;
totalInstallments sonucunun 3980
ve
totalTransactions sonucunun 3980 olması lazımken
totalInstallments 7960
totalTransactions 19900 çıkıyor.
App\Models\User {#2832 ▼
#fillable: array:25 [▶]
#auditInclude: []
#hidden: array:2 [▶]
#casts: array:1 [▶]
#dates: array:4 [▶]
#connection: "mysql"
#table: "users"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:4 [▼
"id" => 29016
"name" => "DENEME DENEME"
"totalInstallments" => 7960.0
"totalTransactions" => 19900.0
]
#original: array:4 [▶]
#changes: []
#classCastCache: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [▶]
#rememberTokenName: "remember_token"
#accessToken: null
#forceDeleting: false
#userstamping: true
-roleClass: null
-permissionClass: null
#excludedAttributes: []
#auditEvent: null
}
installments tablosunda 5 adet kayıt var, transactions tablosunda iki adet kayıt var.
installments sonucunu transactions tablosundaki adetle çarpıyor ve transactions sonucunu installments tablosundaki adetle çarpıyor.
Bunun önüne nasıl geçebilirim?