WaybillFinancialSnapshotsController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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('created_at_start')){
  16. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
  17. }
  18. if ($request->input('created_at_end')){
  19. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
  20. }
  21. $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
  22. return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'']);
  23. }
  24. public function indexZF(Request $request)
  25. {
  26. if(!Gate::allows('财务报表-查询')){ return redirect(url('/')); }
  27. $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC')->where('json_content','like','%直发车%');
  28. if ($request->input('created_at_start')){
  29. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
  30. }
  31. if ($request->input('created_at_end')){
  32. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
  33. }
  34. $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
  35. return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'ZF']);
  36. }
  37. public function indexZX(Request $request)
  38. {
  39. if(!Gate::allows('财务报表-查询')){ return redirect(url('/')); }
  40. $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC')->where('json_content','like','%专线%');
  41. if ($request->input('created_at_start')){
  42. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
  43. }
  44. if ($request->input('created_at_end')){
  45. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
  46. }
  47. $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
  48. return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'ZX']);
  49. }
  50. public function export($id){
  51. $id = explode( ',',$id);
  52. $row=[[
  53. 'type'=>'运单类型',
  54. 'waybill_number'=>'运单号',
  55. 'owner'=>'货主',
  56. 'wms_bill_number'=>'WMS单号',
  57. 'origination'=>'始发地',
  58. 'destination'=>'目的地',
  59. 'recipient'=>'收件人',
  60. 'recipient_mobile'=>'收件人电话',
  61. 'charge'=>'收费(元)',
  62. 'ordering_remark'=>'下单备注',
  63. 'carrier'=>'承运商',
  64. 'carrier_bill'=>'承运商单号',
  65. 'origination_city'=>'始发市',
  66. 'destination_city'=>'目的市',
  67. 'warehouse_weight'=>'仓库计数(抛)',
  68. 'warehouse_weight_other'=>'仓库计数二',
  69. 'carrier_weight'=>'承运商计数(抛)',
  70. 'carrier_weight_other'=>'承运商计数二',
  71. 'carType'=>'车型',
  72. 'car_owner_info'=>'车型',
  73. 'fee'=>'运费(元)',
  74. 'pick_up_fee'=>'提货费(元)',
  75. 'other_fee'=>'其他费用(元)',
  76. 'collect_fee'=>'到付金额(元)',
  77. 'dispatch_remark'=>'调度备注',
  78. 'waybillAuditor'=>'运单审核人',
  79. 'dispatchAuditor'=>'调度审核人',
  80. 'created_at'=>'运单创建时间',
  81. 'total_receivable'=>'应收款(元)',
  82. 'total_expense'=>'应付款(元)',
  83. 'gross_margin'=>'毛利(元)',
  84. 'gross_profit_rate'=>'毛利率(元)',
  85. 'snapshotCreated_at'=>'报表生成时间',
  86. ]];
  87. $list=[];
  88. for ($i=0; $i<count($id);$i++){
  89. $waybillFinancialSnapshot=WaybillFinancialSnapshot::where('waybill_id','=',$id[$i])->first();
  90. $waybillFinancialSnapshot=json_decode($waybillFinancialSnapshot->json_content);
  91. $waybillAuditor='';
  92. $dispatchAuditor='';
  93. foreach ($waybillFinancialSnapshot->waybill->waybill_audit_logs as $waybill_audit_logs){
  94. if ($waybill_audit_logs->audit_stage=="运单阶段"){
  95. $waybillAuditor=$waybill_audit_logs->user->name;
  96. }
  97. if ($waybill_audit_logs->audit_stage=="调度阶段"){
  98. $dispatchAuditor=$waybill_audit_logs->user->name;
  99. }
  100. };
  101. $w=[
  102. 'type'=>isset($waybillFinancialSnapshot->waybill->type)?$waybillFinancialSnapshot->waybill->type:'',
  103. 'waybill_number'=>isset($waybillFinancialSnapshot->waybill->waybill_number)?$waybillFinancialSnapshot->waybill->waybill_number:'',
  104. 'owner'=>isset($waybillFinancialSnapshot->waybill->owner->name)?$waybillFinancialSnapshot->waybill->owner->name:'',
  105. 'wms_bill_number'=>isset($waybillFinancialSnapshot->waybill->wms_bill_number)?$waybillFinancialSnapshot->waybill->wms_bill_number:'',
  106. 'origination'=>isset($waybillFinancialSnapshot->waybill->origination)?$waybillFinancialSnapshot->waybill->origination:'',
  107. 'destination'=>isset($waybillFinancialSnapshot->waybill->destination)?$waybillFinancialSnapshot->waybill->destination:'',
  108. 'recipient'=>isset($waybillFinancialSnapshot->waybill->recipient)?$waybillFinancialSnapshot->waybill->recipient:'',
  109. 'recipient_mobile'=>isset($waybillFinancialSnapshot->waybill->recipient_mobile)?$waybillFinancialSnapshot->waybill->recipient_mobile:'',
  110. 'charge'=>isset($waybillFinancialSnapshot->waybill->charge)?$waybillFinancialSnapshot->waybill->charge:'',
  111. 'ordering_remark'=>isset($waybillFinancialSnapshot->waybill->ordering_remark)?$waybillFinancialSnapshot->waybill->ordering_remark:'',
  112. 'carrier'=>isset($waybillFinancialSnapshot->waybill->carrier->name)?$waybillFinancialSnapshot->waybill->carrier->name:'',
  113. 'carrier_bill'=>isset($waybillFinancialSnapshot->waybill->carrier_bill)?$waybillFinancialSnapshot->waybill->carrier_bill:'',
  114. 'origination_city'=>isset($waybillFinancialSnapshot->waybill->origination_city->name)?$waybillFinancialSnapshot->waybill->origination_city->name:'',
  115. 'destination_city'=>isset($waybillFinancialSnapshot->waybill->destination_city->name)?$waybillFinancialSnapshot->waybill->destination_city->name:'',
  116. 'warehouse_weight'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight)?
  117. $waybillFinancialSnapshot->waybill->warehouse_weight.' '.(isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit_name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit_name:''):'',
  118. 'warehouse_weight_other'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight_other)?
  119. $waybillFinancialSnapshot->waybill->warehouse_weight_other.' '.(isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit_other_name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit_other_name:''):'',
  120. 'carrier_weight'=>isset($waybillFinancialSnapshot->waybill->carrier_weight)?
  121. $waybillFinancialSnapshot->waybill->carrier_weight.' '.(isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit_name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit_name:''):'',
  122. 'carrier_weight_other'=>isset($waybillFinancialSnapshot->waybill->carrier_weight_other)?
  123. $waybillFinancialSnapshot->waybill->carrier_weight_other.' '.(isset($waybillFinancialSnapshot->waybill->carrier_weight_unit_other_name)?$waybillFinancialSnapshot->waybill->carrier_weight_unit_other_name:''):'',
  124. 'carType'=>isset($waybillFinancialSnapshot->waybill->carType->name)?$waybillFinancialSnapshot->waybill->carType->name.($waybillFinancialSnapshot->waybill->carType->length.'米'):'',
  125. 'car_owner_info'=>isset($waybillFinancialSnapshot->waybill->car_owner_info)?$waybillFinancialSnapshot->waybill->car_owner_info:'',
  126. 'fee'=>isset($waybillFinancialSnapshot->waybill->fee)?$waybillFinancialSnapshot->waybill->fee:'',
  127. 'pick_up_fee'=>isset($waybillFinancialSnapshot->waybill->pick_up_fee)?$waybillFinancialSnapshot->waybill->pick_up_fee:'',
  128. 'other_fee'=>isset($waybillFinancialSnapshot->waybill->other_fee)?$waybillFinancialSnapshot->waybill->other_fee:'',
  129. 'collect_fee'=>isset($waybillFinancialSnapshot->waybill->collect_fee)?$waybillFinancialSnapshot->waybill->collect_fee:'',
  130. 'dispatch_remark'=>isset($waybillFinancialSnapshot->waybill->dispatch_remark)?$waybillFinancialSnapshot->waybill->dispatch_remark:'',
  131. 'waybillAuditor'=>isset($waybillAuditor)?$waybillAuditor:'',
  132. 'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
  133. 'created_at'=>isset($waybillFinancialSnapshot->waybill->created_at)?$waybillFinancialSnapshot->waybill->created_at:'',
  134. 'total_receivable'=>isset($waybillFinancialSnapshot->total_receivable)?$waybillFinancialSnapshot->total_receivable:'',
  135. 'total_expense'=>isset($waybillFinancialSnapshot->total_expense)?$waybillFinancialSnapshot->total_expense:'',
  136. 'gross_margin'=>isset($waybillFinancialSnapshot->gross_margin)?$waybillFinancialSnapshot->gross_margin:'',
  137. 'gross_profit_rate'=>isset($waybillFinancialSnapshot->gross_profit_rate)?$waybillFinancialSnapshot->gross_profit_rate:'',
  138. 'snapshotCreated_at'=>isset($waybillFinancialSnapshot->created_at)?$waybillFinancialSnapshot->created_at:'',
  139. ];
  140. $list[$i]=$w;
  141. }
  142. $this->log(__METHOD__,__FUNCTION__,json_encode($waybillFinancialSnapshot),Auth::user()['id']);
  143. return Excel::download(new WaybillExport($row,$list), date('Y:m:d ') . '财务报表.xls');
  144. }
  145. }