mgsmus
Evet en son yüklenen packing liste göre sıralamak istiyorum ama her bir ordera girilen en son yükleme tarihi farklı packingler de order relationun içerisinde kendi aralarında sıralandığı için tabloda sıralayamıyorum
try {
$per_page = $request->input('per_page') ?? 15;
$page = $request->input('page') ?? 1;
$order = $request->input('order') ?? "id";
$sort = $request->input('sort') ?? "desc";
$filter_start_date = $request->input('start_date');
$filter_end_date = $request->input('end_date');
$filter_company_id = $request->input('company_id');
$filter_order_id = $request->input('order_id');
$filter_monthly = json_decode($request->input('monthly'));
$filter_yearly = json_decode($request->input('yearly'));
if ($filter_monthly || $filter_yearly) {
$filter_start_date = null;
$filter_end_date = null;
}
if ($filter_start_date && $filter_end_date) {
$filter_start_date = Carbon::parse($filter_start_date);
$filter_end_date = Carbon::parse($filter_end_date)->addHours(11)->addMinutes(59)->addSeconds(59);
}
$result = Order::with([
'packing' => function ($query) use ($filter_start_date, $filter_end_date, $order, $sort, $filter_monthly, $filter_yearly) {
$query->where('packing_lists.status_id', 27);
if ($filter_start_date && $filter_end_date && !$filter_monthly && !$filter_yearly) {
$query->whereBetween('packing_lists.created_at', [$filter_start_date, $filter_end_date]);
}
if ($order == 'loaded_date') {
$query->orderBy('created_at', $sort);
}
if ($filter_monthly) {
$query->where(function ($query) use ($filter_monthly) {
foreach ($filter_monthly as $month) {
$query->orWhereMonth('created_at', intval($month));
}
});
}
if ($filter_yearly) {
$query->where(function ($query) use ($filter_yearly) {
foreach ($filter_yearly as $year) {
$query->orWhereYear('created_at', intval($year));
}
});
}
},
'company' => function ($query) use ($order, $sort) {
if ($order === 'customer') {
$query->orderBy('name', $sort);
}
},
'currency_unit'
]) ->whereHas('packing', function ($query) use ($filter_start_date, $filter_end_date, $filter_monthly, $filter_yearly, $order, $sort) {
$query->where('packing_lists.status_id', 27);
if ($filter_start_date && $filter_end_date && !$filter_monthly && !$filter_yearly) {
$query->whereBetween('packing_lists.created_at', [$filter_start_date, $filter_end_date]);
}
if ($order == 'loaded_date') {
$query->orderBy('created_at', $sort);
}
if ($filter_monthly) {
$query->where(function ($query) use ($filter_monthly) {
foreach ($filter_monthly as $month) {
$query->orWhereMonth('created_at', intval($month));
}
});
}
if ($filter_yearly) {
$query->where(function ($query) use ($filter_yearly) {
foreach ($filter_yearly as $year) {
$query->orWhereYear('created_at', intval($year));
}
});
}
});
if ($filter_company_id) {
$result->where('company_id', $filter_company_id);
}
if ($filter_order_id) {
$result->where('id', $filter_order_id);
}
if ($order === 'loaded_date') {
$result->orderBy('created_at', $sort);
}
if ($order != "loaded_date" && $order != 'customer') {
$result = $result
->orderBy($order, $sort);
}
$result = $result->paginate($per_page, ['*'], 'page', $page)
->toArray();
return Output::success($result);
} catch (Exception $e) {
return Output::error(Response::HTTP_INTERNAL_SERVER_ERROR, $e->getMessage());
}
Front Kısmı
formattedReport() {
if (!this.items || this.items.data === null || this.items.data === undefined)
return [];
let temp = [];
this.items.data.forEach((item) => {
let findCurrency = _.find(this.currencyRateOptions, {
code: item.currency_unit.code,
});
let sumPackingListAmount = _.sumBy(item.packing, function (o) {
return o.amount;
});
let endorsement = Number(sumPackingListAmount) * Number(item.sale_price);
let endorsementTL = endorsement * Number(findCurrency.rate);
let salePrice = Number(item.sale_price);
let loadedDate = "";
if (item.packing[0]) {
loadedDate = moment(item.packing[0].created_at).format(
MOMENT_SYSTEM_DATE_FORMAT
);
}
temp.push({
customer: item.company.name,
order_number: item.order_number,
amount: sumPackingListAmount,
loaded_date: loadedDate,
sale_price: salePrice.toLocaleString("tr-TR") + " " + item.currency_unit.code,
currency_indorsement:
endorsement.toLocaleString("tr-TR") + " " + item.currency_unit.code,
currency_tl_indorsement:
endorsementTL.toLocaleString("tr-TR", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}) + " ₺",
});
});
return temp;
},