Path : /var/www/html/jewelry-pos/app/Http/Controllers/ |
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/CategoryReportTransactionController.php |
<?php namespace App\Http\Controllers; use App\Exports\CategoryProductExport; use App\Exports\ProductExport; use App\Exports\SaleExport; use App\Exports\TransactionExport; use App\Models\Product; use App\Models\ProductCategoryWeightHistory; use App\Models\ProductCategory; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Maatwebsite\Excel\Facades\Excel; class CategoryReportTransactionController extends Controller { public function transaction(Request $request, $id) { $paginate = $request->get('paginate')??25; $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; $productCategoryWeightHistory = ProductCategoryWeightHistory::where('product_category_id' , $id)->whereBetween('created_at', [$start_date . " 00:00:00", $end_date . " 23:59:59"])->orderBy('id' , 'desc'); if($request->in_out > 0){ $productCategoryWeightHistory = $productCategoryWeightHistory->where('weight' , '>' , 0)->paginate($paginate); }else if($request->in_out < 0){ $productCategoryWeightHistory = $productCategoryWeightHistory->where('weight' , '<' , 0)->paginate($paginate); }else{ $productCategoryWeightHistory = $productCategoryWeightHistory->paginate($paginate); } return view('transactions.transaction', compact('productCategoryWeightHistory' , 'paginate' , 'start_date' , 'end_date' , 'id' , 'dates' , 'in_out')); } public function exportTransaction(Request $request , $id) { return Excel::download(new TransactionExport($id,$request->get('in_out'),$request->get('start_date'),$request->get('end_date'),$request->get('paginate')),'transaction.xlsx'); } public function transactionPrint(Request $request , $id) { $paginate = $request->get('paginate')??25; $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; $productCategoryWeightHistory = ProductCategoryWeightHistory::where('product_category_id' , $id)->whereBetween('created_at', [$start_date . " 00:00:00", $end_date . " 23:59:59"])->orderBy('id' , 'desc'); if($request->in_out > 0){ $productCategoryWeightHistory = $productCategoryWeightHistory->where('weight' , '>' , 0)->paginate($paginate); }else if($request->in_out < 0){ $productCategoryWeightHistory = $productCategoryWeightHistory->where('weight' , '<' , 0)->paginate($paginate); }else{ $productCategoryWeightHistory = $productCategoryWeightHistory->paginate($paginate); } return view('transactions.transaction-print', compact('productCategoryWeightHistory' , 'paginate' , 'start_date' , 'end_date' , 'id' , 'dates' , 'in_out')); } // public function edit($id , Request $request) // { // $category_id = $request->get('category_id'); // $productCategoryWeightHistory = ProductCategoryWeightHistory::find($id); // return view('transactions.edit' , compact('productCategoryWeightHistory' , 'category_id')); // } // public function update($id , Request $request) // { // $request->validate([ // 'weight' => 'required', //// 'note' => 'required', // ]); // $updateWeightHistory = ProductCategoryWeightHistory::find($id); // $updateWeightHistory->update([ // 'weight' => $request->weight, // 'note' => $request->note, // ]); // $category_id = $request->get('category_id'); // return redirect()->route('product-category.transaction' , $category_id); // } public function destroy($id , Request $request) { $productCategoryWeightHistory = ProductCategoryWeightHistory::find($id); $productCategory = $productCategoryWeightHistory->productCategory; $productCategory->total_weight = $productCategory->total_weight-$productCategoryWeightHistory->weight; $productCategory->save(); $productCategoryWeightHistory->delete(); $category_id = $request->get('category_id'); return redirect()->route('product-category.transaction' , $category_id); } }