KUJUNTI.ID MINISH3LL
Path : /var/www/html/jewelry-pos/app/Exports/
(S)h3ll Cr3at0r :
F!le Upl0ad :

B-Con CMD Config cPanel C-Rdp D-Log Info Jump Mass Ransom Symlink vHost Zone-H

Current File : /var/www/html/jewelry-pos/app/Exports/QtyTransactionExport.php


<?php

namespace App\Exports;

use App\Models\QtyHistory;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class QtyTransactionExport implements FromQuery , WithMapping , WithHeadings
{
    /**
    * @return \Illuminate\Support\Collection
    */
//    public function collection()
//    {
//        //
//    }
    private $no = 0;
    private $in_out;
    private $start_date;
    private $end_date;
    private $paginate;
    private $date;
    private $id;
    public function __construct($id ,$in_out,$start_date,$end_date,$paginate,$q)
    {
        $this->id = $id;
        $this->in_out = $in_out;
        $this->start_date = $start_date;
        $this->end_date = $end_date;
        $this->paginate = $paginate;
        $this->q = $q;
    }

    /**
     * @return \Illuminate\Support\Collection
     */

    public function headings(): array
    {
        return [
            'no',
            __('message.part number'),
            __('message.product category'),
            __('message.name'),
            __('message.qty'),
            __('message.qty before transaction'),
            __('message.qty after transaction'),
            __('message.note'),
            __('message.user'),
            __('message.updated at'),
        ];
    }
    public function query()
    {
        $paginate = $this->paginate??25;
        $start_date = $this->start_date ?? date('Y-m-d');
        $end_date = $this->end_date ?? date('Y-m-d');
        $q = $this->q ?? null;
        $dates = explode(' - ', $this->date);
        if ($this->date) {
            $start_date = $dates[0];
            $end_date = $dates[1];
        }
        $in_out = $this->in_out??0;
        $qtyHistories = QtyHistory::where('product_id' , $this->id)->whereBetween('created_at', [$start_date . " 00:00:00", $end_date . " 23:59:59"])->orderBy('id' , 'desc');
        if($q){
            $qtyHistories = $qtyHistories->where('grn' , $q);
        }
        if($this->in_out > 0){
            $qtyHistories = $qtyHistories->where('qty' , '>' , 0);
        }else if($this->in_out < 0){
            $qtyHistories = $qtyHistories->where('qty' , '<' , 0);
        }else{
            $qtyHistories = $qtyHistories;
        }
        return $qtyHistories;
    }

    public function map($qtyHistories): array
    {
        $this->no++;
        return [
            $this->no,
            $qtyHistories->product->part_number,
            $qtyHistories->product->productCategoy->name??'',
            $qtyHistories->product->name??'',
            $qtyHistories->qty,
            $qtyHistories->qty_before_transaction,
            $qtyHistories->qty_after_transaction,
            $qtyHistories->note,
            $qtyHistories->user->name??'',
            $qtyHistories->created_at->format('d/m/y H:i'),
        ];
    }
}

© KUJUNTI.ID