Siopas Inventory PETI for ISTW Website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
3.8 KiB

<?php
namespace App\Http\Controllers\API\v1\TransferApi;
use App\Models\Transfer;
use App\Models\Type_peti;
use Illuminate\Http\Request;
use App\Helpers\ResponseFormatter;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Http\Controllers\Controller;
use Illuminate\Database\QueryException;
class TransferApiController extends Controller
{
public function index()
{
// $tipePeti = \App\Models\Type_peti::get();
$transfer = \App\Models\Transfer::get();
return ResponseFormatter::success([
'status' => true,
'message' => 'Data Transfer Peti berhasil diambil',
'transfer_peti' => $transfer
]);
}
// public function store(Request $request)
// {
// $mobile_id = $request->input('mobile_id');
// $peti_id = $request->input('peti_id');
// $name_customer = $request->input('name_customer');
// $source_warehouse = $request->input('source_warehouse');
// $destination_warehouse = $request->input('destination_warehouse');
// $transfer_date = $request->input('date');
// $created_by = $request->input('created_by');
// $created_at = $request->input('created_at');
// $transfer = Transfer::create([
// 'mobile_id' => $mobile_id,
// 'peti_id' => $peti_id,
// 'name_customer' => $name_customer,
// 'source_warehouse' => $source_warehouse,
// 'destination_warehouse' => $destination_warehouse,
// 'date' => $transfer_date,
// 'created_by' => $created_by,
// 'created_at' => $created_at
// ]);
// if ($transfer) {
// return ResponseFormatter::success([
// 'status' => true,
// 'message' => 'Data Transfer Peti berhasil ditambahkan',
// 'transfer_peti' => $transfer
// ]);
// } else {
// return ResponseFormatter::error([
// 'status' => false,
// 'message' => 'Data Transfer Peti gagal ditambahkan',
// 'transfer_peti' => $transfer
// ]);
// }
// }
public function store(Request $request)
{
try {
DB::beginTransaction();
$mobile_id = $request->input('mobile_id');
$peti_id = $request->input('peti_id');
$name_customer = $request->input('name_customer');
$source_warehouse = $request->input('source_warehouse');
$destination_warehouse = $request->input('destination_warehouse');
$transfer_date = $request->input('date');
$created_by = $request->input('created_by');
$created_at = $request->input('created_at');
$transfer = Transfer::create([
'mobile_id' => $mobile_id,
'peti_id' => $peti_id,
'name_customer' => $name_customer,
'source_warehouse' => $source_warehouse,
'destination_warehouse' => $destination_warehouse,
'date' => $transfer_date,
'created_by' => $created_by,
'created_at' => $created_at
]);
DB::commit();
return ResponseFormatter::success([
'status' => true,
'message' => 'Data Transfer Peti berhasil ditambahkan',
'transfer_peti' => $transfer
]);
} catch (QueryException $e) {
DB::rollBack();
// Log the error for further investigation
Log::error('Error storing Transfer data: ' . $e->getMessage());
return ResponseFormatter::error([
'status' => false,
'message' => 'Error while processing the request.',
'error' => $e->getMessage()
]);
}
}
}