public function export(KeyExportRequest $request)
{
try {
$name = 'filter_keys_' . now()->format('d_m_y_H_i_s') . '.xlsx';
(new KeyExport($request->validated()))->store($name, 'filter_keys');
return $this->apiSuccessResponse(null, Response::HTTP_OK, 'Filiternize uygun exportu tamamlayınca sizi bilgilendireceğiz.');
} catch (\Exception $exception) {
return $this->exceptionResponse($exception);
}
//KEyExport
public function query()
{
return
Key::query()->
with('supplier', 'game', 'creator', 'order', 'saleInfo')
->when(in_array($this->payload['status'], [KeyStatus::SOLD->value, KeyStatus::DELIVERED->value]), function (Builder $query) {
// $query->whereBetween('sell_date', [Carbon::parse($this->payload['start_date']), Carbon::parse($this->payload['end_date'])]);
$query->whereBetween('sell_date', [Carbon::parse('2023-07-01')->startOfMonth(), Carbon::parse('2023-07-10')]);
})
->where('status', $this->payload['status'])
->when(!empty($this->payload['games']), function (Builder $query) {
$query->whereIn('game_id', $this->payload['games']);
})
->when(!empty($this->payload['suppliers']), function (Builder $query) {
$query->whereIn('supplier_id', $this->payload['suppliers']);
})
->when(!empty($this->payload['customers']), function (Builder $query) {
$orders = Order::whereIn('customer_id', $this->payload['customers'])->with('orderItems')->get();
$keys = $orders->flatMap(function ($order) {
return $order->orderItems->map(function ($item) {
return $item->key_id;
});
})->unique()->values()->all();
$query->whereIn('id', $keys);
});
}
public function headings(): array
{
return [
"ID",
"UUID",
"WHO",
"ORDER_TYPE",
"CUSTOMER NAME",
"SUPPLIER NAME",
"GAME_ID",
"KEY",
"STATUS",
"IS_KDV",
"KDV_AMOUNT",
"COST",
"COST_CURRENCY",
"COST_CONVERT_EURO",
"AMOUNT",
"AMOUNT_CURRENCY",
"AMOUNT_CONVERT_EURO",
"SELL_DATE",
"CREATED_AT"
];
}
public function map($row): array
{
$isNotOrder = is_null($row->order_id);
return [
$row->id,
$row->uuid,
$row->creator->full_name,
!$isNotOrder ? OrderService::defineOrderType($row?->order->order_type) : '-',
KeyService::defineCustomer($row),
$row->supplier->name,
$row->game->name,
$row->key,
KeyStatus::defineStatus($row->status),
$row->is_kdv ? "1" : "0",
$row->is_kdv ? $row->kdv_amount : "0",
number_format($row->cost, 2),
CurrencyEnum::from($row->cost_currency_id)->name,
$row->cost_convert_euro,
!is_null($row->saleInfo) ? $row->saleInfo->amount : '-',
!is_null($row->saleInfo) ? CurrencyEnum::from($row->saleInfo->amount_currency_id)->name : '-',
!is_null($row->saleInfo) ? $row->saleInfo->amount_convert_euro : '-',
!is_null($row->sell_date) ? $row->sell_date->format('d.m.Y H:i:s') : '-',
$row->created_at?->format('d.m.Y H:i:s')
];
}
Basit bir tabloyu export alırken sorun olmuyor aama 200 300 binlik bir data içinb sıkıntı çıkıyor
kontroller endpointini tetiklemedn önce jobs tabosunu temizliyorum.
queue:work komutunu çalıştırıyorum fail durumu olmuyor ama kendiliğinden duruyor