WaybillFinancialSnapshotsController.php 11 KB

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