Account Changes
This commit is contained in:
@@ -11,13 +11,16 @@ use Illuminate\Support\Facades\DB;
|
|||||||
|
|
||||||
class AdminAccountController extends Controller
|
class AdminAccountController extends Controller
|
||||||
{
|
{
|
||||||
public function updateEntry(Request $request)
|
public function updateEntry(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$data = $request->validate([
|
$data = $request->validate([
|
||||||
'entry_no' => 'required|exists:entries,entry_no',
|
'entry_no' => 'required|exists:entries,entry_no',
|
||||||
'description' => 'required|string|max:255',
|
'description' => 'required|string|max:255',
|
||||||
'order_quantity' => 'required|numeric|min:0',
|
'order_quantity' => 'required|numeric|min:0',
|
||||||
|
'region' => 'required|string|max:50',
|
||||||
|
'amount' => 'required|numeric|min:0',
|
||||||
|
'payment_status' => 'required|string|max:50',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$entry = Entry::where('entry_no', $data['entry_no'])->first();
|
$entry = Entry::where('entry_no', $data['entry_no'])->first();
|
||||||
@@ -31,6 +34,10 @@ class AdminAccountController extends Controller
|
|||||||
|
|
||||||
$entry->description = $data['description'];
|
$entry->description = $data['description'];
|
||||||
$entry->order_quantity = $data['order_quantity'];
|
$entry->order_quantity = $data['order_quantity'];
|
||||||
|
$entry->region = $data['region'];
|
||||||
|
$entry->amount = $data['amount'];
|
||||||
|
$entry->payment_status = $data['payment_status'];
|
||||||
|
|
||||||
$entry->save();
|
$entry->save();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -46,36 +53,6 @@ class AdminAccountController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteEntry(Request $request)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$data = $request->validate([
|
|
||||||
'entry_no' => 'required|exists:entries,entry_no',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$entry = Entry::where('entry_no', $data['entry_no'])->first();
|
|
||||||
|
|
||||||
if (!$entry) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Entry not found.',
|
|
||||||
], 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
$entry->delete();
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Entry deleted successfully.',
|
|
||||||
]);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
return response()->json([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Server error: '.$e->getMessage(),
|
|
||||||
], 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 🚀 1. Get dashboard entries
|
* 🚀 1. Get dashboard entries
|
||||||
*/
|
*/
|
||||||
@@ -96,16 +73,15 @@ public function deleteEntry(Request $request)
|
|||||||
*/
|
*/
|
||||||
public function getAvailableOrders()
|
public function getAvailableOrders()
|
||||||
{
|
{
|
||||||
$orders = Order::whereDoesntHave('entries')
|
$orders = Order::orderBy('id', 'desc')->get();
|
||||||
->orderBy('id', 'desc')
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'orders' => $orders
|
'orders' => $orders,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 🚀 3. Create new entry
|
* 🚀 3. Create new entry
|
||||||
*/
|
*/
|
||||||
@@ -325,10 +301,9 @@ public function deleteEntry(Request $request)
|
|||||||
return DB::transaction(function () use ($data) {
|
return DB::transaction(function () use ($data) {
|
||||||
$entry = Entry::where('entry_no', $data['entry_no'])->firstOrFail();
|
$entry = Entry::where('entry_no', $data['entry_no'])->firstOrFail();
|
||||||
|
|
||||||
// आधीचे orders काढू नका, फक्त नवीन add करा
|
|
||||||
$entry->orders()->syncWithoutDetaching($data['order_ids']);
|
$entry->orders()->syncWithoutDetaching($data['order_ids']);
|
||||||
|
|
||||||
// इथे quantity auto update
|
|
||||||
$entry->order_quantity = $entry->orders()->count();
|
$entry->order_quantity = $entry->orders()->count();
|
||||||
$entry->save();
|
$entry->save();
|
||||||
|
|
||||||
@@ -387,5 +362,35 @@ public function removeOrderFromEntry(Request $request)
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public function deleteEntry(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$data = $request->validate([
|
||||||
|
'entry_no' => 'required|exists:entries,entry_no',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$entry = Entry::where('entry_no', $data['entry_no'])->first();
|
||||||
|
|
||||||
|
if (!$entry) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Entry not found.',
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$entry->delete();
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Entry deleted successfully.',
|
||||||
|
]);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return response()->json([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Server error: '.$e->getMessage(),
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user