KUJUNTI.ID MINISH3LL
Path : /var/www/html/jewelry-pos/app/Http/Controllers/
(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/Http/Controllers/QtyHistoryReportController.php


<?php

namespace App\Http\Controllers;

use App\Exports\ProductTransactionReportExport;
use App\Models\QtyHistory;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class QtyHistoryReportController extends Controller
{
    public function __construct()
    {
        $this->middleware('permission:reports-product-transaction-list' , ['only' => ['index' , 'list' , 'export' , 'destroy']]);
    }
    /**
     * Display a listing of the resource.
     */
    public function option(Request $request)
    {
        return view('report-product-transactions.option');
    }
    public function option2(Request $request)
    {
        return view('product-qty-histories.option');
    }
    public function index(Request $request)
    {
        $paginate = $request->get('paginate')??25;
        $for_sale = $request->get('for_sale');
        $q = $request->get('q')??null;
        $start_date = $request->get('start_date') ?? date('Y-m-d');
        $end_date = $request->get('end_date') ?? date('Y-m-d');
        $dates = explode(' - ', $request->date);
        if ($request->date) {
            $start_date = $dates[0];
            $end_date = $dates[1];
        }
        $in_out = $request->in_out??0;
        $productQtyHistories = QtyHistory::with('product')->whereBetween('created_at' , [$start_date . " 00:00:00" , $end_date . " 23:59:59"])
            ->whereHas('product', function ($query) use ($for_sale) {  // Filter based on related product's 'for_sale' column
                $query->where('for_sale', $for_sale);
            })->where('qty_histories.is_adjustment' , false);
        if($q){
            $productQtyHistories = $productQtyHistories->where('grn' , $q);
        }
        if($request->in_out > 0){
            $productQtyHistories = $productQtyHistories->where('qty' , '>' , 0)->paginate($paginate);
        }else if($request->in_out < 0){
            $productQtyHistories = $productQtyHistories->where('qty' , '<' , 0)->paginate($paginate);
        }else{
            $productQtyHistories = $productQtyHistories->paginate($paginate);
        }
        return view('report-product-transactions.index' , compact('productQtyHistories' , 'for_sale' , 'start_date' , 'end_date' , 'paginate' , 'in_out' , 'q'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     */
    public function print(Request $request)
    {
        $ids = explode(',',$request->get('past_sale_ids'));
        // $ids = $ids[0];
        $paginate = $request->get('paginate')??25;
        $for_sale = $request->get('for_sale');
        $q = $request->get('q')??null;
        $start_date = $request->get('start_date') ?? date('Y-m-d');
        $end_date = $request->get('end_date') ?? date('Y-m-d');
        $dates = explode(' - ', $request->date);
        if ($request->date) {
            $start_date = $dates[0];
            $end_date = $dates[1];
        }
        $in_out = $request->in_out??0;
        $productQtyHistories = QtyHistory::whereBetween('created_at' , [$start_date . " 00:00:00" , $end_date . " 23:59:59"])
            ->whereHas('product', function ($query) use ($for_sale) {  // Filter based on related product's 'for_sale' column
                $query->where('for_sale', $for_sale);
            })->where('qty_histories.is_adjustment' , false)
            ->orderBy('id' , 'desc');
        if($q){
            $productQtyHistories = $productQtyHistories->where('grn' , $q);
        }
        if($request->in_out > 0){
            $productQtyHistories = $productQtyHistories->where('qty' , '>' , 0);
        }else if($request->in_out < 0){
            $productQtyHistories = $productQtyHistories->where('qty' , '<' , 0);
        }else{
            $productQtyHistories = $productQtyHistories;
        }
        if($request->get('past_sale_ids')){
            $productQtyHistories = $productQtyHistories->whereIn('id' , $ids)->get();
        }
        else{
            $productQtyHistories = $productQtyHistories->get();
        }

        return view('report-product-transactions.list' , compact('productQtyHistories' , 'for_sale' , 'start_date' , 'end_date' , 'paginate' , 'in_out' , 'q'));
    }

    public function export(Request $request)
    {
        return Excel::download(new ProductTransactionReportExport($request->get('for_sale'),$request->get('start_date'),$request->get('end_date'), $request->get('paginate') , $request->get('in_out') , $request->get('q') , $request->get('date')), 'ProductQtyTransaction.xlsx');
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id , Request $request)
    {
        $qtyHistory = QtyHistory::find($id);
        $paginate = $request->get('paginate')??25;
        $q = $request->get('q')??null;
        $start_date = $request->get('start_date') ?? date('Y-m-d');
        $end_date = $request->get('end_date') ?? date('Y-m-d');
        $dates = explode(' - ', $request->date);
        if ($request->date) {
            $start_date = $dates[0];
            $end_date = $dates[1];
        }
        $in_out = $request->in_out??0;
        $product = $qtyHistory->product;
        $for_sale = $product->for_sale;
        if(!$qtyHistory->weight){
            if($qtyHistory->qty>0){
                $product->qty = $product->qty-$qtyHistory->qty;
            }
            else{
                $product->qty = $product->qty+(-$qtyHistory->qty);
            }
        }else{
            if($qtyHistory->weight>0){
                $product->weight = $product->weight-$qtyHistory->weight;
            }
            else{
                $product->weight = $product->weight+(-$qtyHistory->weight);
            }
        }
        $product->save();

        $qtyHistory->delete();
        return redirect()->route('reports.product-qty-history' , 'start_date=' . $start_date . '&end_date=' . $end_date . '&paginate=' . $paginate . '&in_out=' . $in_out . '&q=' . $q . '&for_sale=' . $for_sale)->with('success' , __('message.deleted successfully'));
    }
}

© KUJUNTI.ID