@bobbybouwmann let me explain this coding line by line, so that i too can understand. and even sometimes if my understanding is wrong means u can correct me,
and sorry for delay, here 2 days leave fo a festival thats y.
Just fetching all the information in descending order from sales_table and storing in $sales
$sales = Sales_details::orderBy('created_at','desc')->get();
Making an empty array
$sales_details = [];
Grouping the customers and initializing total_litres and amount for that customers. so here what happens for each name total_litre and amount is initiated. based on the customer name it is initiated.
foreach ($sales as $key => $sale)
{
//total litres initialisation for all customers
$sales_details[$sale->customer_name]["total_litres"] = 0;
//total rate initialisation for all customers
$sales_details[$sale->customer_name]["total"] = 0;
}
at this position the if i do dd($sales_details)
the screen looks like this
array:70 [▼
"Balajie" => array:2 [▼
"total_litres" => 0
"total" => 0
]
"Johnpan" => array:2 [▼
"total_litres" => 0
"total" => 0
]
"Muthuraj" => array:2 [▶]
"M.M Pannai" => array:2 [▶]
"Paramasivam" => array:2 [▶]
"Selvam" => array:2 [▶]
"Selladurai" => array:2 [▶]
"Sivanaiya" => array:2 [▶]
"Murugan vadai" => array:2 [▶]
"Murugan" => array:2 [▶]
"Merchant" => array:2 [▶]
"Karuppasamy" => array:2 [▶]
"Kadai" => array:2 [▶]
"Mariappan" => array:2 [▶]
"Meera" => array:2 [▶]
"Nelson" => array:2 [▶]
"Murugan (arun bakry)" => array:2 [▶]
"malgudi" => array:2 [▶]
"Arun" => array:2 [▶]
"manikandan" => array:2 [▶]
"Jothi" => array:2 [▶]
"Kani" => array:2 [▶]
"Rathigamess" => array:2 [▶]
"Ramashanthiran" => array:2 [▶]
"Sekar Tea" => array:2 [▶]
"Sekar" => array:2 [▶]
"Lakshmi sankar" => array:2 [▶]
"Rajtea" => array:2 [▶]
"Muthu Tea" => array:2 [▶]
"Muthuvilas" => array:2 [▶]
"Ammaiappar" => array:2 [▶]
"Ratha" => array:2 [▶]
"Gogila" => array:2 [▶]
"Bombay" => array:2 [▶]
"Nanjil" => array:2 [▶]
"Thamilan tea" => array:2 [▶]
"Packiaraj" => array:2 [▶]
"Victor" => array:2 [▶]
"Viyakapparaj Tea" => array:2 [▶]
"Pannaiyar Tea" => array:2 [▶]
"Innacimuthu tea" => array:2 [▶]
"Sinnaraj Tea" => array:2 [▶]
"Peria Raj Tea" => array:2 [▶]
"Philip tea" => array:2 [▶]
"kapil" => array:2 [▶]
"Selvakumar" => array:2 [▶]
"Sinnaraj" => array:2 [▶]
"Selvakumar 1" => array:2 [▶]
"Robert" => array:2 [▶]
"Sinnaraj 1" => array:2 [▶]
"Ganaselvam" => array:2 [▶]
"Calf" => array:2 [▶]
"Aavin" => array:2 [▶]
"Sankar" => array:2 [▶]
"Aathi 2" => array:2 [▶]
"pallack Road Tea" => array:2 [▶]
"sahayam" => array:2 [▶]
"Samithurai" => array:2 [▶]
"Master Loorthu samy" => array:2 [▶]
"Kannan" => array:2 [▶]
"Aanjali" => array:2 [▶]
"Krisnan kovil" => array:2 [▶]
"Mariammal" => array:2 [▶]
"Ponnusamy" => array:2 [▶]
"Karrupasamy" => array:2 [▶]
"Bus stand" => array:2 [▶]
"Aathi 1" => array:2 [▶]
"Vighnesh" => array:2 [▶]
"Bombay battrai" => array:2 [▶]
"SelvaRaj tea" => array:2 [▶]
]
after that there made another for loop to total the litres and total the amount for that customer. here whats happens the total litres of milk is stores in total_litres for specific customer and the total amount of that customer is stored in total. based in the name this is happening
foreach ($sales as $key => $sale)
{
$sales_details[$sale->customer_name]["total_litres"] += $sale->no_of_litre;
$sales_details[$sale->customer_name]["total"] += $sale->total;
}
after this if i give dd($sales_details)
it gives like this
array:70 [▼
"Balajie" => array:2 [▼
"total_litres" => 13.0
"total" => 455.0
]
"Johnpan" => array:2 [▼
"total_litres" => 13.0
"total" => 455.0
]
"Muthuraj" => array:2 [▶]
"M.M Pannai" => array:2 [▶]
"Paramasivam" => array:2 [▶]
"Selvam" => array:2 [▶]
"Selladurai" => array:2 [▶]
"Sivanaiya" => array:2 [▶]
"Murugan vadai" => array:2 [▶]
"Murugan" => array:2 [▶]
"Merchant" => array:2 [▶]
"Karuppasamy" => array:2 [▶]
"Kadai" => array:2 [▶]
"Mariappan" => array:2 [▶]
"Meera" => array:2 [▶]
"Nelson" => array:2 [▶]
"Murugan (arun bakry)" => array:2 [▶]
"malgudi" => array:2 [▶]
"Arun" => array:2 [▶]
"manikandan" => array:2 [▶]
"Jothi" => array:2 [▶]
"Kani" => array:2 [▶]
"Rathigamess" => array:2 [▶]
"Ramashanthiran" => array:2 [▶]
"Sekar Tea" => array:2 [▶]
"Sekar" => array:2 [▶]
"Lakshmi sankar" => array:2 [▶]
"Rajtea" => array:2 [▶]
"Muthu Tea" => array:2 [▶]
"Muthuvilas" => array:2 [▶]
"Ammaiappar" => array:2 [▶]
"Ratha" => array:2 [▶]
"Gogila" => array:2 [▶]
"Bombay" => array:2 [▶]
"Nanjil" => array:2 [▶]
"Thamilan tea" => array:2 [▶]
"Packiaraj" => array:2 [▶]
"Victor" => array:2 [▶]
"Viyakapparaj Tea" => array:2 [▶]
"Pannaiyar Tea" => array:2 [▶]
"Innacimuthu tea" => array:2 [▶]
"Sinnaraj Tea" => array:2 [▶]
"Peria Raj Tea" => array:2 [▶]
"Philip tea" => array:2 [▶]
"kapil" => array:2 [▶]
"Selvakumar" => array:2 [▶]
"Sinnaraj" => array:2 [▶]
"Selvakumar 1" => array:2 [▶]
"Robert" => array:2 [▶]
"Sinnaraj 1" => array:2 [▶]
"Ganaselvam" => array:2 [▶]
"Calf" => array:2 [▶]
"Aavin" => array:2 [▶]
"Sankar" => array:2 [▶]
"Aathi 2" => array:2 [▶]
"pallack Road Tea" => array:2 [▶]
"sahayam" => array:2 [▶]
"Samithurai" => array:2 [▶]
"Master Loorthu samy" => array:2 [▶]
"Kannan" => array:2 [▶]
"Aanjali" => array:2 [▶]
"Krisnan kovil" => array:2 [▶]
"Mariammal" => array:2 [▶]
"Ponnusamy" => array:2 [▶]
"Karrupasamy" => array:2 [▶]
"Bus stand" => array:2 [▶]
"Aathi 1" => array:2 [▶]
"Vighnesh" => array:2 [▶]
"Bombay battrai" => array:2 [▶]
"SelvaRaj tea" => array:2 [▶]
]
Am i right? is my understanding right?
Now everything is fine. i got the customer name, their total_litres and total_amount.
Now i need to display the am and pm based on date.
whats my doubt is
so just think of the $sales = Sales_details::orderBy('created_at','desc')->get(); which possesses all the rows and columns from the table.
so if there is a two rows,
17-01-2019 am Abdul 30 litres
17-01-2019 pm Abdul 50 litres.
consider this above two entries. i should change the above entry as
Customer 17-01-2019 litres
Name am pm -
Abdul 30 50 80
That is the date must come one time only but the am pm must be displayed with the litres.
think the above example just having two rows. but it must be displayed given above.
How please give a glimpse.
just forget the coding which given for total_litres and total.
only think the above example, for that how we can write code. just for the two rows.
Kindly suggest me a logic