121 lines
3.2 KiB
PHP
121 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Connector\Http\Controllers\Api\V2;
|
|
|
|
use App\Services\Api\BusinessContextService;
|
|
use App\Transaction;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class ModuleController extends BaseController
|
|
{
|
|
public function __construct(protected BusinessContextService $contextService)
|
|
{
|
|
}
|
|
|
|
public function manufacturingRecipes(Request $request)
|
|
{
|
|
return $this->moduleList($request, 'mfg_recipes');
|
|
}
|
|
|
|
public function manufacturingProduction(Request $request)
|
|
{
|
|
return $this->transactionsBySubType($request, 'production_purchase');
|
|
}
|
|
|
|
public function repairJobs(Request $request)
|
|
{
|
|
return $this->transactionsBySubType($request, 'repair');
|
|
}
|
|
|
|
public function projects(Request $request)
|
|
{
|
|
return $this->moduleList($request, 'pjt_projects');
|
|
}
|
|
|
|
public function tasks(Request $request)
|
|
{
|
|
return $this->moduleList($request, 'pjt_project_tasks');
|
|
}
|
|
|
|
public function accountingAccounts(Request $request)
|
|
{
|
|
return $this->moduleList($request, 'accounting_accounts');
|
|
}
|
|
|
|
public function assets(Request $request)
|
|
{
|
|
return $this->moduleList($request, 'assets');
|
|
}
|
|
|
|
public function inventoryCounts(Request $request)
|
|
{
|
|
$business_id = $this->contextService->getBusinessId($request);
|
|
|
|
if (! Schema::hasTable('inventory')) {
|
|
return $this->success([]);
|
|
}
|
|
|
|
$items = DB::table('inventory')
|
|
->join('business_locations', 'inventory.branch_id', '=', 'business_locations.id')
|
|
->where('business_locations.business_id', $business_id)
|
|
->select('inventory.*', 'business_locations.name as branch_name')
|
|
->orderByDesc('inventory.id')
|
|
->limit(100)
|
|
->get();
|
|
|
|
return $this->success($items);
|
|
}
|
|
|
|
public function woocommerceSettings(Request $request)
|
|
{
|
|
$business_id = $this->contextService->getBusinessId($request);
|
|
|
|
if (! Schema::hasTable('woocommerce_settings')) {
|
|
return $this->success([]);
|
|
}
|
|
|
|
$settings = DB::table('woocommerce_settings')
|
|
->where('business_id', $business_id)
|
|
->get();
|
|
|
|
return $this->success($settings);
|
|
}
|
|
|
|
public function spreadsheets(Request $request)
|
|
{
|
|
return $this->moduleList($request, 'sheet_spreadsheets');
|
|
}
|
|
|
|
protected function moduleList(Request $request, string $table)
|
|
{
|
|
if (! Schema::hasTable($table)) {
|
|
return $this->success([]);
|
|
}
|
|
|
|
$business_id = $this->contextService->getBusinessId($request);
|
|
|
|
$items = DB::table($table)
|
|
->where('business_id', $business_id)
|
|
->orderByDesc('id')
|
|
->limit(100)
|
|
->get();
|
|
|
|
return $this->success($items);
|
|
}
|
|
|
|
protected function transactionsBySubType(Request $request, string $sub_type)
|
|
{
|
|
$business_id = $this->contextService->getBusinessId($request);
|
|
|
|
$items = Transaction::where('business_id', $business_id)
|
|
->where('sub_type', $sub_type)
|
|
->orderBy('transaction_date', 'desc')
|
|
->limit(100)
|
|
->get();
|
|
|
|
return $this->success($items);
|
|
}
|
|
}
|