migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\PaymentType;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportBalanceSheet implements FromView
{
public function view(): View
{
$businessId = auth()->user()->business_id;
// PRODUCT
$productQuery = Product::select('id', 'business_id', 'productName', 'product_type', 'created_at')
->with(['stocks:id,business_id,product_id,productStock,productPurchasePrice', 'combo_products.stock'])
->where('business_id', $businessId);
$products = $productQuery->get()
->map(function ($item) {
$item->source = 'product';
return $item;
});
// BANK
$bankQuery = PaymentType::where('business_id', $businessId);
$banks = $bankQuery->get()
->map(function ($item) {
$item->source = 'bank';
return $item;
});
$asset_datas = $products->merge($banks);
// TOTAL STOCK VALUE
$total_stock_value = 0;
foreach ($products as $product) {
if (in_array($product->product_type, ['single', 'variant'])) {
foreach ($product->stocks as $stock) {
$total_stock_value += $stock->productStock * $stock->productPurchasePrice;
}
}
if ($product->product_type === 'combo') {
foreach ($product->combo_products as $combo) {
$childStock = $combo->stock;
if ($childStock) {
$total_stock_value += ($childStock->productStock / $combo->quantity) * $combo->purchase_price;
}
}
}
}
$totalBankBalance = $banks->sum('balance');
$total_asset = $total_stock_value + $totalBankBalance;
return view('business::balance-sheets.excel-csv', compact('asset_datas', 'total_asset'));
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Sale;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportBillWisePofit implements FromView
{
public function view(): View
{
$profits = Sale::with('party:id,name')
->where('business_id', auth()->user()->business_id)
->latest()
->get();
return view('business::bill-wise-profits.excel-csv', compact('profits'));
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Transaction;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportCashFlowReport implements FromView
{
public function view(): View
{
$cash_flows = Transaction::with([
'paymentType:id,name',
'sale:id,party_id',
'sale.party:id,name',
'saleReturn:id,sale_id',
'purchase:id,party_id',
'purchase.party:id,name',
'purchaseReturn:id,purchase_id',
'dueCollect:id,party_id',
'dueCollect.party:id,name',
])
->where('business_id', auth()->user()->business_id)
->whereIn('type', ['debit', 'credit'])
->latest()
->get();
$opening_balance = 0;
return view('business::cash-flow.excel-csv', compact('cash_flows', 'opening_balance'));
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportComboProduct implements FromView
{
public function view(): View
{
$combo_products = Product::with(['combo_products', 'unit:id,unitName', 'category:id,categoryName'])
->where('business_id', auth()->user()->business_id)
->where('product_type', 'combo')
->withCount('combo_products as total_combo_products')
->latest()
->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 view('business::products.combo-products.excel-csv', [
'combo_products' => $combo_products
]);
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportComboProductReport implements FromView
{
public function view(): View
{
$combo_products = Product::with(['combo_products', 'unit:id,unitName', 'category:id,categoryName'])
->where('business_id', auth()->user()->business_id)
->where('product_type', 'combo')
->withCount('combo_products as total_combo_products')
->latest()
->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 view('business::reports.combo-products.excel-csv', [
'combo_products' => $combo_products
]);
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportCurrentStock implements FromView
{
public function view(): View
{
$query = Product::with('stocks')
->where('product_type', '!=', 'combo')
->where('business_id', auth()->user()->business_id);
if (request('alert_qty')) {
$products = $query->get()->filter(function ($product) {
$totalStock = $product->stocks->sum('productStock');
return $totalStock <= $product->alert_qty;
});
} else {
$products = $query->latest()->get();
}
return view('business::stocks.excel-csv', [
'products' => $products
]);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportCurrentStockReport implements FromView
{
public function view(): View
{
return view('business::reports.stocks.excel-csv', [
'stock_reports' => Product::with('stocks')
->where('business_id', auth()->user()->business_id)
->where('product_type', '!=', 'combo')
->withSum('stocks', 'productStock')
->latest()
->get()
]);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportCustomerLedger implements FromView
{
public function view(): View
{
$customers = Party::with('sales')
->where('business_id', auth()->user()->business_id)
->where('type', '!=', 'Supplier')
->latest()
->get();
$totalAmount = $customers->sum(function ($customer) {
return $customer->sales?->sum('totalAmount') ?? 0;
});
$totalPaid = $customers->sum(function ($customer) {
return $customer->sales?->sum('paidAmount') ?? 0;
});
$totalDue = $customers->sum(function ($customer) {
return $customer->sales?->sum('dueAmount') ?? 0;
});
return view('business::party-reports.customer-ledger.excel-csv', compact('customers', 'totalAmount', 'totalPaid', 'totalDue'));
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Transaction;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportDayBookReport implements FromView
{
public function view(): View
{
$day_books = Transaction::with([
'paymentType:id,name',
'sale:id,user_id,party_id,totalAmount',
'sale.party:id,name',
'sale.user:id,name',
'saleReturn:id,sale_id',
'purchase:id,user_id,party_id,totalAmount',
'purchase.party:id,name',
'purchase.user:id,name',
'purchaseReturn:id,purchase_id',
'dueCollect:id,user_id,party_id,totalDue',
'dueCollect.party:id,name',
'dueCollect.user:id,name',
])
->where('business_id', auth()->user()->business_id)
->whereIn('type', ['debit', 'credit'])
->latest()
->get();
return view('business::day-book.excel-csv', compact('day_books'));
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\SaleDetails;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportDiscountProduct implements FromView
{
public function view(): View
{
$discount_products = SaleDetails::with('product:id,productName,productCode')
->whereHas('product', function ($q) {
$q->where('business_id', auth()->user()->business_id);
})
->where('discount', '>', 0)
->get();
return view('business::reports.discount-products.excel-csv', compact('discount_products'));
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportDue implements FromView
{
public function view(): View
{
$user = auth()->user();
$businessId = $user->business_id;
$activeBranch = $user->active_branch;
$query = Party::where('business_id', $businessId)
->where('type', '!=', 'Supplier')
->with('sales_dues')
->latest();
if ($activeBranch) {
$query->whereHas('sales_dues', function ($q) use ($activeBranch) {
$q->where('branch_id', $activeBranch->id)
->where('dueAmount', '>', 0);
});
} else {
$query->where('due', '>', 0);
}
$parties = $query->get();
if ($activeBranch) {
$parties->transform(function ($supplier) use ($activeBranch) {
$supplier->due = $supplier->sales_dues
->where('branch_id', $activeBranch->id)
->sum('dueAmount');
return $supplier;
})->filter(fn($supplier) => $supplier->due > 0);
}
return view('business::reports.due.excel-csv', [
'parties' => $parties
]);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Expense;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportExpense implements FromView
{
public function view(): View
{
return view('business::reports.expense.excel-csv', [
'expense_reports' => Expense::with('category:id,categoryName', 'payment_type:id,name', 'branch:id,name', 'transactions')->where('business_id', auth()->user()->business_id)->latest()->get()
]);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportExpiredProduct implements FromView
{
public function view(): View
{
$expired_products = Product::with('stocks', 'unit:id,unitName', 'brand:id,brandName', 'category:id,categoryName')
->where('business_id', auth()->user()->business_id)
->withSum('stocks as total_stock', 'productStock')
->whereHas('stocks', function ($query) {
$query->whereDate('expire_date', '<', today())->where('productStock', '>', 0);
})
->latest()->get();
return view('business::expired-products.excel-csv', [
'expired_products' => $expired_products
]);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportExpiredProductReport implements FromView
{
public function view(): View
{
return view('business::reports.expired-products.excel-csv', [
'expired_products' => Product::with('unit:id,unitName', 'brand:id,brandName', 'category:id,categoryName', 'stocks')
->withSum('stocks', 'productStock')
->where('business_id', auth()->user()->business_id)
->whereHas('stocks', function ($query) {
$query->whereDate('expire_date', '<', today())->where('productStock', '>', 0);
})
->latest()
->get()
]);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Income;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportIncome implements FromView
{
public function view(): View
{
return view('business::reports.income.excel-csv', [
'income_reports' => Income::with('category:id,categoryName', 'payment_type:id,name', 'branch:id,name', 'transactions')->where('business_id', auth()->user()->business_id)->latest()->get()
]);
}
}

View File

@@ -0,0 +1,131 @@
<?php
namespace Modules\Business\App\Exports;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromView;
class ExportLossProfitHistory implements FromView
{
public function view(): View
{
$user = auth()->user();
$businessId = $user->business_id;
$branchId = null;
if (moduleCheck('MultiBranchAddon')) {
$branchId = $user->branch_id ?? $user->active_branch_id;
}
// SALES
$dailySales = DB::table('sales')
->select(
DB::raw('DATE(saleDate) as date'),
DB::raw('SUM(actual_total_amount) as total_sales'),
DB::raw('SUM(lossProfit) as total_sale_income')
)
->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId))
->groupBy(DB::raw('DATE(saleDate)'))
->get();
$sale_datas = $dailySales->map(fn($sale) => (object)[
'type' => 'Sale',
'date' => $sale->date,
'total_sales' => $sale->total_sales,
'total_incomes' => $sale->total_sale_income,
]);
// INCOME
$dailyIncomes = DB::table('incomes')
->select(
DB::raw('DATE(incomeDate) as date'),
DB::raw('SUM(amount) as total_incomes')
)
->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId))
->groupBy(DB::raw('DATE(incomeDate)'))
->get();
$income_datas = $dailyIncomes->map(fn($income) => (object)[
'type' => 'Income',
'date' => $income->date,
'total_incomes' => $income->total_incomes,
]);
// MERGE SALE + INCOME
$mergedIncomeSaleData = collect();
$allDates = $dailySales->pluck('date')->merge($dailyIncomes->pluck('date'))->unique()->sort();
foreach ($allDates as $date) {
if ($income = $income_datas->firstWhere('date', $date)) {
$mergedIncomeSaleData->push($income);
}
if ($sale = $sale_datas->firstWhere('date', $date)) {
$mergedIncomeSaleData->push($sale);
}
}
// PAYROLL
$dailyPayrolls = collect();
if (moduleCheck('HrmAddon')) {
$dailyPayrolls = DB::table('payrolls')
->select(
DB::raw('DATE(date) as date'),
DB::raw('SUM(amount) as total_payrolls')
)
->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId))
->groupBy(DB::raw('DATE(date)'))
->get();
}
// EXPENSES
$dailyExpenses = DB::table('expenses')
->select(
DB::raw('DATE(expenseDate) as date'),
DB::raw('SUM(amount) as total_expenses_only')
)
->where('business_id', $businessId)
->when($branchId, fn($q) => $q->where('branch_id', $branchId))
->groupBy(DB::raw('DATE(expenseDate)'))
->get();
$mergedExpenseData = collect();
$allExpenseDates = $dailyExpenses->pluck('date')->merge($dailyPayrolls->pluck('date'))->unique()->sort();
foreach ($allExpenseDates as $date) {
if ($expense = $dailyExpenses->firstWhere('date', $date)) {
$mergedExpenseData->push((object)[
'type' => 'Expense',
'date' => $date,
'total_expenses' => $expense->total_expenses_only,
]);
}
if ($payroll = $dailyPayrolls->firstWhere('date', $date)) {
$mergedExpenseData->push((object)[
'type' => 'Payroll',
'date' => $date,
'total_expenses' => $payroll->total_payrolls,
]);
}
}
// SUMMARY
$grossSaleProfit = $sale_datas->sum('total_sales');
$grossIncomeProfit = $income_datas->sum('total_incomes') + $sale_datas->sum('total_incomes');
$totalExpenses = $mergedExpenseData->sum('total_expenses');
$netProfit = $grossIncomeProfit - $totalExpenses;
return view(
'business::loss-profit-histories.excel-csv',
compact(
'mergedIncomeSaleData',
'mergedExpenseData',
'grossSaleProfit',
'grossIncomeProfit',
'totalExpenses',
'netProfit'
)
);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportPartyLossProfit implements FromView
{
public function view(): View
{
$parties = Party::with('sales')
->where('business_id', auth()->user()->business_id)
->where('type', '!=', 'Supplier')
->latest()
->get();
return view('business::party-reports.loss-profit.excel-csv', compact('parties'));
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProduct implements FromView
{
public function view(): View
{
$products = Product::with('unit:id,unitName', 'brand:id,brandName', 'category:id,categoryName')->where('business_id', auth()->user()->business_id)->withSum('stocks as total_stock', 'productStock')->latest()->get();
return view('business::products.excel-csv', [
'products' => $products
]);
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\SaleDetails;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductLossProfit implements FromView
{
public function view(): View
{
$branchId = moduleCheck('MultiBranchAddon') ? auth()->user()->branch_id ?? auth()->user()->active_branch_id : null;
$product_lossProfits = SaleDetails::with('product:id,productName,productCode')
->whereHas('product', function ($q) {
$q->where('business_id', auth()->user()->business_id);
})
->when($branchId, function ($q) use ($branchId) {
$q->whereHas('sale', function ($sale) use ($branchId) {
$sale->where('branch_id', $branchId);
});
})
->select(
'product_id',
DB::raw('SUM(CASE WHEN lossProfit > 0 THEN lossProfit ELSE 0 END) as profit'),
DB::raw('SUM(CASE WHEN lossProfit < 0 THEN lossProfit ELSE 0 END) as loss')
)
->groupBy('product_id')
->get();
return view('business::reports.product-loss-profit.excel-csv', compact('product_lossProfits'));
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductPurchaseHistoryDetailReport implements FromView
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function view(): View
{
$product = Product::select('id', 'business_id', 'productName')
->where('business_id', auth()->user()->business_id)
->findOrFail($this->id);
$purchaseDetailsQuery = $product->purchaseDetails()
->with('purchase:id,invoiceNumber,purchaseDate')
->select('id', 'purchase_id', 'product_id', 'quantities', 'productPurchasePrice');
$purchaseDetails = $purchaseDetailsQuery->get();
return view('business::product-purchase-history-report.excel-csv-detail', compact('product', 'purchaseDetails'));
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductPurchaseHistoryReport implements FromView
{
public function view(): View
{
$businessId = auth()->user()->business_id;
$productQuery = Product::with('saleDetails', 'purchaseDetails', 'stocks', 'combo_products')->where('business_id', $businessId);
$products = $productQuery->get();
$total_purchase_qty = $products->sum(function ($product) {
return $product->purchaseDetails->sum('quantities');
});
$total_sale_qty = $products->sum(function ($product) {
return $product->saleDetails->sum('quantities');
});
return view('business::product-purchase-history-report.excel-csv', compact('products', 'total_purchase_qty', 'total_sale_qty'));
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use App\Models\PurchaseDetails;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductPurchaseReport implements FromView
{
public function view(): View
{
$product_purchases = PurchaseDetails::with('product:id,productName', 'purchase:id,party_id,invoiceNumber,purchaseDate', 'purchase.party:id,name')
->whereHas('purchase', function ($q) {
$q->where('business_id', auth()->user()->business_id);
})
->get();
return view('business::reports.product-purchase.excel-csv', compact('product_purchases'));
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductSaleHistoryDetailReport implements FromView
{
protected $id;
public function __construct($id)
{
$this->id = $id;
}
public function view(): View
{
$product = Product::select('id', 'business_id', 'productName')
->where('business_id', auth()->user()->business_id)
->findOrFail($this->id);
$saleDetailsQuery = $product->saleDetails()
->with('sale:id,party_id,invoiceNumber,saleDate', 'sale.party:id,name')
->select('id', 'sale_id', 'product_id', 'quantities', 'lossprofit', 'price', 'productPurchasePrice');
$saleDetails = $saleDetailsQuery->get();
return view('business::product-sale-history-report.excel-csv-detail', compact('product', 'saleDetails'));
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Product;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductSaleHistoryReport implements FromView
{
public function view(): View
{
$businessId = auth()->user()->business_id;
$productQuery = Product::with('saleDetails', 'purchaseDetails', 'stocks', 'combo_products')->where('business_id', $businessId);
$products = $productQuery->get();
$total_single_sale_price = $products->sum(function ($product) {
return $product->saleDetails->sum('price');
});
$total_combo_sale_price = $products->sum('productSalePrice');
$total_sale_price = $total_single_sale_price + $total_combo_sale_price;
$total_purchase_qty = $products->sum(function ($product) {
return $product->purchaseDetails->sum('quantities');
});
$total_sale_qty = $products->sum(function ($product) {
return $product->saleDetails->sum('quantities');
});
return view('business::product-sale-history-report.excel-csv', compact('products', 'total_purchase_qty', 'total_sale_qty', 'total_sale_price'));
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Sale;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportProductSaleReport implements FromView
{
public function view(): View
{
$product_sales = Sale::with('details:id,sale_id,product_id,quantities,price', 'details.product:id,productName', 'party:id,name')
->where('business_id', auth()->user()->business_id)
->latest()
->get();
return view('business::reports.product-sale.excel-csv', compact('product_sales'));
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Purchase;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportPurchaseReturn implements FromView
{
public function view(): View
{
$purchases = Purchase::with([
'user:id,name',
'branch:id,name',
'party:id,name,email,phone,type',
'details:id,purchase_id,product_id,productPurchasePrice,quantities',
'details.product:id,productName,category_id',
'details.product.category:id,categoryName',
'purchaseReturns' => function ($query) {
$query->withSum('details as total_return_amount', 'return_amount');
}
])
->where('business_id', auth()->user()->business_id)
->whereHas('purchaseReturns')
->latest()
->get();
return view('business::reports.purchase-return.excel-csv', compact('purchases'));
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Sale;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportSaleReport implements FromView
{
public function view(): View
{
$sales = Sale::with('user:id,name', 'party:id,name,email,phone,type', 'payment_type:id,name', 'branch:id,name', 'transactions')->where('business_id', auth()->user()->business_id)
->latest()
->get();
return view('business::reports.sales.excel', compact('sales'));
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Sale;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportSalesReturn implements FromView
{
public function view(): View
{
$sales = Sale::with([
'user:id,name',
'party:id,name',
'branch:id,name',
'details',
'details.product:id,productName,category_id',
'details.product.category:id,categoryName',
'saleReturns' => function ($query) {
$query->withSum('details as total_return_amount', 'return_amount')
->with('branch:id,name');
}
])
->where('business_id', auth()->user()->business_id)
->whereHas('saleReturns')
->latest()
->get();
return view('business::reports.sales-return.excel-csv', compact('sales'));
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Business\App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Illuminate\Contracts\View\View;
class ExportSingleCustomerLedger implements FromView
{
public $ledger;
public $party;
public function __construct($ledger, $party)
{
$this->ledger = $ledger;
$this->party = $party;
}
public function view(): View
{
return view('business::party-reports.customer-ledger.show-details.excel-csv', [
'ledger' => $this->ledger,
'party' => $this->party,
]);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Business\App\Exports;
use Maatwebsite\Excel\Concerns\FromView;
use Illuminate\Contracts\View\View;
class ExportSingleSupplierLedger implements FromView
{
public $ledger;
public $party;
public function __construct($ledger, $party)
{
$this->ledger = $ledger;
$this->party = $party;
}
public function view(): View
{
return view('business::party-reports.supplier-ledger.show-details.excel-csv', [
'ledger' => $this->ledger,
'party' => $this->party,
]);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\PlanSubscribe;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportSubscription implements FromView
{
public function view(): View
{
return view('business::reports.subscription-reports.excel-csv', [
'subscribers' => PlanSubscribe::with(['plan:id,subscriptionName','business:id,companyName,business_category_id,pictureUrl','business.category:id,name','gateway:id,name'])->where('business_id', auth()->user()->business_id)->latest()->get()
]);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportSupplierDue implements FromView
{
public function view(): View
{
$user = auth()->user();
$businessId = $user->business_id;
$activeBranch = $user->active_branch;
$query = Party::where('business_id', $businessId)
->where('type', 'Supplier')
->with('purchases_dues')
->latest();
if ($activeBranch) {
$query->whereHas('purchases_dues', function ($q) use ($activeBranch) {
$q->where('branch_id', $activeBranch->id)
->where('dueAmount', '>', 0);
});
} else {
$query->where('due', '>', 0);
}
$parties = $query->get();
if ($activeBranch) {
$parties->transform(function ($supplier) use ($activeBranch) {
$supplier->due = $supplier->purchases_dues
->where('branch_id', $activeBranch->id)
->sum('dueAmount');
return $supplier;
})->filter(fn($supplier) => $supplier->due > 0);
}
return view('business::reports.supplier-due.excel-csv', [
'parties' => $parties
]);
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportSupplierLedger implements FromView
{
public function view(): View
{
$suppliers = Party::with('purchases')
->where('business_id', auth()->user()->business_id)
->where('type', '=', 'Supplier')
->latest()
->get();
$totalAmount = $suppliers->sum(function ($customer) {
return $customer->purchases?->sum('totalAmount') ?? 0;
});
$totalPaid = $suppliers->sum(function ($customer) {
return $customer->purchases?->sum('paidAmount') ?? 0;
});
$totalDue = $suppliers->sum(function ($customer) {
return $customer->purchases?->sum('dueAmount') ?? 0;
});
return view('business::party-reports.supplier-ledger.excel-csv', compact('suppliers', 'totalAmount', 'totalPaid', 'totalDue'));
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTopCustomer implements FromView
{
public function view(): View
{
$customers = Party::with('sales')
->where('business_id', auth()->user()->business_id)
->where('type', '!=', 'Supplier')
->whereHas('sales')
->withCount('sales')
->withSum('sales', 'totalAmount')
->orderByDesc('sales_count')
->orderByDesc('sales_sum_total_amount')
->take(5)
->get();
return view('business::party-reports.top-customers.excel-csv', compact('customers'));
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\SaleDetails;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTopProduct implements FromView
{
public function view(): View
{
$branchId = moduleCheck('MultiBranchAddon') ? auth()->user()->branch_id ?? auth()->user()->active_branch_id : null;
$top_products = SaleDetails::with('product:id,productName,productCode')
->whereHas('product', function ($q) {
$q->where('business_id', auth()->user()->business_id);
})
->when($branchId, function ($q) use ($branchId) {
$q->whereHas('sale', function ($sale) use ($branchId) {
$sale->where('branch_id', $branchId);
});
})
->select(
'product_id',
DB::raw('SUM(quantities) as total_sold_qty'),
DB::raw('SUM(price * quantities) as total_sale_amount')
)
->groupBy('product_id')
->orderByDesc('total_sold_qty')
->take(5)
->get();
return view('business::reports.top-products.excel-csv', compact('top_products'));
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Party;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTopSupplier implements FromView
{
public function view(): View
{
$suppliers = Party::with('purchases')
->where('business_id', auth()->user()->business_id)
->where('type', '=', 'Supplier')
->whereHas('purchases')
->withCount('purchases')
->withSum('purchases', 'totalAmount')
->orderByDesc('purchases_count')
->orderByDesc('purchases_sum_total_amount')
->take(5)
->get();
return view('business::party-reports.top-suppliers.excel-csv', compact('suppliers'));
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\DueCollect;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTransaction implements FromView
{
public function view(): View
{
return view('business::reports.transaction-history.excel-csv', [
'transactions' => DueCollect::where('business_id', auth()->user()->business_id)->with('party:id,name,type', 'payment_type:id,name', 'transactions')->latest()->get()
]);
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Transaction;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTransactionReport implements FromView
{
public function view(): View
{
$transactions = Transaction::with('paymentType')
->where('business_id', auth()->user()->business_id)
->latest()
->get();
return view('business::transactions.excel-csv', compact('transactions'));
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Transfer;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTransfer implements FromView
{
public function view(): View
{
return view('business::transfers.excel-csv', [
'transfers' => Transfer::with(['fromWarehouse:id,name', 'toWarehouse:id,name', 'toBranch:id,name', 'fromBranch:id,name', 'transferProducts'])->where('business_id', auth()->user()->business_id)->latest()->get()
]);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Modules\Business\App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportVatReport implements FromView
{
protected $sales, $purchases, $vats, $salesVatTotals, $purchasesVatTotals;
public function __construct($sales, $purchases, $vats, $salesVatTotals, $purchasesVatTotals)
{
$this->sales = $sales;
$this->purchases = $purchases;
$this->vats = $vats;
$this->salesVatTotals = $salesVatTotals;
$this->purchasesVatTotals = $purchasesVatTotals;
}
public function view(): View
{
return view('business::reports.vats.excel', [
'sales' => $this->sales,
'purchases' => $this->purchases,
'vats' => $this->vats,
'salesVatTotals' => $this->salesVatTotals,
'purchasesVatTotals' => $this->purchasesVatTotals,
]);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Modules\Business\App\Exports;
use App\Models\Purchase;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class PurchaseExport implements FromView
{
public function view(): View
{
$purchases = Purchase::with('user:id,name', 'party:id,name,email,phone,type', 'payment_type:id,name', 'branch:id,name', 'transactions')
->where('business_id', auth()->user()->business_id)
->latest()
->get();
return view('business::reports.purchase.excel-csv', compact('purchases'));
}
}