WaybillFinancialSnapshotsController.php 7.4 KB

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