WaybillFinancialSnapshotsController.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\WaybillExport;
  4. use App\WaybillFinancialSnapshot;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\Gate;
  8. use Maatwebsite\Excel\Facades\Excel;
  9. class WaybillFinancialSnapshotsController extends Controller
  10. {
  11. public function index(Request $request)
  12. {
  13. if(!Gate::allows('财务报表-查询')){ return redirect(url('/')); }
  14. $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC');
  15. if ($request->input('type')=='直发'){
  16. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发%');
  17. }
  18. if($request->input('type')=='专线'){
  19. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
  20. }
  21. if ($request->input('created_at_start')){
  22. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
  23. }
  24. if ($request->input('created_at_end')){
  25. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
  26. }
  27. $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
  28. return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$request->input('type')]);
  29. }
  30. public function export($id){
  31. $id = explode( ',',$id);
  32. $row=[[
  33. 'type'=>'运单类型',
  34. 'waybill_number'=>'运单号',
  35. 'owner'=>'货主',
  36. 'wms_bill_number'=>'WMS单号',
  37. 'origination'=>'始发地',
  38. 'destination'=>'目的地',
  39. 'recipient'=>'收件人',
  40. 'recipient_mobile'=>'收件人电话',
  41. 'charge'=>'收费(元)',
  42. 'ordering_remark'=>'下单备注',
  43. 'carrier'=>'承运商',
  44. 'carrier_bill'=>'承运商单号',
  45. 'origination_city'=>'始发市',
  46. 'destination_city'=>'目的市',
  47. 'warehouse_weight'=>'仓库计重(抛)',
  48. 'warehouse_weight_unit'=>'仓库计重单位 ',
  49. 'carrier_weight'=>'承运商计重(抛)',
  50. 'carrier_weight_unit'=>'承运商计重单位',
  51. 'carType'=>'车型',
  52. 'fee'=>'运费(元)',
  53. 'pick_up_fee'=>'提货费(元)',
  54. 'other_fee'=>'其他费用(元)',
  55. 'collect_fee'=>'到付金额(元)',
  56. 'dispatch_remark'=>'调度备注',
  57. 'waybillAuditor'=>'运单审核人',
  58. 'dispatchAuditor'=>'调度审核人',
  59. 'created_at'=>'运单创建时间',
  60. 'total_receivable'=>'应收款(元)',
  61. 'total_expense'=>'应付款(元)',
  62. 'gross_margin'=>'毛利(元)',
  63. 'gross_profit_rate'=>'毛利率(元)',
  64. 'snapshotCreated_at'=>'报表生成时间',
  65. ]];
  66. $list=[];
  67. for ($i=0; $i<count($id);$i++){
  68. $waybillFinancialSnapshot=WaybillFinancialSnapshot::where('waybill_id','=',$id[$i])->first();
  69. $waybillFinancialSnapshot=json_decode($waybillFinancialSnapshot->json_content);
  70. $waybillAuditor='';
  71. $dispatchAuditor='';
  72. foreach ($waybillFinancialSnapshot->waybill->audit_logs as $auditLog){
  73. if ($auditLog->audit_stage=="运单阶段"){
  74. $waybillAuditor=$auditLog->user->name;
  75. }
  76. if ($auditLog->audit_stage=="调度阶段"){
  77. $dispatchAuditor=$auditLog->user->name;
  78. }
  79. };
  80. $w=[
  81. 'type'=>isset($waybillFinancialSnapshot->waybill->type)?$waybillFinancialSnapshot->waybill->type:'',
  82. 'waybill_number'=>isset($waybillFinancialSnapshot->waybill->waybill_number)?$waybillFinancialSnapshot->waybill->waybill_number:'',
  83. 'owner'=>isset($waybillFinancialSnapshot->waybill->owner->name)?$waybillFinancialSnapshot->waybill->owner->name:'',
  84. 'wms_bill_number'=>isset($waybillFinancialSnapshot->waybill->wms_bill_number)?$waybillFinancialSnapshot->waybill->wms_bill_number:'',
  85. 'origination'=>isset($waybillFinancialSnapshot->waybill->origination)?$waybillFinancialSnapshot->waybill->origination:'',
  86. 'destination'=>isset($waybillFinancialSnapshot->waybill->destination)?$waybillFinancialSnapshot->waybill->destination:'',
  87. 'recipient'=>isset($waybillFinancialSnapshot->waybill->recipient)?$waybillFinancialSnapshot->waybill->recipient:'',
  88. 'recipient_mobile'=>isset($waybillFinancialSnapshot->waybill->recipient_mobile)?$waybillFinancialSnapshot->waybill->recipient_mobile:'',
  89. 'charge'=>isset($waybillFinancialSnapshot->waybill->charge)?$waybillFinancialSnapshot->waybill->charge:'',
  90. 'ordering_remark'=>isset($waybillFinancialSnapshot->waybill->ordering_remark)?$waybillFinancialSnapshot->waybill->ordering_remark:'',
  91. 'carrier'=>isset($waybillFinancialSnapshot->waybill->carrier->name)?$waybillFinancialSnapshot->waybill->carrier->name:'',
  92. 'carrier_bill'=>isset($waybillFinancialSnapshot->waybill->carrier_bill)?$waybillFinancialSnapshot->waybill->carrier_bill:'',
  93. 'origination_city'=>isset($waybillFinancialSnapshot->waybill->origination_city->name)?$waybillFinancialSnapshot->waybill->origination_city->name:'',
  94. 'destination_city'=>isset($waybillFinancialSnapshot->waybill->destination_city->name)?$waybillFinancialSnapshot->waybill->destination_city->name:'',
  95. 'warehouse_weight'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight)?$waybillFinancialSnapshot->waybill->warehouse_weight:'',
  96. 'warehouse_weight_unit'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit->name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit->name:'',
  97. 'carrier_weight'=>isset($waybillFinancialSnapshot->waybill->carrier_weight)?$waybillFinancialSnapshot->waybill->carrier_weight:'',
  98. 'carrier_weight_unit'=>isset($waybillFinancialSnapshot->waybill->carrier_weight_unit->name)?$waybillFinancialSnapshot->waybill->carrier_weight_unit->name:'',
  99. 'carType'=>isset($waybillFinancialSnapshot->waybill->carType->name)?$waybillFinancialSnapshot->waybill->carType->name.($waybillFinancialSnapshot->waybill->carType->length.'米'):'',
  100. 'fee'=>isset($waybillFinancialSnapshot->waybill->fee)?$waybillFinancialSnapshot->waybill->fee:'',
  101. 'pick_up_fee'=>isset($waybillFinancialSnapshot->waybill->pick_up_fee)?$waybillFinancialSnapshot->waybill->pick_up_fee:'',
  102. 'other_fee'=>isset($waybillFinancialSnapshot->waybill->other_fee)?$waybillFinancialSnapshot->waybill->other_fee:'',
  103. 'collect_fee'=>isset($waybillFinancialSnapshot->waybill->collect_fee)?$waybillFinancialSnapshot->waybill->collect_fee:'',
  104. 'dispatch_remark'=>isset($waybillFinancialSnapshot->waybill->dispatch_remark)?$waybillFinancialSnapshot->waybill->dispatch_remark:'',
  105. 'waybillAuditor'=>isset($waybillAuditor)?$waybillAuditor:'',
  106. 'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
  107. 'created_at'=>isset($waybillFinancialSnapshot->waybill->created_at)?$waybillFinancialSnapshot->waybill->created_at:'',
  108. 'total_receivable'=>isset($waybillFinancialSnapshot->total_receivable)?$waybillFinancialSnapshot->total_receivable:'',
  109. 'total_expense'=>isset($waybillFinancialSnapshot->total_expense)?$waybillFinancialSnapshot->total_expense:'',
  110. 'gross_margin'=>isset($waybillFinancialSnapshot->gross_margin)?$waybillFinancialSnapshot->gross_margin:'',
  111. 'gross_profit_rate'=>isset($waybillFinancialSnapshot->gross_profit_rate)?$waybillFinancialSnapshot->gross_profit_rate:'',
  112. 'snapshotCreated_at'=>isset($waybillFinancialSnapshot->created_at)?$waybillFinancialSnapshot->created_at:'',
  113. ];
  114. $list[$i]=$w;
  115. }
  116. $this->log(__METHOD__,__FUNCTION__,json_encode($waybillFinancialSnapshot),Auth::user()['id']);
  117. return Excel::download(new WaybillExport($row,$list), date('Y:m:d ') . '财务报表.xls');
  118. }
  119. }