### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### POST /admin/items Source: https://context7.com/noorfikri/kp_asri/llms.txt Creates a new product item with multiple stock combinations of sizes and colors. It validates input data, handles image uploads, and initializes stock levels for all specified size-color combinations. ```APIDOC ## POST /admin/items ### Description Creates a new product item with multiple stock combinations of sizes and colors, validates input data, handles image upload, and initializes stock levels for all specified size-color combinations. ### Method POST ### Endpoint /admin/items ### Parameters #### Query Parameters None #### Request Body - **name** (string) - Required - The name of the item. - **category_id** (integer) - Required - The ID of the item's category. - **brand_id** (integer) - Optional - The ID of the item's brand. - **price** (numeric) - Required - The price of the item. - **description** (string) - Optional - A description of the item. - **note** (string) - Optional - Additional notes about the item. - **image** (file) - Optional - The product image file. - **stocks** (array) - Required - An array of stock combinations. - **stocks[].size_id** (integer) - Required - The ID of the size. - **stocks[].colour_id** (integer) - Required - The ID of the color. - **stocks[].stock** (integer) - Required - The stock quantity for this combination. ### Request Example ```json { "name": "T-Shirt Basic", "category_id": 1, "brand_id": 2, "price": 150000, "description": "Cotton basic t-shirt", "note": "Available in multiple colors", "image": "", "stocks": [ {"size_id": 1, "colour_id": 1, "stock": 50}, {"size_id": 1, "colour_id": 2, "stock": 30}, {"size_id": 2, "colour_id": 1, "stock": 40} ] } ``` ### Response #### Success Response (Redirect) Redirects to the items index page with a success status message. #### Response Example (Redirect response with status message) #### Error Response (400/422) Returns an error message if validation fails or an exception occurs. ```json { "message": "The given data was invalid.", "errors": { "field_name": ["error message"] } } ``` ``` -------------------------------- ### Create Staff Account - PHP Source: https://context7.com/noorfikri/kp_asri/llms.txt Creates a new user account, validates input, handles profile picture uploads, and enforces authorization policies using PHP. It requires authentication and handles potential exceptions during account creation. The response is a redirect with a status or error message. ```php // POST /admin/users // Request payload example $request = [ 'name' => 'John Doe', 'email' => 'john.doe@example.com', 'contact_number' => '+62812345678', 'address' => 'Jl. Example No. 123, Jakarta', 'password' => 'securepassword123', 'category' => 'staff', // or 'owner' 'image' => $uploadedFile // Profile picture ]; // Controller: UserController@store public function store() { $this->authorize('userManagementAccess', auth()->user()); $validator = Validator::make(request()->all(), [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users,email', 'contact_number' => 'required|string|max:50', 'address' => 'required|string|max:255', 'password' => 'required|string|min:8', 'category' => 'required|in:staff,owner', 'image' => 'nullable|image|max:2048', ]); if ($validator->fails()) { return redirect()->route('users.index') ->withErrors($validator) ->withInput(); } try { $user = new User(); $user->name = request('name'); $user->email = request('email'); $user->contact_number = request('contact_number'); $user->address = request('address'); $user->password = bcrypt(request('password')); $user->category = request('category'); $user->remember_token = Str::random(10); if (request()->hasFile('image')) { $user->profile_picture = App::call([new FileUploadService, 'uploadFile'], [ 'file' => request()->file('image'), 'filename' => $user->name, 'folder' => 'user' ]); } $user->save(); return redirect()->route('users.index') ->with('status', 'Account created successfully: ' . $user->name); } catch (Exception $e) { return redirect()->back()->with('error', $e->getMessage()); } } // Expected response: Redirect with success message // Authorization: Only users with 'userManagementAccess' can execute // Database changes: New record in users table with bcrypt password ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Create Item with Stock Variants - Laravel Source: https://context7.com/noorfikri/kp_asri/llms.txt This function creates a new product item in the inventory system, including multiple stock variants based on size and color. It validates incoming data, handles image uploads using a FileUploadService, and creates corresponding entries in the items and items_stock tables. Error handling is included to log and report any exceptions during the process. ```php // POST /admin/items // Request payload example $request = [ 'name' => 'T-Shirt Basic', 'category_id' => 1, 'brand_id' => 2, 'price' => 150000, 'description' => 'Cotton basic t-shirt', 'note' => 'Available in multiple colors', 'image' => $uploadedFile, // UploadedFile instance 'stocks' => [ ['size_id' => 1, 'colour_id' => 1, 'stock' => 50], // Small, Black ['size_id' => 1, 'colour_id' => 2, 'stock' => 30], // Small, White ['size_id' => 2, 'colour_id' => 1, 'stock' => 40], // Medium, Black ] ]; // Controller: ItemController@store public function store(\Illuminate\Http\Request $request, FileUploadService $fileUpload) { $validated = $request->validate([ 'name' => 'required|string|max:255', 'category_id' => 'required|exists:categories,id', 'brand_id' => 'nullable|exists:brands,id', 'price' => 'required|numeric|min:0', 'stocks' => 'required|array|min:1', 'stocks.*.size_id' => 'required|exists:sizes,id', 'stocks.*.colour_id' => 'required|exists:colours,id', 'stocks.*.stock' => 'required|integer|min:0', ]); try { $item = new Item(); $item->fill($validated); if ($request->hasFile('image')) { $item->image = $fileUpload->uploadFile( $request->file('image'), $item->name, 'item' ); } $item->save(); foreach ($validated['stocks'] as $stockCombo) { ItemStock::create([ 'item_id' => $item->id, 'size_id' => $stockCombo['size_id'], 'colour_id' => $stockCombo['colour_id'], 'stock' => $stockCombo['stock'], ]); } return redirect()->route('items.index') ->with('status', 'Item created successfully'); } catch (\Exception $e) { Log::error('Item store failed', ['error' => $e->getMessage()]); return redirect()->back()->with('error', $e->getMessage()); } } // Expected response: Redirect to items index with success message // Database changes: New record in items table + multiple records in items_stock table ``` -------------------------------- ### Untitled No description -------------------------------- ### Supplier Management - Register New Supplier Source: https://context7.com/noorfikri/kp_asri/llms.txt Creates a supplier record with contact information and optional profile picture for maintaining vendor relationships and tracking purchase sources. ```APIDOC ## POST /admin/suppliers ### Description Creates a new supplier record in the system. This endpoint allows for the submission of supplier details including name, address, telephone number, and an optional profile picture. ### Method POST ### Endpoint /admin/suppliers ### Parameters #### Request Body - **name** (string) - Required - The name of the supplier. - **address** (string) - Required - The physical address of the supplier. - **telephone** (string) - Required - The contact telephone number of the supplier. - **picture** (file) - Optional - The profile picture or logo of the supplier. Maximum file size is 2048 KB. ### Request Example ```json { "name": "ABC Textile Supplier", "address": "Jl. Industri No. 45, Bandung", "telephone": "+62227654321", "picture": "file_upload" } ``` ### Response #### Success Response (Redirect) Redirects to the suppliers index page with a success status message upon successful creation. #### Error Response Returns validation errors or exception messages if the creation fails. ``` -------------------------------- ### POST /admin/reports Source: https://context7.com/noorfikri/kp_asri/llms.txt Generates a financial report by aggregating specified buying and selling transactions, calculating cash flow, and storing the report details. ```APIDOC ## POST /admin/reports ### Description Generates monthly or yearly financial reports by aggregating buying and selling transactions, calculating cash flow, and storing report snapshots for historical tracking. ### Method POST ### Endpoint /admin/reports ### Parameters #### Request Body - **report_date** (string) - Required - The date for the report (YYYY-MM-DD). - **type** (string) - Required - The type of report, either 'monthly' or 'yearly'. - **buying_transactions** (array) - Optional - An array of transaction IDs to include in the buying side. - **selling_transactions** (array) - Optional - An array of transaction IDs to include in the selling side. - **other_cost** (integer) - Optional - Additional operational costs (rent, utilities, etc.). Defaults to 0. ### Request Example ```json { "report_date": "2025-10-31", "type": "monthly", "buying_transactions": [ 1, 2, 3, 5, 7 ], "selling_transactions": [ 10, 11, 12, 15, 20 ], "other_cost": 500000 } ``` ### Response #### Success Response (Redirect) On successful creation, the user is redirected to the reports index page with a success status message. #### Response Example (Data persisted in DB and returned on request) ```json { "report_date": "2025-10-31", "type": "monthly", "total_buying": 45000000, "total_bought_count": 500, "total_selling": 65000000, "total_sold_count": 380, "other_cost": 500000, "cash_flow": 19500000 } ``` #### Error Response - **400 Bad Request**: If validation fails. - **500 Internal Server Error**: If an exception occurs during report creation. ``` -------------------------------- ### PHP: Create Financial Report API Endpoint Source: https://context7.com/noorfikri/kp_asri/llms.txt This snippet defines the POST endpoint for creating financial reports. It includes request validation, data aggregation from buying and selling transactions, calculation of financial metrics like cash flow, and storage of the report data. It uses authenticated user IDs and handles potential exceptions. ```php // POST /admin/reports // Request payload example $request = [ 'report_date' => '2025-10-31', 'type' => 'monthly', // or 'yearly' 'creator_id' => 1, // Ignored, uses auth()->id() 'buying_transactions' => [1, 2, 3, 5, 7], // Transaction IDs to include 'selling_transactions' => [10, 11, 12, 15, 20], 'other_cost' => 500000 // Operational costs, rent, utilities, etc. ]; // Controller: ReportController@store public function store(Request $request) { $validated = $request->validate([ 'report_date' => 'required|date', 'type' => 'required|in:monthly,yearly', 'creator_id' => 'required|exists:users,id', 'buying_transactions' => 'nullable|array', 'buying_transactions.*' => 'required|distinct|exists:buying_transactions,id', 'selling_transactions' => 'nullable|array', 'selling_transactions.*' => 'required|distinct|exists:selling_transactions,id', 'other_cost' => 'nullable|integer|min:0', ]); try { // Use authenticated user for security $creatorId = auth()->id(); $report = Report::create([ 'report_date' => $validated['report_date'], 'type' => $validated['type'], 'creator_id' => $creatorId, 'other_cost' => $validated['other_cost'] ?? 0, ]); // Attach transactions if (!empty($validated['buying_transactions'])) { $report->buyingTransactions()->attach($validated['buying_transactions']); } if (!empty($validated['selling_transactions'])) { $report->sellingTransactions()->attach($validated['selling_transactions']); } // Calculate financial metrics $totalBuying = $report->buyingTransactions()->sum('total_amount'); $totalBoughtCount = $report->buyingTransactions()->sum('total_count'); $totalSelling = $report->sellingTransactions()->sum('total_amount'); $totalSoldCount = $report->sellingTransactions()->sum('total_count'); $otherCost = $report->other_cost; $cashFlow = $totalSelling - $totalBuying - $otherCost; $report->update([ 'total_buying' => $totalBuying, 'total_bought_count' => $totalBoughtCount, 'total_selling' => $totalSelling, 'total_sold_count' => $totalSoldCount, 'cash_flow' => $cashFlow, ]); return redirect()->route('reports.index') ->with('status', 'Report created successfully'); } catch (Exception $e) { Log::error('Report creation failed', ['error' => $e->getMessage()]); return redirect()->back()->with('error', $e->getMessage()); } } // Expected response: Redirect with success message // Database changes: // - New record in reports table with calculated totals // - Pivot records linking report to transactions // Example output: // { // "report_date": "2025-10-31", // "type": "monthly", // "total_buying": 45000000, // "total_bought_count": 500, // "total_selling": 65000000, // "total_sold_count": 380, // "other_cost": 500000, // "cash_flow": 19500000 // Profit for the period // } ``` -------------------------------- ### Record Purchase Transaction - PHP Source: https://context7.com/noorfikri/kp_asri/llms.txt This PHP code snippet demonstrates how to record a purchase transaction from a supplier. It includes request validation, file upload for receipt images, and updates to inventory stock levels. It handles potential exceptions during the process. ```php // POST /admin/buyingtransactions // Request payload example $request = [ 'supplier_id' => 3, 'date' => '2025-10-15', 'items' => [ [ 'items_stock_id' => 10, 'quantity' => 100, 'price' => 8000000 // Purchase price for 100 units ], [ 'items_stock_id' => 11, 'quantity' => 50, 'price' => 3500000 ] ], 'sub_total' => 11500000, 'total_count' => 150, 'discount_amount' => 500000, 'other_cost' => 200000, // Shipping, taxes, etc. 'total_amount' => 11200000, // sub_total - discount + other_cost 'reciept_image' => $uploadedFile // Receipt scan/photo ]; // Controller: BuyingTranscationController@store public function store(Request $request, FileUploadService $fileUpload) { $validated = $request->validate([ 'supplier_id' => 'required|exists:suppliers,id', 'date' => 'required|date', 'items' => 'required|array|min:1', 'items.*.items_stock_id' => 'required|exists:items_stock,id', 'items.*.quantity' => 'required|integer|min:1', 'items.*.price' => 'required|integer|min:0', 'sub_total' => 'required|integer|min:0', 'total_count' => 'required|integer|min:0', 'discount_amount' => 'nullable|integer|min:0', 'other_cost' => 'nullable|integer|min:0', 'total_amount' => 'required|integer|min:0', 'reciept_image' => 'nullable|image|max:2048', ]); try { $transaction = new BuyingTransaction(); $transaction->fill($validated); if ($request->hasFile('reciept_image')) { $transaction->reciept_image = $fileUpload->uploadFile( $request->file('reciept_image'), 'buying_transaction_' . now()->format('YmdHis'), 'receipts' ); } $transaction->save(); foreach ($validated['items'] as $item) { BuyingTransactionItem::create([ 'transaction_id' => $transaction->id, 'items_stock_id' => $item['items_stock_id'], 'total_quantity' => $item['quantity'], 'total_price' => $item['price'], ]); // Add stock $stock = ItemStock::find($item['items_stock_id']); $stock->stock += $item['quantity']; $stock->save(); } return redirect()->route('buyingtransactions.index') ->with('status', 'Purchase transaction created successfully'); } catch (Exception $e) { Log::error('Purchase failed', ['error' => $e->getMessage()]); return redirect()->back()->with('error', $e->getMessage()); } } // Expected response: Redirect with success message // Database changes: // - New record in buying_transactions table with receipt image path // - Multiple records in buying_transactions_items table // - Stock quantities increased in items_stock table ``` -------------------------------- ### Create Sales Transaction with Stock Deduction (PHP) Source: https://context7.com/noorfikri/kp_asri/llms.txt This PHP code demonstrates the process of creating a sales transaction. It first validates the request data, then checks for stock availability for each item. If stock is sufficient, it creates the transaction and its associated items, and finally deducts the sold quantities from the inventory. Error handling is included for exceptions during the process. ```php // POST /admin/sellingtransactions // Request payload example $request = [ 'seller_id' => 5, // User ID of the seller 'date' => '2025-10-20', 'items' => [ [ 'items_stock_id' => 10, // ItemStock ID for Small/Black T-Shirt 'quantity' => 5, 'price' => 750000 // Total price (5 * 150000) ], [ 'items_stock_id' => 11, // ItemStock ID for Medium/White T-Shirt 'quantity' => 3, 'price' => 450000 // Total price (3 * 150000) ] ], 'sub_total' => 1200000, 'total_count' => 8, // Total quantity of items 'discount_amount' => 50000, 'total_amount' => 1150000 // sub_total - discount_amount ]; // Controller: SellingTransactionController@store public function store(Request $request) { $validated = $request->validate([ 'seller_id' => 'required|exists:users,id', 'date' => 'required|date', 'items' => 'required|array|min:1', 'items.*.items_stock_id' => 'required|exists:items_stock,id', 'items.*.quantity' => 'required|integer|min:1', 'items.*.price' => 'required|integer|min:0', 'sub_total' => 'required|integer|min:0', 'total_count' => 'required|integer|min:0', 'discount_amount' => 'nullable|integer|min:0', 'total_amount' => 'required|integer|min:0', ]); // Validate stock availability before processing foreach ($validated['items'] as $item) { $stock = ItemStock::findOrFail($item['items_stock_id']); if ($stock->stock < $item['quantity']) { return redirect()->back() ->with('error', 'Insufficient stock for transaction'); } } try { $transaction = new SellingTransaction(); $transaction->fill($validated); $transaction->save(); foreach ($validated['items'] as $item) { SellingTransactionItem::create([ 'transaction_id' => $transaction->id, 'items_stock_id' => $item['items_stock_id'], 'total_quantity' => $item['quantity'], 'total_price' => $item['price'], ]); // Deduct stock $stock = ItemStock::find($item['items_stock_id']); $stock->stock -= $item['quantity']; $stock->save(); } return redirect()->route('sellingtransactions.index') ->with('status', 'Sales transaction created successfully'); } catch (Exception $e) { Log::error('Transaction failed', ['error' => $e->getMessage()]); return redirect()->back()->with('error', $e->getMessage()); } } // Expected response: Redirect with success message // Database changes: // - New record in selling_transactions table // - Multiple records in selling_transactions_items table // - Stock quantities decreased in items_stock table ``` -------------------------------- ### Untitled No description -------------------------------- ### Register New Supplier - PHP Source: https://context7.com/noorfikri/kp_asri/llms.txt Creates a new supplier record in the system, including contact details and an optional profile picture. This functionality is crucial for managing vendor relationships and tracking purchase sources. It validates input data and handles file uploads for the supplier's picture. ```php // POST /admin/suppliers // Request payload example $request = [ 'name' => 'ABC Textile Supplier', 'address' => 'Jl. Industri No. 45, Bandung', 'telephone' => '+62227654321', 'picture' => $uploadedFile // Supplier logo/photo ]; // Controller: SupplierController@store public function store() { $validator = Validator::make(request()->all(), [ 'name' => 'required|string|max:255|unique:suppliers,name', 'address' => 'required|string|max:255', 'telephone' => 'required|string|max:50', 'picture' => 'nullable|image|max:2048', ]); if ($validator->fails()) { return redirect()->route('suppliers.index') ->withErrors($validator) ->withInput(); } try { $supplier = new Supplier(); $supplier->name = request('name'); $supplier->address = request('address'); $supplier->telephone = request('telephone'); if (request()->hasFile('picture')) { $supplier->picture = App::call([new FileUploadService, 'uploadFile'], [ 'file' => request()->file('picture'), 'filename' => $supplier->name, 'folder' => 'supplier' ]); } $supplier->save(); return redirect()->route('suppliers.index') ->with('status', 'Supplier created: ' . $supplier->name); } catch (Exception $e) { return redirect()->back()->with('error', $e->getMessage()); } } // Expected response: Redirect with success message // Database changes: New record in suppliers table // Can be referenced in buying transactions ``` -------------------------------- ### Untitled No description -------------------------------- ### Load Item Creation Form via AJAX (PHP/JavaScript) Source: https://context7.com/noorfikri/kp_asri/llms.txt This snippet shows how to load a form for creating new items dynamically using AJAX in a Laravel application. The PHP controller prepares necessary data (categories, sizes, colors, brands) and returns rendered HTML within a JSON response. The JavaScript code then uses this response to populate a modal dialog, enhancing user experience by avoiding full page reloads. Dependencies include Laravel framework for the backend and jQuery for frontend AJAX handling. Inputs are typically CSRF token for security, and outputs are JSON containing the rendered form HTML. ```php // POST /admin/items/showCreate // AJAX request from frontend // Controller: ItemController@showCreate public function showCreate(\Illuminate\Http\Request $request) { $category = Category::all(); $size = Size::all(); $colour = Colour::all(); $brand = Brand::all(); return response()->json([ 'status' => 'ok', 'msg' => view('item.create', [ 'category' => $category, 'size' => $size, 'colour' => $colour, 'brand' => $brand ])->render() ], 200); } ``` ```javascript $.ajax({ url: '/admin/items/showCreate', method: 'POST', data: { _token: $('meta[name="csrf-token"]').attr('content') }, success: function(response) { if (response.status === 'ok') { // Inject rendered HTML into modal $('#modalContent').html(response.msg); $('#createModal').modal('show'); } }, error: function(xhr) { console.error('Failed to load form:', xhr.responseText); } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.