Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
5.88% covered (danger)
5.88%
3 / 51
WaybillFinancialSnapshotsController
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
1307.07
5.88% covered (danger)
5.88%
3 / 51
 index
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 export
0.00% covered (danger)
0.00%
0 / 1
1406.00
0.00% covered (danger)
0.00%
0 / 48
<?php
namespace App\Http\Controllers;
use App\Exports\WaybillExport;
use App\WaybillFinancialSnapshot;
use Illuminate\Support\Facades\Gate;
use Maatwebsite\Excel\Facades\Excel;
class WaybillFinancialSnapshotsController extends Controller
{
    public function index()
    {
        if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
        $waybillFinancialSnapshots=WaybillFinancialSnapshot::paginate(10);
        return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots]);
    }
    public function export($id){
        $id = explode( ',',$id);
        $row=[[
            'type'=>'运单类型',
            'waybill_number'=>'运单号',
            'owner'=>'货主',
            'wms_bill_number'=>'WMS单号',
            'origination'=>'始发地',
            'destination'=>'目的地',
            'recipient'=>'收件人',
            'recipient_mobile'=>'收件人电话',
            'charge'=>'收费(元)',
            'ordering_remark'=>'下单备注',
            'carrier'=>'承运商',
            'carrier_bill'=>'承运商单号',
            'origination_city'=>'始发市',
            'destination_city'=>'目的市',
            'warehouse_weight'=>'仓库计重(抛)',
            'warehouse_weight_unit'=>'仓库计重单位    ',
            'carrier_weight'=>'承运商计重(抛)',
            'carrier_weight_unit'=>'承运商计重单位',
            'carType'=>'车型',
            'fee'=>'运费(元)',
            'pick_up_fee'=>'提货费(元)',
            'other_fee'=>'其他费用(元)',
            'collect_fee'=>'到付金额(元)',
            'dispatch_remark'=>'调度备注',
            'waybillAuditor'=>'运单审核人',
            'dispatchAuditor'=>'调度审核人',
            'created_at'=>'运单创建时间',
            'total_receivable'=>'应收款(元)',
            'total_expense'=>'应付款(元)',
            'gross_margin'=>'毛利(元)',
            'gross_profit_rate'=>'毛利率(元)',
            'snapshotCreated_at'=>'报表生成时间',
        ]];
        $list=[];
        for ($i=0; $i<count($id);$i++){
            $waybillFinancialSnapshot=WaybillFinancialSnapshot::where('waybill_id','=',$id[$i])->first();
            $waybillFinancialSnapshot=json_decode($waybillFinancialSnapshot->json_content);
            $waybillAuditor='';
            $dispatchAuditor='';
            foreach ($waybillFinancialSnapshot->waybill->waybillAuditLogs as $waybillAuditLog){
                if ($waybillAuditLog->audit_stage=="运单阶段"){
                    $waybillAuditor=$waybillAuditLog->user->name;
                }
                if ($waybillAuditLog->audit_stage=="调度阶段"){
                    $dispatchAuditor=$waybillAuditLog->user->name;
                }
            };
            $w=[
                'type'=>isset($waybillFinancialSnapshot->waybill->type)?$waybillFinancialSnapshot->waybill->type:'',
                'waybill_number'=>isset($waybillFinancialSnapshot->waybill->waybill_number)?$waybillFinancialSnapshot->waybill->waybill_number:'',
                'owner'=>isset($waybillFinancialSnapshot->waybill->owner->name)?$waybillFinancialSnapshot->waybill->owner->name:'',
                'wms_bill_number'=>isset($waybillFinancialSnapshot->waybill->wms_bill_number)?$waybillFinancialSnapshot->waybill->wms_bill_number:'',
                'origination'=>isset($waybillFinancialSnapshot->waybill->origination)?$waybillFinancialSnapshot->waybill->origination:'',
                'destination'=>isset($waybillFinancialSnapshot->waybill->destination)?$waybillFinancialSnapshot->waybill->destination:'',
                'recipient'=>isset($waybillFinancialSnapshot->waybill->recipient)?$waybillFinancialSnapshot->waybill->recipient:'',
                'recipient_mobile'=>isset($waybillFinancialSnapshot->waybill->recipient_mobile)?$waybillFinancialSnapshot->waybill->recipient_mobile:'',
                'charge'=>isset($waybillFinancialSnapshot->waybill->charge)?$waybillFinancialSnapshot->waybill->charge:'',
                'ordering_remark'=>isset($waybillFinancialSnapshot->waybill->ordering_remark)?$waybillFinancialSnapshot->waybill->ordering_remark:'',
                'carrier'=>isset($waybillFinancialSnapshot->waybill->carrier->name)?$waybillFinancialSnapshot->waybill->carrier->name:'',
                'carrier_bill'=>isset($waybillFinancialSnapshot->waybill->carrier_bill)?$waybillFinancialSnapshot->waybill->carrier_bill:'',
                'origination_city'=>isset($waybillFinancialSnapshot->waybill->origination_city->name)?$waybillFinancialSnapshot->waybill->origination_city->name:'',
                'destination_city'=>isset($waybillFinancialSnapshot->waybill->destination_city->name)?$waybillFinancialSnapshot->waybill->destination_city->name:'',
                'warehouse_weight'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight)?$waybillFinancialSnapshot->waybill->warehouse_weight:'',
                'warehouse_weight_unit'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit->name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit->name:'',
                'carrier_weight'=>isset($waybillFinancialSnapshot->waybill->carrier_weight)?$waybillFinancialSnapshot->waybill->carrier_weight:'',
                'carrier_weight_unit'=>isset($waybillFinancialSnapshot->waybill->carrier_weight_unit->name)?$waybillFinancialSnapshot->waybill->carrier_weight_unit->name:'',
                'carType'=>isset($waybillFinancialSnapshot->waybill->carType->name)?$waybillFinancialSnapshot->waybill->carType->name.($waybillFinancialSnapshot->waybill->carType->length.'米'):'',
                'fee'=>isset($waybillFinancialSnapshot->waybill->fee)?$waybillFinancialSnapshot->waybill->fee:'',
                'pick_up_fee'=>isset($waybillFinancialSnapshot->waybill->pick_up_fee)?$waybillFinancialSnapshot->waybill->pick_up_fee:'',
                'other_fee'=>isset($waybillFinancialSnapshot->waybill->other_fee)?$waybillFinancialSnapshot->waybill->other_fee:'',
                'collect_fee'=>isset($waybillFinancialSnapshot->waybill->collect_fee)?$waybillFinancialSnapshot->waybill->collect_fee:'',
                'dispatch_remark'=>isset($waybillFinancialSnapshot->waybill->dispatch_remark)?$waybillFinancialSnapshot->waybill->dispatch_remark:'',
                'waybillAuditor'=>isset($waybillAuditor)?$waybillAuditor:'',
                'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
                'created_at'=>isset($waybillFinancialSnapshot->waybill->created_at)?$waybillFinancialSnapshot->waybill->created_at:'',
                'total_receivable'=>isset($waybillFinancialSnapshot->total_receivable)?$waybillFinancialSnapshot->total_receivable:'',
                'total_expense'=>isset($waybillFinancialSnapshot->total_expense)?$waybillFinancialSnapshot->total_expense:'',
                'gross_margin'=>isset($waybillFinancialSnapshot->gross_margin)?$waybillFinancialSnapshot->gross_margin:'',
                'gross_profit_rate'=>isset($waybillFinancialSnapshot->gross_profit_rate)?$waybillFinancialSnapshot->gross_profit_rate:'',
                'snapshotCreated_at'=>isset($waybillFinancialSnapshot->created_at)?$waybillFinancialSnapshot->created_at:'',
            ];
            $list[$i]=$w;
        }
        $this->log(__METHOD__,__FUNCTION__,json_encode($waybillFinancialSnapshot),Auth::user()['id']);
        return Excel::download(new WaybillExport($row,$list), date('Y:m:d ') . '财务报表.xls');
    }
}