Bugfix/list clickup issue (#5)
Reviewed-on: #5 Co-authored-by: ISMAIL MASSERAN <ismail@koppkb.com> Co-committed-by: ISMAIL MASSERAN <ismail@koppkb.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -2,25 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Models\User;
|
||||
use PDF;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Cawangan;
|
||||
use App\Models\JenisEmas;
|
||||
use App\Models\JenisKarat;
|
||||
|
||||
use App\Models\Lelong;
|
||||
use App\Models\CawanganLelong;
|
||||
use App\Models\FileMarhun;
|
||||
use App\Models\LelongBid;
|
||||
use App\Models\LelongBidMarhun;
|
||||
use App\Models\LelKarat;
|
||||
use App\Models\Cart;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\FileMarhun;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CartController extends Controller
|
||||
{
|
||||
@@ -35,32 +22,30 @@ class CartController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\Support\Renderable
|
||||
*/
|
||||
|
||||
public function getCart($userid)
|
||||
public function getCart($userid)
|
||||
{
|
||||
$carts = Cart::where('user_id','=', $userid)->get()->toArray();
|
||||
|
||||
foreach($carts as $index => $cart)
|
||||
{
|
||||
$lelongbid = LelongBid::where('id',$cart['lelongbid_id'])->first()->toArray();
|
||||
$marhun = LelongBidMarhun::where('lelongbid_id','=',$lelongbid['id'])->get()->toArray();
|
||||
$cawangan = Cawangan::where('id','=',$lelongbid['caw_id'])->first()->toArray();
|
||||
$carts = Cart::where('user_id', '=', $userid)->get()->toArray();
|
||||
|
||||
foreach ($carts as $index => $cart) {
|
||||
$lelongbid = LelongBid::where('id', $cart['lelongbid_id'])->first()->toArray();
|
||||
$marhun = LelongBidMarhun::where('lelongbid_id', '=', $lelongbid['id'])->get()->toArray();
|
||||
$cawangan = Cawangan::where('id', '=', $lelongbid['caw_id'])->first()->toArray();
|
||||
|
||||
$carts[$index]['datalelongbid'] = $lelongbid;
|
||||
$carts[$index]['datalelongbid']['lelongbidmarhun'] = $marhun;
|
||||
$carts[$index]['datalelongbid']['cawangan'] = $cawangan;
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
"carts" => $carts
|
||||
'carts' => $carts,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCartByCawangan($userId)
|
||||
{
|
||||
$groupCawangan = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id')
|
||||
->join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id')
|
||||
->where('user_id', '=', $userId)
|
||||
->join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id')
|
||||
->where('user_id', '=', $userId)
|
||||
->select('caw_id', 'caw_name')
|
||||
->groupBy('caw_id')
|
||||
->get()->toArray();
|
||||
@@ -71,7 +56,7 @@ class CartController extends Controller
|
||||
foreach ($groupCawangan as $index => $cawangan) {
|
||||
|
||||
$cart = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id')
|
||||
->where('user_id', $userId)
|
||||
->where('user_id', $userId)
|
||||
->where('caw_id', $cawangan)
|
||||
->get()->toArray();
|
||||
|
||||
@@ -92,11 +77,11 @@ class CartController extends Controller
|
||||
$marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray();
|
||||
|
||||
$cart[$index1]['lelongbidmarhun'] = $marhun;
|
||||
$cart[$index1]['tambahanbidaan'] = number_format((float)$tambahan_bidaan, 2, '.', '');
|
||||
$cart[$index1]['tambahanbidaan'] = number_format((float) $tambahan_bidaan, 2, '.', '');
|
||||
}
|
||||
$groupCawangan[$index]['total_surat'] = $total_surat;
|
||||
$groupCawangan[$index]['total_berat'] = number_format((float)$total_berat, 2, '.', '');
|
||||
$groupCawangan[$index]['total_bidaan'] = number_format((float)$total_hargabida, 2, '.', '');
|
||||
$groupCawangan[$index]['total_berat'] = number_format((float) $total_berat, 2, '.', '');
|
||||
$groupCawangan[$index]['total_bidaan'] = number_format((float) $total_hargabida, 2, '.', '');
|
||||
|
||||
$groupCawangan[$index]['lelongbid'] = $cart;
|
||||
|
||||
@@ -104,18 +89,17 @@ class CartController extends Controller
|
||||
$master_total_bidaan += $total_hargabida;
|
||||
}
|
||||
|
||||
|
||||
if ($groupCawangan) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'cart' => $groupCawangan,
|
||||
'master_total_surat' => $master_total_surat,
|
||||
'master_total_bidaan' => number_format((float)$master_total_bidaan, 2, '.', ''),
|
||||
'master_total_bidaan' => number_format((float) $master_total_bidaan, 2, '.', ''),
|
||||
], 201);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Empty Data'
|
||||
'message' => 'Empty Data',
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
@@ -126,20 +110,20 @@ class CartController extends Controller
|
||||
|
||||
$beza_harga = $request->hargabida - $lelong_bid->hargaasas;
|
||||
|
||||
if($beza_harga < 1) {
|
||||
if ($beza_harga < 1) {
|
||||
return response()->json([
|
||||
'success' => 'gagal',
|
||||
'status' => 9,
|
||||
'message' => 'Harga bida kurang daripada harga asas.'
|
||||
'message' => 'Harga bida kurang daripada harga asas.',
|
||||
]);
|
||||
}
|
||||
|
||||
$check_exist = Cart::where('lelongbid_id', $request->lelongbid_id)->where('user_id', $request->user_id)->exists();
|
||||
if($check_exist == true) {
|
||||
if ($check_exist == true) {
|
||||
return response()->json([
|
||||
'success' => 'gagal_tambah_ke_troli',
|
||||
'status' => 8,
|
||||
'message' => 'SAG telah berada di dalam troli!'
|
||||
'message' => 'SAG telah berada di dalam troli!',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -148,15 +132,12 @@ class CartController extends Controller
|
||||
$item->lelongbid_id = $request->lelongbid_id;
|
||||
$item->hargabida = $request->hargabida;
|
||||
|
||||
if($item->save())
|
||||
{
|
||||
if ($item->save()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'carts' => $item
|
||||
'carts' => $item,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error! Cannot save.',
|
||||
@@ -166,16 +147,13 @@ class CartController extends Controller
|
||||
|
||||
public function removeFromCart(Request $request)
|
||||
{
|
||||
$item = Cart::where('id',$request->cart_id)->first();
|
||||
if($item->delete())
|
||||
{
|
||||
$item = Cart::where('id', $request->cart_id)->first();
|
||||
if ($item->delete()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'carts' => $item
|
||||
'carts' => $item,
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error! Cannot save.',
|
||||
@@ -193,11 +171,11 @@ class CartController extends Controller
|
||||
|
||||
$beza_harga = $request->hargabida - $lelong_bid->hargaasas;
|
||||
|
||||
if($beza_harga < 1) {
|
||||
if ($beza_harga < 1) {
|
||||
return response()->json([
|
||||
'success' => 'gagal',
|
||||
'status' => 9,
|
||||
'message' => 'Harga bida kurang daripada harga asas.'
|
||||
'message' => 'Harga bida kurang daripada harga asas.',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -205,7 +183,7 @@ class CartController extends Controller
|
||||
if ($cart->save()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'cart' => $cart
|
||||
'cart' => $cart,
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
@@ -217,32 +195,11 @@ class CartController extends Controller
|
||||
|
||||
public function deleteCart($id)
|
||||
{
|
||||
$cart = Cart::where('id','=',$id)->first();
|
||||
if($cart->delete())
|
||||
{
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Delete Success'
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error! Cannot save.',
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteItem(Request $request)
|
||||
{
|
||||
$cart = Cart::where('user_id', $request->userId)
|
||||
->where('lelongbid_id', $request->lelongBidId)
|
||||
->first();
|
||||
$cart = Cart::where('id', '=', $id)->first();
|
||||
if ($cart->delete()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Delete Success'
|
||||
'message' => 'Delete Success',
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
@@ -252,6 +209,21 @@ class CartController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function deleteItem(Request $request)
|
||||
{
|
||||
$cart = Cart::where('user_id', $request->userId)
|
||||
->where('lelongbid_id', $request->lelongBidId)
|
||||
->first();
|
||||
if ($cart->delete()) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Delete Success',
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Error! Cannot save.',
|
||||
], 401);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user