Guys i am working with a project Inventory control like system
The project maintains the whole purchase, income, expenses of a hotel.
the hotel is of three branches. so to make this application used by all the three hotels, i kept separate login for everything.
consider that three hotels S1, S2, and S3
the hotel calculates their income at the end of the day.
so what i did is,
had a form to enter the income_type like
ROOM SERVICE
ROOM BILL
MEALS
PARCEL
TIFFEN
the table income_types contains the fields
id,
login_user_id,
income_type,
created_at,
updated_at
this is the data in that table
id login_user_id income_type
1 1 ROOM SERVICE
2 1 ROOM BILL
3 1 MEALS
4 2 ROOM SERVICE
5 2 ROOM BILL
6 2 MEALS
where
login_user_id 1 =S1 hotel
2= S2 hotel
and this is the incomes table with columns
id,
login_user_id,
income_date,
income_type_id,
income_amount,
and the data are
id login_user_id income_date income_type_id income_amount
1 1 6-04-19 1 200
2 1 6-04-19 2 100
3 1 6-04-19 3 50
4 2 6-04-19 4 600
5 2 6-04-19 5 700
6 2 6-04-19 6 800
Now as i said each shop has separate login id and password
so if S1 is login, that user can take that day income report.
what he gets for the date 6-04-19 is
ROOM SERVICE - 200
ROOM BILL - 100
MEALS - 50
and for the second branch S2
ROOM SERVICE - 600
ROOM BILL - 700
MEALS - 800
this above given are separate income report for one day for two shops S1 and S2
now i need to get both the shops report with total of income_type.
what i expect is
ROOM SERVICE - 800 // (600+200)
ROOM BILL - 800 //(700+100)
MEALS - 850 // (800+50)
this is what the output i expect.
but whats the problem is the login user id are different so that the id's of the income_type also different.
now what can i do??
is there any solution please kindly someone help please.
i think it is possible when the income_type id's are same.
But due to confusion i have given all the details separetely for the users.
i used these codes to get the total values based on income_type
//this fetches all income values based on login id
$incomes=Income::where ('login_user_id',auth()->id())->get();
//declared a array for income type
$income_type=[];
// Initialized the $income_type with 0
foreach ($incomes as $key => $income)
{
$income_type[$income->income_type_id]["total_amount"] = 0;
}
// add the total amount based in the income_type
foreach ($incomes as $key => $income)
{
$income_type[$income->income_type_id]["total_amount"] += $income->income_amount;
}
when i dd($income_type)
the result is
array:4 [▼
1 => array:1 [▼
"total_amount" => 200
]
2 => array:1 [▼
"total_amount" => 100
]
4 => array:1 [▼
"total_amount" => 600
]
5 => array:1 [▼
"total_amount" => 700
]
]
All the above code worked for same id's for another concept in another project.
but here the id's are different so the value are not added what can i do
i thought an idea that,
id's are different but the names will be same.. so why cant i try with income_type names?
bot in controller how can i get the names of income_type with this relation.
this is my income_type model
public function income()
{
return $this->hasMany('App\Income', 'income_type_id');
}
this is my income model
public function income_type()
{
return $this->belongsTo('App\IncomeType', 'income_type_id');
}
if i need the name of income type in my view.blade file just i use
{{$income->income_type->income_type}}
but in controller how can i use the name of the income_type??
Kindly some one help please