update marketing
All checks were successful
All checks were successful
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\PdfService;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Business\App\Exports\ExportComboProduct;
|
||||
|
||||
@@ -13,9 +14,14 @@ class AcnooComboProductController extends Controller
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$branchId = null;
|
||||
if (moduleCheck('MultiBranchAddon')) {
|
||||
$branchId = $user->branch_id ?? $user->active_branch_id;
|
||||
}
|
||||
$search = $request->input('search');
|
||||
|
||||
$combo_products = Product::with(['combo_products', 'unit:id,unitName', 'category:id,categoryName'])
|
||||
$combo_products = Product::with(['combo_products.stock.product', 'unit:id,unitName', 'category:id,categoryName'])
|
||||
->where('business_id', auth()->user()->business_id)
|
||||
->where('product_type', 'combo')
|
||||
->withCount('combo_products as total_combo_products')
|
||||
@@ -31,6 +37,12 @@ public function index(Request $request)
|
||||
});
|
||||
});
|
||||
})
|
||||
->when($branchId, function ($q) use ($branchId) {
|
||||
$q->whereHas('combo_products.stock', function ($q) use ($branchId) {
|
||||
$q->where('branch_id', $branchId);
|
||||
});
|
||||
})
|
||||
|
||||
->latest()
|
||||
->paginate($request->per_page ?? 20)->appends($request->query());
|
||||
|
||||
@@ -73,4 +85,55 @@ public function exportCsv()
|
||||
{
|
||||
return Excel::download(new ExportComboProduct, 'combo-products.csv');
|
||||
}
|
||||
|
||||
public function exportPdf(Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$branchId = null;
|
||||
if (moduleCheck('MultiBranchAddon')) {
|
||||
$branchId = $user->branch_id ?? $user->active_branch_id;
|
||||
}
|
||||
|
||||
$search = $request->input('search');
|
||||
|
||||
$combo_products = Product::with(['combo_products.stock.product', 'unit:id,unitName', 'category:id,categoryName'])
|
||||
->where('business_id', auth()->user()->business_id)
|
||||
->where('product_type', 'combo')
|
||||
->withCount('combo_products as total_combo_products')
|
||||
->when($search, function ($q) use ($search) {
|
||||
$q->where(function ($q) use ($search) {
|
||||
$q->where('productName', 'like', '%' . $search . '%')
|
||||
->orWhere('productCode', 'like', '%' . $search . '%')
|
||||
->orWhereHas('category', function ($q) use ($search) {
|
||||
$q->where('categoryName', 'like', '%' . $search . '%');
|
||||
})
|
||||
->orWhereHas('unit', function ($q) use ($search) {
|
||||
$q->where('unitName', 'like', '%' . $search . '%');
|
||||
});
|
||||
});
|
||||
})
|
||||
->when($branchId, function ($q) use ($branchId) {
|
||||
$q->whereHas('combo_products.stock', function ($q) use ($branchId) {
|
||||
$q->where('branch_id', $branchId);
|
||||
});
|
||||
})
|
||||
|
||||
->latest()
|
||||
->limit($request->per_page ?? 20)->get();
|
||||
|
||||
$combo_products->transform(function ($product) {
|
||||
$product->total_stock = $product->combo_products->sum(function ($combo) {
|
||||
return optional($combo->stock)->productStock ?? 0;
|
||||
});
|
||||
|
||||
$product->total_cost = $product->combo_products->sum(function ($combo) {
|
||||
return ($combo->quantity ?? 0) * ($combo->purchase_price ?? 0);
|
||||
});
|
||||
|
||||
return $product;
|
||||
});
|
||||
|
||||
return PdfService::render('business::products.combo-products.pdf', compact('combo_products'),'combo-products.pdf');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user