added export functionality
This commit is contained in:
33
app/Exports/UserProductExport.php
Normal file
33
app/Exports/UserProductExport.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Admin\monthly_update_master;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
|
||||
class UserProductExport implements FromCollection, WithHeadings
|
||||
{
|
||||
// use Exportable;
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
|
||||
protected $data, $columns;
|
||||
function __construct($data, $columns)
|
||||
{
|
||||
$this->data = $data;
|
||||
$this->columns = $columns;
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
// $data = monthly_update_master::select('')->get();
|
||||
return $this->data;
|
||||
}
|
||||
public function headings(): array
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Exports\UserProductExport;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\MonthlyUpdateMaster;
|
||||
@@ -39,6 +40,33 @@ class ManageUserProductController extends Controller
|
||||
return view('Admin.Pages.manage_investors.manage_user_product.manage_user', compact('userProduct'));
|
||||
}
|
||||
|
||||
public function exportUserProduct()
|
||||
{
|
||||
// dd('hello');
|
||||
$data = MonthlyUpdateMaster::with(
|
||||
['investor' => function($query){
|
||||
$query->select('id','name');
|
||||
// },'products.categorys' => function($query){
|
||||
// $query->select('id','categories_id');
|
||||
// }])->select('id','users_id','products_id','custom_id')->get();
|
||||
},'products.categorys'])->get();
|
||||
// dd($data->toArray());
|
||||
$withClearData = collect();
|
||||
$new = [];
|
||||
$data->each(function($value) use($withClearData, $new){
|
||||
$new['user_name'] = $value->investor->name;
|
||||
$new['custom_id'] = $value->custom_id;
|
||||
$new['investor_name'] = $value->investor->name;
|
||||
$new['category'] = $value->products->categorys->category_name;
|
||||
$new['holding_status'] = $value->holding_status;
|
||||
$new['created_at'] = $value->created_at->format('d-m-Y');
|
||||
$withClearData->push($new);
|
||||
});
|
||||
$columns = ['User Name', 'CustomId', 'Investor Name', 'Category', 'Holding Status', 'Created At'];
|
||||
// dd($withClearData->sortByDesc('created_at'));
|
||||
return Excel::download(new UserProductExport($withClearData->sortByDesc('created_at'), $columns), 'UsersProduct.XLSX');
|
||||
}
|
||||
|
||||
public function redeemWithSoldAmount(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
|
||||
@@ -139,7 +139,7 @@ $("#editCategoryForm").validate({
|
||||
// $("#save_btn").text("Please wait...");
|
||||
// $("#save_btn").attr("disabled", true);
|
||||
$.ajax({
|
||||
url: "http://localhost/jericho_28_march/manage-investments/categories/edit",
|
||||
url: "/manage-investments/categories/edit",
|
||||
// url: "{{route('manage.categories.edit')}}",
|
||||
type: "POST",
|
||||
data: formData,
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
<div class="top_header d-flex justify-content-between">
|
||||
<p class='fs-2 fw-bold'>Manage User Product</p>
|
||||
<div class="table_right_options d-flex align-items-center">
|
||||
|
||||
<a class="action_icon" href="{{ route('store-user-product') }}">
|
||||
<button type="button" class="btn btn-light-primary me-3">
|
||||
<!--begin::Svg Icon | path: icons/duotune/arrows/arr075.svg-->
|
||||
@@ -90,6 +89,9 @@
|
||||
Financial Assets</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<a class="action_icon" href="{{ route('export-user-product') }}">
|
||||
<button type="button" class="btn btn-light-primary me-3">Export</button>
|
||||
</a>
|
||||
|
||||
<!--begin::Search-->
|
||||
<div class="d-flex align-items-center position-relative">
|
||||
|
||||
@@ -601,6 +601,7 @@ Route::middleware([BackendAccess::class])->group(function () {
|
||||
Route::controller(ManageUserProductController::class)->group(function () {
|
||||
Route::get("manage-user-product", 'index')->name('manage-user-product');
|
||||
Route::get("store-user-product", 'storeUserProduct')->name('store-user-product');
|
||||
Route::get("export-user-product", 'exportUserProduct')->name('export-user-product');
|
||||
Route::get('userProduct/{id}', 'userProduct')->name('userProduct');
|
||||
Route::get("import-monthly-updates", 'importMonthlyUpdateBlade')->name('import-monthly-updates');
|
||||
Route::get("monthly-updates/{id}", 'monthlyUpdates')->name('monthly-updates');
|
||||
|
||||
Reference in New Issue
Block a user