update marketing
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-14 11:55:22 +07:00
parent f80fcc4c1b
commit 05fd3230b8
448 changed files with 17545 additions and 5128 deletions

View File

@@ -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');
}
}