| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\WaybillExport;
- use App\WaybillFinancialSnapshot;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Gate;
- use Maatwebsite\Excel\Facades\Excel;
- class WaybillFinancialSnapshotsController extends Controller
- {
- public function index(Request $request)
- {
- if(!Gate::allows('财务报表-查询')){ return redirect(url('/')); }
- $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC');
- if ($request->input('type')=='直发'){
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发%');
- }
- if($request->input('type')=='专线'){
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
- }
- if ($request->input('created_at_start')){
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
- }
- if ($request->input('created_at_end')){
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
- }
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
- return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$request->input('type')]);
- }
- public function export($id){
- $id = explode( ',',$id);
- $row=[[
- 'type'=>'运单类型',
- 'waybill_number'=>'运单号',
- 'owner'=>'货主',
- 'wms_bill_number'=>'WMS单号',
- 'origination'=>'始发地',
- 'destination'=>'目的地',
- 'recipient'=>'收件人',
- 'recipient_mobile'=>'收件人电话',
- 'charge'=>'收费(元)',
- 'ordering_remark'=>'下单备注',
- 'carrier'=>'承运商',
- 'carrier_bill'=>'承运商单号',
- 'origination_city'=>'始发市',
- 'destination_city'=>'目的市',
- 'warehouse_weight'=>'仓库计重(抛)',
- 'warehouse_weight_unit'=>'仓库计重单位 ',
- 'carrier_weight'=>'承运商计重(抛)',
- 'carrier_weight_unit'=>'承运商计重单位',
- 'carType'=>'车型',
- 'fee'=>'运费(元)',
- 'pick_up_fee'=>'提货费(元)',
- 'other_fee'=>'其他费用(元)',
- 'collect_fee'=>'到付金额(元)',
- 'dispatch_remark'=>'调度备注',
- 'waybillAuditor'=>'运单审核人',
- 'dispatchAuditor'=>'调度审核人',
- 'created_at'=>'运单创建时间',
- 'total_receivable'=>'应收款(元)',
- 'total_expense'=>'应付款(元)',
- 'gross_margin'=>'毛利(元)',
- 'gross_profit_rate'=>'毛利率(元)',
- 'snapshotCreated_at'=>'报表生成时间',
- ]];
- $list=[];
- for ($i=0; $i<count($id);$i++){
- $waybillFinancialSnapshot=WaybillFinancialSnapshot::where('waybill_id','=',$id[$i])->first();
- $waybillFinancialSnapshot=json_decode($waybillFinancialSnapshot->json_content);
- $waybillAuditor='';
- $dispatchAuditor='';
- foreach ($waybillFinancialSnapshot->waybill->audit_logs as $auditLog){
- if ($auditLog->audit_stage=="运单阶段"){
- $waybillAuditor=$auditLog->user->name;
- }
- if ($auditLog->audit_stage=="调度阶段"){
- $dispatchAuditor=$auditLog->user->name;
- }
- };
- $w=[
- 'type'=>isset($waybillFinancialSnapshot->waybill->type)?$waybillFinancialSnapshot->waybill->type:'',
- 'waybill_number'=>isset($waybillFinancialSnapshot->waybill->waybill_number)?$waybillFinancialSnapshot->waybill->waybill_number:'',
- 'owner'=>isset($waybillFinancialSnapshot->waybill->owner->name)?$waybillFinancialSnapshot->waybill->owner->name:'',
- 'wms_bill_number'=>isset($waybillFinancialSnapshot->waybill->wms_bill_number)?$waybillFinancialSnapshot->waybill->wms_bill_number:'',
- 'origination'=>isset($waybillFinancialSnapshot->waybill->origination)?$waybillFinancialSnapshot->waybill->origination:'',
- 'destination'=>isset($waybillFinancialSnapshot->waybill->destination)?$waybillFinancialSnapshot->waybill->destination:'',
- 'recipient'=>isset($waybillFinancialSnapshot->waybill->recipient)?$waybillFinancialSnapshot->waybill->recipient:'',
- 'recipient_mobile'=>isset($waybillFinancialSnapshot->waybill->recipient_mobile)?$waybillFinancialSnapshot->waybill->recipient_mobile:'',
- 'charge'=>isset($waybillFinancialSnapshot->waybill->charge)?$waybillFinancialSnapshot->waybill->charge:'',
- 'ordering_remark'=>isset($waybillFinancialSnapshot->waybill->ordering_remark)?$waybillFinancialSnapshot->waybill->ordering_remark:'',
- 'carrier'=>isset($waybillFinancialSnapshot->waybill->carrier->name)?$waybillFinancialSnapshot->waybill->carrier->name:'',
- 'carrier_bill'=>isset($waybillFinancialSnapshot->waybill->carrier_bill)?$waybillFinancialSnapshot->waybill->carrier_bill:'',
- 'origination_city'=>isset($waybillFinancialSnapshot->waybill->origination_city->name)?$waybillFinancialSnapshot->waybill->origination_city->name:'',
- 'destination_city'=>isset($waybillFinancialSnapshot->waybill->destination_city->name)?$waybillFinancialSnapshot->waybill->destination_city->name:'',
- 'warehouse_weight'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight)?$waybillFinancialSnapshot->waybill->warehouse_weight:'',
- 'warehouse_weight_unit'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit->name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit->name:'',
- 'carrier_weight'=>isset($waybillFinancialSnapshot->waybill->carrier_weight)?$waybillFinancialSnapshot->waybill->carrier_weight:'',
- 'carrier_weight_unit'=>isset($waybillFinancialSnapshot->waybill->carrier_weight_unit->name)?$waybillFinancialSnapshot->waybill->carrier_weight_unit->name:'',
- 'carType'=>isset($waybillFinancialSnapshot->waybill->carType->name)?$waybillFinancialSnapshot->waybill->carType->name.($waybillFinancialSnapshot->waybill->carType->length.'米'):'',
- 'fee'=>isset($waybillFinancialSnapshot->waybill->fee)?$waybillFinancialSnapshot->waybill->fee:'',
- 'pick_up_fee'=>isset($waybillFinancialSnapshot->waybill->pick_up_fee)?$waybillFinancialSnapshot->waybill->pick_up_fee:'',
- 'other_fee'=>isset($waybillFinancialSnapshot->waybill->other_fee)?$waybillFinancialSnapshot->waybill->other_fee:'',
- 'collect_fee'=>isset($waybillFinancialSnapshot->waybill->collect_fee)?$waybillFinancialSnapshot->waybill->collect_fee:'',
- 'dispatch_remark'=>isset($waybillFinancialSnapshot->waybill->dispatch_remark)?$waybillFinancialSnapshot->waybill->dispatch_remark:'',
- 'waybillAuditor'=>isset($waybillAuditor)?$waybillAuditor:'',
- 'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
- 'created_at'=>isset($waybillFinancialSnapshot->waybill->created_at)?$waybillFinancialSnapshot->waybill->created_at:'',
- 'total_receivable'=>isset($waybillFinancialSnapshot->total_receivable)?$waybillFinancialSnapshot->total_receivable:'',
- 'total_expense'=>isset($waybillFinancialSnapshot->total_expense)?$waybillFinancialSnapshot->total_expense:'',
- 'gross_margin'=>isset($waybillFinancialSnapshot->gross_margin)?$waybillFinancialSnapshot->gross_margin:'',
- 'gross_profit_rate'=>isset($waybillFinancialSnapshot->gross_profit_rate)?$waybillFinancialSnapshot->gross_profit_rate:'',
- 'snapshotCreated_at'=>isset($waybillFinancialSnapshot->created_at)?$waybillFinancialSnapshot->created_at:'',
- ];
- $list[$i]=$w;
- }
- $this->log(__METHOD__,__FUNCTION__,json_encode($waybillFinancialSnapshot),Auth::user()['id']);
- return Excel::download(new WaybillExport($row,$list), date('Y:m:d ') . '财务报表.xls');
- }
- }
|