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,7 +5,6 @@
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Party;
use App\Models\Sale;
use App\Services\PdfService;
use Maatwebsite\Excel\Facades\Excel;
use Modules\Business\App\Exports\ExportPartyLossProfit;
@@ -14,12 +13,6 @@ class AcnooPartyLossProfitController extends Controller
{
public function index(Request $request)
{
$sale = Sale::where('business_id', auth()->user()->business_id)->whereNotNull('party_id')->get();
$totalAmount = $sale->sum('totalAmount');
$totalProfit = $sale->where('lossProfit', '>', 0)->sum('lossProfit') ?? 0;
$totalLoss = $sale->where('lossProfit', '<', 0)->sum('lossProfit') ?? 0;
$parties = Party::with('sales')
->where('business_id', auth()->user()->business_id)
->where('type', '!=', 'Supplier')
@@ -32,13 +25,20 @@ public function index(Request $request)
->paginate($request->per_page ?? 20)
->appends($request->query());
$totalSaleAmount = $parties->sum(fn($party) => $party->sales?->sum('totalAmount') ?? 0);
$totalProfit = $parties->sum(fn($party) => $party->sales?->where('lossProfit', '>', 0)->sum('lossProfit') ?? 0);
$totalLoss = $parties->sum(fn($party) => $party->sales?->where('lossProfit', '<', 0)->sum('lossProfit') ?? 0);
if ($request->ajax()) {
return response()->json([
'data' => view('business::party-reports.loss-profit.datas', compact('parties'))->render()
'data' => view('business::party-reports.loss-profit.datas', compact('parties', 'totalSaleAmount', 'totalProfit', 'totalLoss'))->render(),
'totalSaleAmount' => currency_format($totalSaleAmount, currency: business_currency()),
'totalProfit' => currency_format($totalProfit, currency: business_currency()),
'totalLoss' => currency_format($totalLoss, currency: business_currency()),
]);
}
return view('business::party-reports.loss-profit.index', compact('parties', 'totalAmount', 'totalProfit', 'totalLoss'));
return view('business::party-reports.loss-profit.index', compact('parties', 'totalSaleAmount', 'totalProfit', 'totalLoss'));
}
public function exportExcel()
@@ -51,18 +51,24 @@ public function exportCsv()
return Excel::download(new ExportPartyLossProfit, 'party-loss-profit.csv');
}
public function exportPdf()
public function exportPdf(Request $request)
{
$parties = Party::with('sales')
->where('business_id', auth()->user()->business_id)
->where('type', '!=', 'Supplier')
->when($request->search, function ($query) use ($request) {
$query->where(function ($q) use ($request) {
$q->where('name', 'like', '%' . $request->search . '%');
});
})
->latest()
->limit($request->per_page ?? 20)
->get();
return PdfService::render('business::party-reports.loss-profit.pdf', compact('parties'),'party-loss-profit-report.pdf');
}
public function view($id)
public function view(string $id)
{
$party = Party::with('sales.details', 'sales.details.product')
->where('id', $id)