mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim-api.git
synced 2026-08-19 04:24:01 +00:00
174 lines
5.6 KiB
PHP
174 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\So;
|
|
use App\Soitem;
|
|
use App\company;
|
|
use Auth;
|
|
|
|
class SoController extends Controller
|
|
{
|
|
|
|
public function showso($id)
|
|
{
|
|
// Fix : find the shipping order that belongs to the user
|
|
$so = So::findOrFail($id);
|
|
|
|
// Fix : return with json not view
|
|
return view('home')->with('so', $so);
|
|
}
|
|
|
|
/**
|
|
* Store shipping order item.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$so = new So;
|
|
|
|
// Fix : contact undefined, for now just get it from input
|
|
$so->ff_id = $contact->id; //ff contact list id
|
|
|
|
// TODO : check ff_id is belongs to user's friend
|
|
|
|
$so->supplier_company_name = $request->input('supplier_company_name');
|
|
$so->supplier_contact_person = $request->input('supplier_contact_person');
|
|
$so->supplier_contact_person_no = $request->input('supplier_contact_person_no');
|
|
|
|
// TODO, FIX : $deliveryinfo undefined, this one need deliveryinfo branch
|
|
$so->delivery_id = $deliveryinfo->id; //deli-info id
|
|
|
|
// TODO, FIX : $warehouse undefined, this one need warehouse branch
|
|
$so->warehouse_id = $warehouse->id; //warehouse id
|
|
$so->com_id = $user->company(); //company id
|
|
$so->save();
|
|
|
|
$soitems = $request->input('soitem');
|
|
foreach ($soitems as $soitem)
|
|
{
|
|
$new_soitem = new Soitem(array(
|
|
'so_id'=>$so->id,
|
|
'status'=>$soitem['status'],
|
|
'brand_no'=>$soitem['brand_no'],
|
|
'model_no'=>$soitem['model_no'],
|
|
'item_code'=>$soitem['item_code'],
|
|
'quantity_of_item'=>$soitem['quantity_of_item'],
|
|
'uom'=>$soitem['uom'],
|
|
'quantity_of_carton'=>$soitem['quantity_of_carton'],
|
|
'packaging_type'=>$soitem['packaging_type'],
|
|
'packaging_height'=>$soitem['packaging_height'],
|
|
'packaging_width'=>$soitem['packaging_width'],
|
|
'packaging_depth'=>$soitem['packaging_depth'],
|
|
'packaging_gross'=>$soitem['packaging_gross'],
|
|
'packaging_nett'=>$soitem['packaging_nett'],
|
|
));
|
|
|
|
$new_soitem->save();
|
|
}
|
|
return response()->json(['so'=>$so], 201);
|
|
}
|
|
|
|
/**
|
|
*cancel the shipping order.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function cancelOrder(Request $request)
|
|
{
|
|
|
|
if (!$so = So::where('com_id', Auth::user()->company())->where('id', $id)->first())
|
|
{
|
|
return response()->json(['message'=>'Access denied'], 200);
|
|
}
|
|
|
|
$so->is_cancel = true;
|
|
|
|
$so->save();
|
|
|
|
|
|
return response()->json(['message'=>'Success'],200);
|
|
}
|
|
|
|
/**
|
|
* Update the shipping order and item.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$so = So::where('com_id', Auth::user()->company())->where('id', $id)->first();
|
|
|
|
if (!$so)
|
|
{
|
|
return response()->json(['message'=>'Access Denied!'], 404);
|
|
}
|
|
|
|
// Fix : contact undefined, for now just get it from input
|
|
$so->ff_id = $contact->id;
|
|
$so->supplier_company_name = $request->input('supplier_company_name');
|
|
$so->supplier_contact_person = $request->input('supplier_contact_person');
|
|
$so->supplier_contact_person_no = $request->input('supplier_contact_person_no');
|
|
$so->delivery_id = $deliveryinfo->id;
|
|
$so->warehouse_id = $warehouse->id;
|
|
$deliveryinfo->com_id = $user->company();
|
|
$so->save();
|
|
|
|
$soitems = $request->input('soitem');
|
|
foreach ($soitems as $soitem)
|
|
{
|
|
$new_soitem = Soitem::where('so_id', $id)->first();
|
|
$new_soitem->status = $soitem['status'];
|
|
$new_soitem->order_id = $soitem['order_id'];
|
|
$new_soitem->brand_no = $soitem['brand_no'];
|
|
$new_soitem->model_no = $soitem['model_no'];
|
|
$new_soitem->item_code = $soitem['item_code'];
|
|
$new_soitem->quantity_of_item = $soitem['quantity_of_item'];
|
|
$new_soitem->uom = $soitem['uom'];
|
|
$new_soitem->quantity_of_carton = $soitem['quantity_of_carton'];
|
|
$new_soitem->packaging_type = $soitem['packaging_type'];
|
|
$new_soitem->packaging_height = $soitem['packaging_height'];
|
|
$new_soitem->packaging_width = $soitem['packaging_width'];
|
|
$new_soitem->packaging_depth = $soitem['packaging_depth'];
|
|
$new_soitem->packaging_gross = $soitem['packaging_gross'];
|
|
$new_soitem->packaging_nett = $soitem['packaging_nett'];
|
|
$new_soitem->save();
|
|
|
|
}
|
|
|
|
return response()->json(['so'=>$so],200);
|
|
|
|
}
|
|
|
|
/**
|
|
* Remove the shipping order and item
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function delete(So $id)
|
|
{
|
|
$so = So::where('com_id', Auth::user()->company())->where('id', $id)->firstOrFail();
|
|
|
|
if (!$so)
|
|
{
|
|
return response()->json(['message'=>'Access Denied!'], 404);
|
|
}
|
|
|
|
$so->delete($id);
|
|
|
|
return response()->json($so, 204);
|
|
|
|
}
|
|
|
|
}
|