WaybillFinancialSnapshotsController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\Export;
  4. use App\WaybillFinancialSnapshot;
  5. use Carbon\Carbon;
  6. use Exception;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\Gate;
  10. use Illuminate\Support\Facades\Http;
  11. use Maatwebsite\Excel\Facades\Excel;
  12. class WaybillFinancialSnapshotsController extends Controller
  13. {
  14. public function conditionQuery(Request $request,$waybillFinancialSnapshots){
  15. if ($request->input('created_at_start')){
  16. $created_at_start=$request->input('created_at_start')." 00:00:00";
  17. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>=',$created_at_start);
  18. }
  19. if ($request->input('created_at_end')){
  20. $created_at_end=$request->input('created_at_end')." 23:59:59";
  21. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<=',$created_at_end);
  22. }
  23. $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
  24. return $waybillFinancialSnapshots;
  25. }
  26. public function index(Request $request)
  27. {
  28. if(!Gate::allows('财务报表')){ return redirect(url('/')); }
  29. $waybillFinancialSnapshots=WaybillFinancialSnapshot::query()->orderBy('id', 'DESC');
  30. $type='';
  31. if ($request->type=='ZF'){
  32. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发车%');
  33. $type='ZF';
  34. }
  35. if ($request->type=='ZX'){
  36. $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
  37. $type='ZX';
  38. }
  39. $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
  40. return view('transport.waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$type]);
  41. }
  42. public function export(Request $request){
  43. if(!Gate::allows('财务报表')){ return '没有权限'; }
  44. if ($request->checkAllSign){
  45. $param = $request->input();
  46. unset($param['checkAllSign']);
  47. $sql = app('WaybillFinancialService')->getSql($param);
  48. }else{
  49. $sql = app('WaybillFinancialService')->getSql(['waybill_id'=>$request->data]);
  50. }
  51. $e = new \Oursdreams\Export\Export();
  52. $e->setMysqlConnection(config('database.connections.mysql.host'),
  53. config('database.connections.mysql.port'),config('database.connections.mysql.database')
  54. ,config('database.connections.mysql.username'),config('database.connections.mysql.password'));
  55. $e->setFileName("财务报表");
  56. return $e->sql($sql,[
  57. "type"=>"运单类型","waybill_number"=>"运单号",
  58. "owner_name"=>"货主","wms_bill_number"=>"WMS单号",
  59. "origination"=>"始发地","destination"=>"目的地",
  60. "recipient"=>"收件人","recipient_mobile"=>"收件人电话",
  61. "charge"=>"收费(元)","ordering_remark"=>"下单备注",
  62. "carrier"=>"承运商","carrier_bill"=>"承运商单号",
  63. "origination_city"=>"始发市","destination_city"=>"目的市",
  64. "warehouse_weight"=>"仓库计数(抛)","warehouse_weight_other"=>"仓库计数二",
  65. "carrier_weight"=>"承运商计数(抛)","carrier_weight_other"=>"承运商计数二",
  66. "car_type_name"=>"车型","car_owner_info"=>"车辆信息",
  67. "fee"=>"运费(元)","pick_up_fee"=>"提货费(元)",
  68. "other_fee"=>"其他费用(元)","collect_fee"=>"到付金额(元)",
  69. "dispatch_remark"=>"调度备注","auditLog_user_name"=>"终审人员",
  70. "created_at"=>"运单创建时间","total_receivable"=>"应收款(元)",
  71. "total_expense"=>"应付款(元)","gross_margin"=>"毛利(元)",
  72. "gross_profit_rate"=>"毛利率","snapshotCreated_at"=>"报表生成时间",
  73. ])->direct();
  74. }
  75. }