| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\Export;
- use App\WaybillFinancialSnapshot;
- use Carbon\Carbon;
- use Exception;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Gate;
- use Illuminate\Support\Facades\Http;
- use Maatwebsite\Excel\Facades\Excel;
- class WaybillFinancialSnapshotsController extends Controller
- {
- public function conditionQuery(Request $request,$waybillFinancialSnapshots){
- if ($request->input('created_at_start')){
- $created_at_start=$request->input('created_at_start')." 00:00:00";
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>=',$created_at_start);
- }
- if ($request->input('created_at_end')){
- $created_at_end=$request->input('created_at_end')." 23:59:59";
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<=',$created_at_end);
- }
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
- return $waybillFinancialSnapshots;
- }
- public function index(Request $request)
- {
- if(!Gate::allows('财务报表')){ return redirect(url('/')); }
- $waybillFinancialSnapshots=WaybillFinancialSnapshot::query()->orderBy('id', 'DESC');
- $type='';
- if ($request->type=='ZF'){
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%直发车%');
- $type='ZF';
- }
- if ($request->type=='ZX'){
- $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('json_content','like','%专线%');
- $type='ZX';
- }
- $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
- return view('transport.waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>$type]);
- }
- public function export(Request $request){
- if(!Gate::allows('财务报表')){ return '没有权限'; }
- if ($request->checkAllSign){
- $param = $request->input();
- unset($param['checkAllSign']);
- $sql = app('WaybillFinancialService')->getSql($param);
- }else{
- $sql = app('WaybillFinancialService')->getSql(['waybill_id'=>$request->data]);
- }
- $e = new \Oursdreams\Export\Export();
- $e->setMysqlConnection(config('database.connections.mysql.host'),
- config('database.connections.mysql.port'),config('database.connections.mysql.database')
- ,config('database.connections.mysql.username'),config('database.connections.mysql.password'));
- $e->setFileName("财务报表");
- return $e->sql($sql,[
- "type"=>"运单类型","waybill_number"=>"运单号",
- "owner_name"=>"货主","wms_bill_number"=>"WMS单号",
- "origination"=>"始发地","destination"=>"目的地",
- "recipient"=>"收件人","recipient_mobile"=>"收件人电话",
- "charge"=>"收费(元)","ordering_remark"=>"下单备注",
- "carrier"=>"承运商","carrier_bill"=>"承运商单号",
- "origination_city"=>"始发市","destination_city"=>"目的市",
- "warehouse_weight"=>"仓库计数(抛)","warehouse_weight_other"=>"仓库计数二",
- "carrier_weight"=>"承运商计数(抛)","carrier_weight_other"=>"承运商计数二",
- "car_type_name"=>"车型","car_owner_info"=>"车辆信息",
- "fee"=>"运费(元)","pick_up_fee"=>"提货费(元)",
- "other_fee"=>"其他费用(元)","collect_fee"=>"到付金额(元)",
- "dispatch_remark"=>"调度备注","auditLog_user_name"=>"终审人员",
- "created_at"=>"运单创建时间","total_receivable"=>"应收款(元)",
- "total_expense"=>"应付款(元)","gross_margin"=>"毛利(元)",
- "gross_profit_rate"=>"毛利率","snapshotCreated_at"=>"报表生成时间",
- ])->direct();
- }
- }
|