|
|
@@ -55,6 +55,9 @@ class WaybillsController extends Controller
|
|
|
if ($request->input('created_at_end')){
|
|
|
$waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
|
|
|
}
|
|
|
+ if ($request->input('state')){
|
|
|
+ $waybills=$waybills->where('state',$request->input('state'));
|
|
|
+ }
|
|
|
$waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
|
|
|
if (!$waybills&&$request->input('waybill_number')){
|
|
|
$waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
@@ -68,7 +71,7 @@ class WaybillsController extends Controller
|
|
|
} else {
|
|
|
$waybills = Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
return $query->with('user');
|
|
|
- }])->paginate(50);
|
|
|
+ }])->orderBy('id', 'DESC')->paginate(50);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'']);
|
|
|
@@ -105,6 +108,9 @@ class WaybillsController extends Controller
|
|
|
if ($request->input('created_at_end')){
|
|
|
$waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
|
|
|
}
|
|
|
+ if ($request->input('state')){
|
|
|
+ $waybills=$waybills->where('state',$request->input('state'));
|
|
|
+ }
|
|
|
$waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
|
|
|
if (!$waybills&&$request->input('waybill_number')){
|
|
|
$waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
@@ -118,7 +124,7 @@ class WaybillsController extends Controller
|
|
|
} else {
|
|
|
$waybills = Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
return $query->with('user');
|
|
|
- }])->where('type','直发车')->paginate(50);
|
|
|
+ }])->where('type','直发车')->orderBy('id', 'DESC')->paginate(50);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZF']);
|
|
|
@@ -155,6 +161,9 @@ class WaybillsController extends Controller
|
|
|
if ($request->input('created_at_end')){
|
|
|
$waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
|
|
|
}
|
|
|
+ if ($request->input('state')){
|
|
|
+ $waybills=$waybills->where('state',$request->input('state'));
|
|
|
+ }
|
|
|
$waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
|
|
|
if (!$waybills&&$request->input('waybill_number')){
|
|
|
$waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
@@ -168,7 +177,7 @@ class WaybillsController extends Controller
|
|
|
} else {
|
|
|
$waybills = Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
|
|
|
return $query->with('user');
|
|
|
- }])->where('type','专线')->paginate(50);
|
|
|
+ }])->where('type','专线')->orderBy('id', 'DESC')->paginate(50);
|
|
|
$carries = Carrier::get();
|
|
|
$owners = Owner::get();
|
|
|
return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZX']);
|
|
|
@@ -243,14 +252,16 @@ class WaybillsController extends Controller
|
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
{
|
|
|
+ $waybill=Waybill::find($id);
|
|
|
+ // if ($request->input('carrier_bill')==$waybill->carrier_bill){};
|
|
|
if(!Gate::allows('运输管理-调度')){ return redirect(url('/')); }
|
|
|
$this->validatorWaybillDispatch($request)->validate();
|
|
|
$data=$request->input();
|
|
|
- $waybill=Waybill::find($id);
|
|
|
$waybill->fill($data);
|
|
|
if ($waybill->save()){
|
|
|
if ($waybill->type=="直发车"){
|
|
|
- $total_receivable=($waybill->charge);
|
|
|
+ if ($waybill->charge)$total_receivable=($waybill->charge);
|
|
|
+ elseif ($waybill->collect_fee)$total_receivable=($waybill->collect_fee);
|
|
|
$total_expense=($waybill->fee)+($waybill->other_fee)-($waybill->collect_fee);
|
|
|
}else if ($waybill->type=="专线"){
|
|
|
$waybillPriceModel_id=$request->input('waybillPriceModel');
|
|
|
@@ -270,23 +281,25 @@ class WaybillsController extends Controller
|
|
|
$total_receivable=($waybill->charge);
|
|
|
$total_expense=($waybill->pick_up_fee)+($waybill->other_fee)+($waybill->fee);
|
|
|
}
|
|
|
- $waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
|
|
|
- if ($waybillPayoff){
|
|
|
- $waybillPayoff->waybill_id=$id;
|
|
|
- $waybillPayoff->total_expense=$total_expense;
|
|
|
- $waybillPayoff->total_receivable=$total_receivable;
|
|
|
- $waybillPayoff->gross_margin=$total_receivable-$total_expense;
|
|
|
- $waybillPayoff->gross_profit_rate=(($total_receivable-$total_expense)/$total_receivable);
|
|
|
- $waybillPayoff->save();
|
|
|
- }else{
|
|
|
- WaybillPayoff::create([
|
|
|
- 'waybill_id'=>$id,
|
|
|
- 'total_expense'=>$total_expense,
|
|
|
- 'total_receivable'=>$total_receivable,
|
|
|
- 'gross_margin'=>$total_receivable-$total_expense,
|
|
|
- 'gross_profit_rate'=>(($total_receivable-$total_expense)/$total_receivable),
|
|
|
- ]);
|
|
|
- };
|
|
|
+ if ($waybill->waybill_price_models&&$total_receivable){
|
|
|
+ $waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
|
|
|
+ if ($waybillPayoff){
|
|
|
+ $waybillPayoff->waybill_id=$id;
|
|
|
+ $waybillPayoff->total_expense=$total_expense;
|
|
|
+ $waybillPayoff->total_receivable=$total_receivable;
|
|
|
+ $waybillPayoff->gross_margin=$total_receivable-$total_expense;
|
|
|
+ $waybillPayoff->gross_profit_rate=(($total_receivable-$total_expense)/$total_receivable);
|
|
|
+ $waybillPayoff->save();
|
|
|
+ }else{
|
|
|
+ WaybillPayoff::create([
|
|
|
+ 'waybill_id'=>$id,
|
|
|
+ 'total_expense'=>$total_expense,
|
|
|
+ 'total_receivable'=>$total_receivable,
|
|
|
+ 'gross_margin'=>$total_receivable-$total_expense,
|
|
|
+ 'gross_profit_rate'=>(($total_receivable-$total_expense)/$total_receivable),
|
|
|
+ ]);
|
|
|
+ };
|
|
|
+ }
|
|
|
$this->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
return redirect('waybill')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功');
|
|
|
}
|
|
|
@@ -313,9 +326,28 @@ class WaybillsController extends Controller
|
|
|
if ($waybillPriceModelProvince){return ['success'=>$waybillPriceModelProvince->id];}
|
|
|
$waybillPriceModelProvinceRange=WaybillPriceModel::whereRaw('carrier_id = ? and province_id = ? and unit_id = ? and range_max is null and city_id is null',
|
|
|
[$carrier_id,$city->province_id,$carrier_weight_unit_id])->first();
|
|
|
- if ($waybillPriceModelProvinceRange){return ['success'=>$waybillPriceModelProvinceRange->id];}else{
|
|
|
- return ['success'=>false];
|
|
|
+ if ($waybillPriceModelProvinceRange){return ['success'=>$waybillPriceModelProvinceRange->id];}
|
|
|
+ $unitKG=Unit::where('name','kg')->first();
|
|
|
+ $unitT=Unit::where('name','T')->first();
|
|
|
+ if ($carrier_weight_unit_id==$unitKG){
|
|
|
+ $waybillPriceModelUnit=WaybillPriceModel::whereRaw('carrier_id = ? and province_id = ? and unit_id = ? and range_max >= ? and range_min < ? and city_id is null',
|
|
|
+ [$carrier_id,$city->province_id,$unitT->id,$carrier_weight/1000,$carrier_weight/1000])->first();
|
|
|
+ if ($waybillPriceModelUnit)return ['success'=>$waybillPriceModelUnit->id];
|
|
|
+ $waybillPriceModel=WaybillPriceModel::where('carrier_id',$carrier_id)->where('city_id',$destination_city_id)
|
|
|
+ ->where('range_min','<',$carrier_weight/1000)->where('range_max','>=',$carrier_weight/1000)
|
|
|
+ ->where('unit_id',$unitT->id)->first();
|
|
|
+ if ($waybillPriceModel)return ['success'=>$waybillPriceModel->id];
|
|
|
+ }
|
|
|
+ if ($carrier_weight_unit_id==$unitT){
|
|
|
+ $waybillPriceModelUnit=WaybillPriceModel::whereRaw('carrier_id = ? and province_id = ? and unit_id = ? and range_max >= ? and range_min < ? and city_id is null',
|
|
|
+ [$carrier_id,$city->province_id,$unitT->id,$carrier_weight*1000,$carrier_weight*1000])->first();
|
|
|
+ if ($waybillPriceModelUnit)return ['success'=>$waybillPriceModelUnit->id];
|
|
|
+ $waybillPriceModel=WaybillPriceModel::where('carrier_id',$carrier_id)->where('city_id',$destination_city_id)
|
|
|
+ ->where('range_min','<',$carrier_weight*1000)->where('range_max','>=',$carrier_weight*1000)
|
|
|
+ ->where('unit_id',$unitKG->id)->first();
|
|
|
+ if ($waybillPriceModel)return ['success'=>$waybillPriceModel->id];
|
|
|
}
|
|
|
+ return ['success'=>false];
|
|
|
}
|
|
|
|
|
|
public function waybillUpdate(Request $request, $id){
|
|
|
@@ -371,6 +403,10 @@ class WaybillsController extends Controller
|
|
|
if(!Gate::allows('运输管理-调度审核')){ return redirect(url('/')); }
|
|
|
$id=$request->input('id');
|
|
|
$waybill=Waybill::find($id);
|
|
|
+ if (!$waybill->charge&&!$waybill->collect_fee)return ['exception'=>'收费或到付费用未填!'];
|
|
|
+ if ($waybill->charge==0&&$waybill->collect_fee==0)return ['exception'=>'收费与到付费用都为0!'];
|
|
|
+ if (!$waybill->carrier_weight||$waybill->carrier_weight==0)return ['exception'=>'承运商计重未填或为0!'];
|
|
|
+ if (!$waybill->carrier_weight_unit_id)return ['exception'=>'承运商计重单位未选!'];
|
|
|
$isAudit=WaybillAuditLog::whereRaw('waybill_id = ? and audit_stage = ?',[$id,"调度阶段"])->first();
|
|
|
if (empty($isAudit)){
|
|
|
$waybillAuditLog=new WaybillAuditLog([
|
|
|
@@ -381,7 +417,7 @@ class WaybillsController extends Controller
|
|
|
$waybillAuditLog->save();
|
|
|
$waybillAuditLog['user']=Auth::user();
|
|
|
if ($waybill->waybill_price_model_id||$waybill->type=='直发车'){
|
|
|
- $waybill->state='完结';
|
|
|
+ $waybill->state='已完结';
|
|
|
$result=$waybill->save();
|
|
|
$waybillPayoff=WaybillPayoff::where('waybill_id','=',$id)->first();
|
|
|
$waybillPayoff->load(["waybill"]);
|
|
|
@@ -392,7 +428,6 @@ class WaybillsController extends Controller
|
|
|
'waybill_id'=>$id,
|
|
|
'json_content'=>$waybillPayoffJson,
|
|
|
]);
|
|
|
-
|
|
|
}else{
|
|
|
$waybill->state='未定义计费模型';
|
|
|
$result=$waybill->save();
|
|
|
@@ -429,9 +464,9 @@ class WaybillsController extends Controller
|
|
|
'carrier_bill'=>'承运商单号',
|
|
|
'origination_city'=>'始发市',
|
|
|
'destination_city'=>'目的市',
|
|
|
- 'warehouse_weight'=>'仓库计重(抛)',
|
|
|
+ 'warehouse_weight'=>'仓库计数(抛)',
|
|
|
'warehouse_weight_unit'=>'仓库计重单位 ',
|
|
|
- 'carrier_weight'=>'承运商计重(抛)',
|
|
|
+ 'carrier_weight'=>'承运商计数(抛)',
|
|
|
'carrier_weight_unit'=>'承运商计重单位',
|
|
|
'carType'=>'车型',
|
|
|
'car_owner_info'=>'车辆信息',
|
|
|
@@ -508,7 +543,7 @@ class WaybillsController extends Controller
|
|
|
protected function validatorWaybill(Request $request){
|
|
|
$validator=Validator::make($request->input(),[
|
|
|
'owner_id'=>'required',
|
|
|
- 'wms_bill_number'=>'nullable|alpha_num|max:50|unique:waybills,wms_bill_number',
|
|
|
+ 'wms_bill_number'=>'nullable|max:50|unique:waybills,wms_bill_number',
|
|
|
'origination'=>'required|max:255',
|
|
|
'destination'=>'required|max:255',
|
|
|
'recipient'=>'required|max:50',
|
|
|
@@ -539,7 +574,7 @@ class WaybillsController extends Controller
|
|
|
protected function validatorWaybillDispatch(Request $request){
|
|
|
if ($request->input('type')=='直发车'){
|
|
|
$validator=Validator::make($request->input(),[
|
|
|
- 'carrier_bill'=>'required|alpha_num|max:50|unique:waybills,carrier_bill',
|
|
|
+ 'carrier_bill'=>'nullable|max:50|unique:waybills,carrier_bill',
|
|
|
'fee'=>'required|min:0|numeric|max:999999',
|
|
|
'other_fee'=>'nullable|min:0|numeric|max:999999',
|
|
|
'charge'=>'nullable|min:0|numeric|max:999999',
|
|
|
@@ -559,14 +594,15 @@ class WaybillsController extends Controller
|
|
|
return $validator;
|
|
|
}else if ($request->input('type')=='专线'){
|
|
|
$validator=Validator::make($request->input(),[
|
|
|
- 'carrier_bill'=>'required|alpha_num|max:50|unique:waybills,carrier_bill',
|
|
|
- 'warehouse_weight'=>'required|min:0|numeric|max:999999',
|
|
|
- 'carrier_weight'=>'required|min:0|numeric|max:999999',
|
|
|
- 'pick_up_fee'=>'required|min:0|numeric|max:999999',
|
|
|
+ 'carrier_bill'=>'nullable|max:50|unique:waybills,carrier_bill',
|
|
|
+ 'warehouse_weight'=>'nullable|min:0|numeric|max:999999',
|
|
|
+ 'carrier_weight'=>'nullable|min:0|numeric|max:999999',
|
|
|
+ 'pick_up_fee'=>'nullable|min:0|numeric|max:999999',
|
|
|
'other_fee'=>'nullable|min:0|numeric|max:999999',
|
|
|
'carrier_id'=>'required|integer',
|
|
|
'destination_city_id'=>'required|integer',
|
|
|
- 'carrier_weight_unit_id'=>'required|integer',
|
|
|
+ 'warehouse_weight_unit_id'=>'nullable|integer',
|
|
|
+ 'carrier_weight_unit_id'=>'nullable|integer',
|
|
|
'charge'=>'nullable|min:0|numeric|max:999999',
|
|
|
],[
|
|
|
'required'=>':attribute 为必填项',
|
|
|
@@ -577,14 +613,15 @@ class WaybillsController extends Controller
|
|
|
'unique'=>':attribute 已存在',
|
|
|
],[
|
|
|
'carrier_bill'=>'承运商单号',
|
|
|
- 'warehouse_weight'=>'仓库计重(抛)',
|
|
|
- 'carrier_weight'=>'承运商计重(抛)',
|
|
|
+ 'warehouse_weight'=>'仓库计数(抛)',
|
|
|
+ 'carrier_weight'=>'承运商计数(抛)',
|
|
|
'pick_up_fee'=>'提货费',
|
|
|
'other_fee'=>'其他费用',
|
|
|
'carrier_id'=>'承运商',
|
|
|
'destination_city_id'=>'目的市',
|
|
|
'carrier_weight_unit_id'=>'承运商计重单位',
|
|
|
'charge'=>'收费',
|
|
|
+ 'warehouse_weight_unit_id'=>'仓库计重单位',
|
|
|
]);
|
|
|
return $validator;
|
|
|
}else{
|