| 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

1 | <?php
2 |
3 | namespace App\Http\Controllers;
4 |
5 | use App\Exports\WaybillExport;
6 | use App\WaybillFinancialSnapshot;
7 | use Illuminate\Support\Facades\Gate;
8 | use Maatwebsite\Excel\Facades\Excel;
9 |
10 | class WaybillFinancialSnapshotsController extends Controller
11 | {
12 | public function index()
13 | {
14 | if(!Gate::allows('财务报表-查询')){ return redirect(url('/')); }
15 | $waybillFinancialSnapshots=WaybillFinancialSnapshot::paginate(10);
16 | return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots]);
17 | }
18 |
19 | public function export($id){
20 | $id = explode( ',',$id);
21 | $row=[[
22 | 'type'=>'运单类型',
23 | 'waybill_number'=>'运单号',
24 | 'owner'=>'货主',
25 | 'wms_bill_number'=>'WMS单号',
26 | 'origination'=>'始发地',
27 | 'destination'=>'目的地',
28 | 'recipient'=>'收件人',
29 | 'recipient_mobile'=>'收件人电话',
30 | 'charge'=>'收费(元)',
31 | 'ordering_remark'=>'下单备注',
32 | 'carrier'=>'承运商',
33 | 'carrier_bill'=>'承运商单号',
34 | 'origination_city'=>'始发市',
35 | 'destination_city'=>'目的市',
36 | 'warehouse_weight'=>'仓库计重(抛)',
37 | 'warehouse_weight_unit'=>'仓库计重单位 ',
38 | 'carrier_weight'=>'承运商计重(抛)',
39 | 'carrier_weight_unit'=>'承运商计重单位',
40 | 'carType'=>'车型',
41 | 'fee'=>'运费(元)',
42 | 'pick_up_fee'=>'提货费(元)',
43 | 'other_fee'=>'其他费用(元)',
44 | 'collect_fee'=>'到付金额(元)',
45 | 'dispatch_remark'=>'调度备注',
46 | 'waybillAuditor'=>'运单审核人',
47 | 'dispatchAuditor'=>'调度审核人',
48 | 'created_at'=>'运单创建时间',
49 | 'total_receivable'=>'应收款(元)',
50 | 'total_expense'=>'应付款(元)',
51 | 'gross_margin'=>'毛利(元)',
52 | 'gross_profit_rate'=>'毛利率(元)',
53 | 'snapshotCreated_at'=>'报表生成时间',
54 | ]];
55 | $list=[];
56 | for ($i=0; $i<count($id);$i++){
57 | $waybillFinancialSnapshot=WaybillFinancialSnapshot::where('waybill_id','=',$id[$i])->first();
58 | $waybillFinancialSnapshot=json_decode($waybillFinancialSnapshot->json_content);
59 | $waybillAuditor='';
60 | $dispatchAuditor='';
61 | foreach ($waybillFinancialSnapshot->waybill->waybillAuditLogs as $waybillAuditLog){
62 | if ($waybillAuditLog->audit_stage=="运单阶段"){
63 | $waybillAuditor=$waybillAuditLog->user->name;
64 | }
65 | if ($waybillAuditLog->audit_stage=="调度阶段"){
66 | $dispatchAuditor=$waybillAuditLog->user->name;
67 | }
68 | };
69 | $w=[
70 | 'type'=>isset($waybillFinancialSnapshot->waybill->type)?$waybillFinancialSnapshot->waybill->type:'',
71 | 'waybill_number'=>isset($waybillFinancialSnapshot->waybill->waybill_number)?$waybillFinancialSnapshot->waybill->waybill_number:'',
72 | 'owner'=>isset($waybillFinancialSnapshot->waybill->owner->name)?$waybillFinancialSnapshot->waybill->owner->name:'',
73 | 'wms_bill_number'=>isset($waybillFinancialSnapshot->waybill->wms_bill_number)?$waybillFinancialSnapshot->waybill->wms_bill_number:'',
74 | 'origination'=>isset($waybillFinancialSnapshot->waybill->origination)?$waybillFinancialSnapshot->waybill->origination:'',
75 | 'destination'=>isset($waybillFinancialSnapshot->waybill->destination)?$waybillFinancialSnapshot->waybill->destination:'',
76 | 'recipient'=>isset($waybillFinancialSnapshot->waybill->recipient)?$waybillFinancialSnapshot->waybill->recipient:'',
77 | 'recipient_mobile'=>isset($waybillFinancialSnapshot->waybill->recipient_mobile)?$waybillFinancialSnapshot->waybill->recipient_mobile:'',
78 | 'charge'=>isset($waybillFinancialSnapshot->waybill->charge)?$waybillFinancialSnapshot->waybill->charge:'',
79 | 'ordering_remark'=>isset($waybillFinancialSnapshot->waybill->ordering_remark)?$waybillFinancialSnapshot->waybill->ordering_remark:'',
80 | 'carrier'=>isset($waybillFinancialSnapshot->waybill->carrier->name)?$waybillFinancialSnapshot->waybill->carrier->name:'',
81 | 'carrier_bill'=>isset($waybillFinancialSnapshot->waybill->carrier_bill)?$waybillFinancialSnapshot->waybill->carrier_bill:'',
82 | 'origination_city'=>isset($waybillFinancialSnapshot->waybill->origination_city->name)?$waybillFinancialSnapshot->waybill->origination_city->name:'',
83 | 'destination_city'=>isset($waybillFinancialSnapshot->waybill->destination_city->name)?$waybillFinancialSnapshot->waybill->destination_city->name:'',
84 | 'warehouse_weight'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight)?$waybillFinancialSnapshot->waybill->warehouse_weight:'',
85 | 'warehouse_weight_unit'=>isset($waybillFinancialSnapshot->waybill->warehouse_weight_unit->name)?$waybillFinancialSnapshot->waybill->warehouse_weight_unit->name:'',
86 | 'carrier_weight'=>isset($waybillFinancialSnapshot->waybill->carrier_weight)?$waybillFinancialSnapshot->waybill->carrier_weight:'',
87 | 'carrier_weight_unit'=>isset($waybillFinancialSnapshot->waybill->carrier_weight_unit->name)?$waybillFinancialSnapshot->waybill->carrier_weight_unit->name:'',
88 | 'carType'=>isset($waybillFinancialSnapshot->waybill->carType->name)?$waybillFinancialSnapshot->waybill->carType->name.($waybillFinancialSnapshot->waybill->carType->length.'米'):'',
89 | 'fee'=>isset($waybillFinancialSnapshot->waybill->fee)?$waybillFinancialSnapshot->waybill->fee:'',
90 | 'pick_up_fee'=>isset($waybillFinancialSnapshot->waybill->pick_up_fee)?$waybillFinancialSnapshot->waybill->pick_up_fee:'',
91 | 'other_fee'=>isset($waybillFinancialSnapshot->waybill->other_fee)?$waybillFinancialSnapshot->waybill->other_fee:'',
92 | 'collect_fee'=>isset($waybillFinancialSnapshot->waybill->collect_fee)?$waybillFinancialSnapshot->waybill->collect_fee:'',
93 | 'dispatch_remark'=>isset($waybillFinancialSnapshot->waybill->dispatch_remark)?$waybillFinancialSnapshot->waybill->dispatch_remark:'',
94 | 'waybillAuditor'=>isset($waybillAuditor)?$waybillAuditor:'',
95 | 'dispatchAuditor'=>isset($dispatchAuditor)?$dispatchAuditor:'',
96 | 'created_at'=>isset($waybillFinancialSnapshot->waybill->created_at)?$waybillFinancialSnapshot->waybill->created_at:'',
97 | 'total_receivable'=>isset($waybillFinancialSnapshot->total_receivable)?$waybillFinancialSnapshot->total_receivable:'',
98 | 'total_expense'=>isset($waybillFinancialSnapshot->total_expense)?$waybillFinancialSnapshot->total_expense:'',
99 | 'gross_margin'=>isset($waybillFinancialSnapshot->gross_margin)?$waybillFinancialSnapshot->gross_margin:'',
100 | 'gross_profit_rate'=>isset($waybillFinancialSnapshot->gross_profit_rate)?$waybillFinancialSnapshot->gross_profit_rate:'',
101 | 'snapshotCreated_at'=>isset($waybillFinancialSnapshot->created_at)?$waybillFinancialSnapshot->created_at:'',
102 | ];
103 | $list[$i]=$w;
104 | }
105 | $this->log(__METHOD__,__FUNCTION__,json_encode($waybillFinancialSnapshot),Auth::user()['id']);
106 | return Excel::download(new WaybillExport($row,$list), date('Y:m:d ') . '财务报表.xls');
107 | }
108 | }