ANG YU 4 lat temu
rodzic
commit
55187493d1

+ 115 - 0
app/Http/Controllers/OwnerStoreOutFeeReportController.php

@@ -0,0 +1,115 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Interfaces\SettlementBillControllerInterface;
+use App\Owner;
+use App\OwnerBillReport;
+use App\OwnerBillReportArchive;
+use App\OwnerStoreOutFeeReport;
+use App\Services\OwnerBillReportArchiveService;
+use App\Services\OwnerStoreOutFeeReportService;
+use App\Traits\SettlementBillTrait;
+use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
+use Oursdreams\Export\Export;
+
+class OwnerStoreOutFeeReportController extends Controller implements SettlementBillControllerInterface
+{
+
+    use SettlementBillTrait;
+
+    //TODO 缺少总计费用
+    /* @var OwnerStoreOutFeeReportService $service */
+    private $service;
+
+    /** @var  $archiveService OwnerBillReportArchiveService */
+    private $archiveService;
+
+    /**
+     * OwnerStoreOutFeeReportController constructor.
+     */
+    public function __construct()
+    {
+        $this->service = app('OwnerStoreOutFeeReportService');
+        $this->archiveService = app('OwnerBillReportArchiveService');
+    }
+
+
+    public function index(Request $request)
+    {
+        list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
+        list($reports, $work_name_fee_total, $fee_total) = $this->service->get([
+            'owner_id' => $owner_id,
+            'counting_month' => $counting_month,
+            'type' => $this->service::TYPE,
+        ]);
+        $owner = Owner::query()->selectRaw("name,id")->find($owner_id);
+        $owners = Owner::query()->selectRaw("id,name")->whereIn('id', $permittingOwnerIds)->get();
+        $isArchived = $this->archiveService->isArchived($counting_month, $owner_id, $this->service::TYPE);
+        $request = $this->buildRequest($request, $counting_month);
+
+        return view('finance.settlementBills.storeOutFee.report.index',
+            compact('reports', 'owners', 'owner', 'isArchived', 'request', 'reports', 'work_name_fee_total', 'fee_total'));
+    }
+
+    public function confirmBill(Request $request): RedirectResponse
+    {
+        list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
+        $billReport = OwnerBillReport::query()
+            ->select('storage_fee', 'id')
+            ->where('owner_id', $owner_id)
+            ->where('counting_month', $counting_month)
+            ->firstOr(function () {
+                return new OwnerBillReport();
+            });
+        list($reports, $work_name_fee_total, $fee_total) = $this->service->get([
+            'owner_id' => $owner_id,
+            'counting_month' => $counting_month,
+            'type' => $this->service::TYPE,
+        ]);
+        OwnerBillReportArchive::query()->create([
+            'owner_bill_report_id' => $billReport->id ?? null,
+            'owner_id' => $owner_id,
+            'counting_month' => $counting_month,
+            'type' => $this->service::TYPE,
+            'archiver_id' => auth()->id(),
+            'archived_at' => now(),
+            'information' => [
+                'reports' => $reports,
+                'work_name_fee_total' => $work_name_fee_total,
+                'fee_total' => $fee_total,
+            ],
+        ]);
+        return back()->with('success', '确认成功');
+    }
+
+    public function export(Request $request)
+    {
+        list($permittingOwnerIds, $counting_month, $owner_id) = $this->getRequestParams($request->year, $request->month, $request->owner_id);
+        list($reports, $work_name_fee_total, $fee_total) = $this->service->get([
+            'owner_id' => $owner_id,
+            'counting_month' => $counting_month,
+            'type' => $this->service::TYPE,
+        ]);
+        $json = [];
+        foreach ($reports as $report) {
+            $fee = '';
+            foreach ($work_name_fee_total as $item) {
+                if ($item['work_name'] == $report['work_name']) {
+                    $fee = $item['fee'];
+                    continue;
+                }
+            }
+            $json[] = [
+                $report['work_name'],
+                $report['step'],
+                $report['unit_price'] . '元/' . $report['unit']['name'] ?? '',
+                $report['amount'],
+                $fee,
+            ];
+        }
+        $row = ['作业名称', '阶梯', '单价', '数量', '合计',];
+        return Export::make($row, $json, "出库费合计");
+    }
+}

+ 1 - 0
app/Interfaces/SettlementBillReportInterface.php

@@ -30,4 +30,5 @@ interface SettlementBillReportInterface
     public function switchType($type);
 
     public function buildExport($details): array;
+
 }

+ 6 - 1
app/OwnerStoreOutFeeDetail.php

@@ -11,7 +11,7 @@ class OwnerStoreOutFeeDetail extends Model
 {
     use ModelLogChanging;
 
-    public $fillable = ['owner_fee_detail_id', 'commodity_id', 'owner_id', 'source_bill', 'work_name', 'price', 'remark'];
+    public $fillable = ['owner_fee_detail_id', 'commodity_id', 'owner_id', 'source_bill', 'work_name', 'unit_price', 'unit_id', 'remark', 'step', 'amount',];
 
     public function ownerFeeDetail(): BelongsTo
     {
@@ -27,4 +27,9 @@ class OwnerStoreOutFeeDetail extends Model
     {
         return $this->belongsTo(Owner::class);
     }
+
+    public function unit(): BelongsTo
+    {
+        return $this->belongsTo(Unit::class);
+    }
 }

+ 37 - 0
app/OwnerStoreOutFeeReport.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class OwnerStoreOutFeeReport extends Model
+{
+    use ModelLogChanging;
+
+    public $fillable = ['owner_bill_report_id', 'owner_price_operation_id', 'counting_month', 'step', 'unit_id', 'unit_price', 'amount', 'fee', 'owner_id', 'work_name'];
+
+    public $timestamps = false;
+
+    public function ownerBillReport(): BelongsTo
+    {
+        return $this->belongsTo(OwnerBillReport::class);
+    }
+
+    public function ownerPriceOperation(): BelongsTo
+    {
+        return $this->belongsTo(OwnerPriceOperation::class);
+    }
+
+    public function unit(): BelongsTo
+    {
+        return $this->belongsTo(Unit::class);
+    }
+
+    public function owner(): BelongsTo
+    {
+        return $this->belongsTo(Owner::class);
+    }
+}

+ 2 - 0
app/Providers/AppServiceProvider.php

@@ -151,6 +151,7 @@ use App\Services\SettlementBillsAreaFeeService;
 use App\Services\OwnerStoreFeeDetailService;
 use App\Services\OwnerStoreFeeReportService;
 use App\Services\OwnerStoreOutFeeDetailService;
+use App\Services\OwnerStoreOutFeeReportService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -305,6 +306,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('OwnerStoreFeeDetailService',OwnerStoreFeeDetailService::class);
         app()->singleton('OwnerStoreFeeReportService',OwnerStoreFeeReportService::class);
         app()->singleton('OwnerStoreOutFeeDetailService',OwnerStoreOutFeeDetailService::class);
+        app()->singleton('OwnerStoreOutFeeReportService',OwnerStoreOutFeeReportService::class);
         app()->singleton('PackageService', PackageService::class);
         app()->singleton('PackageStatisticsService', PackageStatisticsService::class);
         app()->singleton('PrintPartService',PrintPartService::class);

+ 1 - 1
app/Services/OwnerLogisticFeeReportService.php

@@ -40,7 +40,7 @@ class OwnerLogisticFeeReportService
 
 
         $ownerLogisticFeeDetails = OwnerLogisticFeeDetail::query()
-            ->selectRaw("logistic_id,province,DATE_FORMAT(created_at,'%Y-%m-%d') as counted_date,initial_weight,initial_weight_price,count(1) as initial_amount,additional_price,additional_weight,sum(additional_weigh_weight) as additional_amount,created_at,owner_id")
+            ->selectRaw("logistic_id,province,DATE_FORMAT(created_at,'%Y-%m') as counted_date,initial_weight,initial_weight_price,count(1) as initial_amount,additional_price,additional_weight,sum(additional_weigh_weight) as additional_amount,created_at,owner_id")
             ->whereBetween('created_at', [$start, $end])
             ->groupBy('initial_weight', 'initial_weight_price', 'additional_price', 'additional_weight', 'logistic_id', 'province', 'counted_date', 'owner_id')
             ->get();

+ 3 - 2
app/Services/OwnerStoreFeeReportService.php

@@ -5,6 +5,7 @@ namespace App\Services;
 use App\OwnerBillReport;
 use App\Traits\ServiceAppAop;
 use App\OwnerStoreFeeReport;
+use App\Traits\SettlementBillTrait;
 use Carbon\Carbon;
 use Illuminate\Contracts\Pagination\LengthAwarePaginator;
 use Illuminate\Database\Eloquent\Builder;
@@ -15,7 +16,7 @@ class OwnerStoreFeeReportService
     const TYPE = '入库费-合计';
 
     use ServiceAppAop;
-    use \App\Traits\SettlementBillTrait;
+    use SettlementBillTrait;
 
     protected $modelClass = OwnerStoreFeeReport::class;
 
@@ -45,7 +46,7 @@ class OwnerStoreFeeReportService
         $details =
             DB::table('owner_store_fee_details')
                 ->leftJoin('owner_fee_details', 'owner_fee_detail_id', '=', 'owner_fee_details.id')
-                ->selectRaw("DATE_FORMAT(owner_store_fee_details.created_at,'%Y-%m-%d') as counting_month,
+                ->selectRaw("DATE_FORMAT(owner_store_fee_details.created_at,'%Y-%m') as counting_month,
                 owner_store_fee_details.type,unit_id,unit_price,sum(amount) as amounts ,
                 owner_store_fee_details.owner_id,owner_fee_detail_id,
                 sum(owner_fee_details.work_fee) as work_fee")

+ 3 - 3
app/Services/OwnerStoreOutFeeDetailService.php

@@ -31,7 +31,7 @@ class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
         $start = Carbon::parse($counting_month)->startOfMonth()->startOfDay()->toDateTimeString();
         $end = Carbon::parse($counting_month)->endOfMonth()->endOfDay()->toDateTimeString();
         return OwnerStoreOutFeeDetail::query()
-            ->with(['commodity:id,name,sku', 'ownerFeeDetail:id,worked_at,commodity_amount,operation_bill,work_fee'])
+            ->with(['commodity:id,name,sku', 'ownerFeeDetail:id,worked_at,operation_bill,work_fee'])
             ->where('owner_id', $owner_id)
             ->whereBetween('created_at', [$start, $end]);
     }
@@ -53,8 +53,8 @@ class OwnerStoreOutFeeDetailService implements SettlementBillDetailInterface
                 $detail->ownerFeeDetail->operation_bill,
                 $detail->commodity->sku,
                 $detail->commodity->name,
-                $detail->ownerFeeDetail->commodity_amount,
-                $detail->price,
+                $detail->amount,
+                $detail->remark,
                 $detail->ownerFeeDetail->work_fee,
             ];
         }

+ 120 - 0
app/Services/OwnerStoreOutFeeReportService.php

@@ -0,0 +1,120 @@
+<?php
+
+namespace App\Services;
+
+use App\Interfaces\SettlementBillReportInterface;
+use App\OwnerBillReport;
+use App\OwnerStoreFeeReport;
+use App\Traits\ServiceAppAop;
+use App\OwnerStoreOutFeeReport;
+use Carbon\Carbon;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\DB;
+
+class OwnerStoreOutFeeReportService implements SettlementBillReportInterface
+{
+    const TYPE = '出库费-合计';
+
+    use ServiceAppAop;
+
+    protected $modelClass = OwnerStoreOutFeeReport::class;
+    /** @var $detailService OwnerBillReportArchiveService */
+    private $archiveService;
+
+    /** @var $detailService OwnerStoreOutFeeDetailService */
+    private $detailService;
+
+    public function recordReport($counting_month = null)
+    {
+        $this->detailService = app('OwnerStoreOutFeeDetailService');
+        if (is_null($counting_month)) {
+            //默认统计上个月的数据
+            $counting_month = now()->subMonth()->startOfMonth()->toDateString();
+        }
+        $this->reportDate = $counting_month;
+        $start = $this->reportDate;
+        $end = Carbon::parse($this->reportDate)->endOfMonth()->toDateString();
+        $details =
+            DB::table('owner_store_out_fee_details')
+                ->leftJoin('owner_fee_details', 'owner_fee_detail_id', '=', 'owner_fee_details.id')
+                ->selectRaw("DATE_FORMAT(owner_store_out_fee_details.created_at,'%Y-%m') as counting_month,
+                owner_store_out_fee_details.work_name,unit_id,unit_price,sum(amount) as amounts ,
+                owner_store_out_fee_details.owner_id,owner_fee_detail_id,
+                sum(owner_fee_details.work_fee) as work_fee,step")
+                ->whereBetween('owner_store_out_fee_details.created_at', [$start, $end])
+                ->groupBy('counting_month', 'owner_store_out_fee_details.owner_id', 'owner_store_out_fee_details.work_name', 'unit_id', 'unit_price', 'step')
+                ->get();
+        $reports = [];
+        foreach ($details as $detail) {
+            $counting_month = Carbon::parse($detail->counting_month)->startOfMonth()->toDateString();
+            $ownerBillReport = OwnerBillReport::query()
+                ->selectRaw("id")
+                ->where('owner_id', $detail->owner_id)
+                ->where('counting_month', $counting_month)->first();
+            $reports[] = [
+                'owner_bill_report_id' => $ownerBillReport->id ?? null,
+                'owner_price_operation_id' => null,//$detail->ownerFeeDetail->ownerPriceOperation->id??null,
+                'owner_id' => $detail->owner_id,
+                'counting_month' => $counting_month,
+                'step' => $detail->step,
+                'unit_id' => $detail->unit_id,
+                'unit_price' => $detail->unit_price,
+                'amount' => $detail->amounts,
+                'work_name' => $detail->work_name,
+                'fee' => $detail->work_fee,
+            ];
+        }
+        OwnerStoreOutFeeReport::query()->insertOrIgnore($reports);
+    }
+
+    public function getSql($owner_id, $counting_month): Builder
+    {
+        // TODO: Implement getSql() method.
+    }
+
+
+    public function buildExport($details): array
+    {
+        // TODO: Implement buildExport() method.
+    }
+
+
+    public function switchType($type)
+    {
+        // TODO: Implement switchType() method.
+    }
+
+    function get(array $kvPairs)
+    {
+        $this->archiveService = app('OwnerBillReportArchiveService');
+        if ($this->archiveService->isArchived($kvPairs['counting_month'], $kvPairs['owner_id'], $kvPairs['type']) == 1) {
+            //查询存档数据
+            $archived = $this->archiveService->get($kvPairs);
+            $reports = collect($archived->information['reports']);
+            $work_name_fee_total = collect($archived->information['work_name_fee_total']);
+            $fee_total = $archived->information['fee_total'];
+        } else {
+            $reports = OwnerStoreOutFeeReport::query()
+                ->with('unit')
+                ->where('owner_id', $kvPairs['owner_id'])
+                ->where('counting_month', $kvPairs['counting_month'])
+                ->orderBy('work_name')
+                ->get();
+
+            $work_name_fee_total = DB::table('owner_store_out_fee_reports')
+                ->selectRaw("work_name,sum(fee) as fee")
+                ->where('owner_id', $kvPairs['owner_id'])
+                ->where('counting_month', $kvPairs['counting_month'])
+                ->groupBy('work_name')
+                ->get();
+
+            $fee_total = OwnerStoreOutFeeReport::query()
+                ->where('owner_id', $kvPairs['owner_id'])
+                ->where('counting_month', $kvPairs['counting_month'])
+                ->sum('fee');
+        }
+        return array($reports, $work_name_fee_total, $fee_total);
+    }
+
+
+}

+ 8 - 1
database/factories/OwnerStoreOutFeeDetailFactory.php

@@ -17,9 +17,16 @@ $factory->define(OwnerStoreOutFeeDetail::class, function (Faker $faker) {
 
         'work_name' => $faker->title,
 
-        'price' => random_int(1, 100),
+        'unit_price' => random_int(1, 100),
+
+
+        'unit_id' => random_int(1, 10),
+
+        'amount' => random_int(1, 100),
 
         'remark' => $faker->sentence,
+
+        'step' => $faker->title,
         'created_at' => now()->subMonth()->startOfMonth()->addDays(random_int(0, 28)),
         'updated_at' => now()->subMonth()->startOfMonth()->addDays(random_int(0, 28)),
     ];

+ 30 - 0
database/factories/OwnerStoreOutFeeReportFactory.php

@@ -0,0 +1,30 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerStoreOutFeeReport;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerStoreOutFeeReport::class, function (Faker $faker) {
+    return [
+        'owner_bill_report_id'=>random_int(1,100),
+
+        'owner_price_operation_id' => random_int(1, 100),
+
+        'counting_month'=>now()->subMonth()->startOfMonth()->toDateString(),
+
+        'step'=>'100-200',
+
+        'unit_id'=>random_int(1,10),
+
+        'unit_price'=>random_int(1,100),
+
+        'amount'=>random_int(1,100),
+
+        'fee'=>random_int(1,100),
+
+        'owner_id'=>random_int(1,100),
+
+        'work_name'=>$faker->title,
+    ];
+});

+ 4 - 1
database/migrations/2021_06_23_114058_create_owner_store_out_fee_details_table.php

@@ -20,8 +20,11 @@ class CreateOwnerStoreOutFeeDetailsTable extends Migration
             $table->integer('owner_id');
             $table->string('source_bill')->comment('上游单号');
             $table->string('work_name')->comment('作业名称');
-            $table->string('price')->comment('单价');
+            $table->decimal('unit_price')->comment('单价');
+            $table->integer('unit_id')->comment('单价');
             $table->string('remark')->comment('价格描述');
+            $table->string('step')->comment('阶梯');
+            $table->integer('amount');
             $table->timestamps();
         });
     }

+ 40 - 0
database/migrations/2021_06_23_170102_create_owner_store_out_fee_reports_table.php

@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateOwnerStoreOutFeeReportsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('owner_store_out_fee_reports', function (Blueprint $table) {
+            $table->id();
+            $table->integer('owner_bill_report_id');
+            $table->integer('owner_price_operation_id');
+            $table->date('counting_month');
+            $table->string('step')->comment('阶段');
+            $table->integer('unit_id');
+            $table->integer('owner_id');
+            $table->decimal('unit_price')->comment('单价');
+            $table->integer('amount')->comment('数量');
+            $table->decimal('fee')->comment('费用');
+            $table->string('work_name')->comment('作业名称');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('owner_store_out_fee_reports');
+    }
+}

+ 18 - 0
database/seeds/OwnerStoreOutFeeReportSeeder.php

@@ -0,0 +1,18 @@
+<?php
+
+use App\OwnerStoreOutFeeReport;
+use Illuminate\Database\Seeder;
+
+class OwnerStoreOutFeeReportSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        OwnerStoreOutFeeReport::query()->truncate();
+        factory(OwnerStoreOutFeeReport::class)->times(100)->create(['owner_id' => 8]);
+    }
+}

+ 8 - 7
resources/views/finance/settlementBills/storeFee/report/index.blade.php

@@ -82,13 +82,11 @@
                 <tr v-for="(report,i) in reports"
                     @click="selectTr===i+1?selectTr=0:selectTr=i+1"
                     :class="selectTr===i+1?'focusing' : ''">
-                    <td class="text-center pt-4 bg-light"
-                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type==='新品入库'"
-                        :rowspan="calRowspan('新品入库')">@{{ report.type }}
-                    </td>
-                    <td class="text-center pt-4 bg-light"
-                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type==='退货入库'"
-                        :rowspan="calRowspan('退货入库')">@{{ report.type }}
+                    <td
+                        v-for="type in types"
+                        class="text-center pt-4 bg-light"
+                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type===type"
+                        :rowspan="calRowspan(type)">@{{ report.type }}
                     </td>
                     <td>@{{ report.unit_price }}(元/@{{ report.unit.name }})</td>
                     <td>@{{ report.amount }}</td>
@@ -117,6 +115,7 @@
                 isArchived: {!! $isArchived !!},
                 request: {!! $request !!},
                 selectTr: 0,
+                types: null
             },
             created() {
             },
@@ -193,6 +192,8 @@
                     appendDom: 'btn'
                 });
                 _this.form.init();
+
+                this.types = Array.from(new Set(this.reports.map(obj => obj.type)));
             },
             methods: {
                 isShowColumn(preType, type, targetType, i) {

+ 2 - 3
resources/views/finance/settlementBills/storeOutFee/detail/index.blade.php

@@ -61,9 +61,8 @@
                     <td>@{{ detail.owner_fee_detail.operation_bill }}</td>
                     <td>@{{ detail.commodity.sku }}</td>
                     <td>@{{ detail.commodity.name }}</td>
-{{--                    <td>@{{ detail.amount}}</td>--}}
-                    <td>@{{ detail.owner_fee_detail.commodity_amount}}</td>
-                    <td>@{{ detail.price }}</td>
+                    <td>@{{ detail.amount}}</td>
+                    <td>@{{ detail.remark }}</td>
                     <td>@{{ detail.owner_fee_detail.work_fee }}</td>
                 </tr>
             </table>

+ 25 - 29
resources/views/finance/settlementBills/storeOutFee/report/index.blade.php

@@ -27,20 +27,11 @@
                             </span>
                     </div>
                 </div>
-                <div class="col-3">
-                    <div class="row pt-2">
-                        <span class="fa fa-cubes fa-4x offset-md-3" style="color: #9fcdff;opacity: 0.3"></span>
-                        <span class="ml-4 mt-2">
-                                <h5 class="font-weight-bold">{{ $totalAmount }}</h5>
-                                <p class="text-muted">单量合计</p>
-                            </span>
-                    </div>
-                </div>
                 <div class="col-3">
                     <div class="row pt-2">
                         <span class="fa fa-jpy fa-4x offset-md-3" style="color: #2ca02c;opacity: 0.3"></span>
                         <span class="ml-4 mt-2">
-                        <h5 class="font-weight-bold">{{ $totalFee }}</h5>
+                        <h5 class="font-weight-bold">{{ $fee_total }}</h5>
                         <p class="text-muted">总金额</p>
                         </span>
                     </div>
@@ -74,7 +65,8 @@
             </div>
             <table class="table table-striped table-sm text-nowrap table-hover table-bordered">
                 <tr>
-                    <th>名称</th>
+                    <th>作业名称</th>
+                    <th>阶梯</th>
                     <th>单价</th>
                     <th>数量</th>
                     <th>合计</th>
@@ -83,21 +75,18 @@
                     @click="selectTr===i+1?selectTr=0:selectTr=i+1"
                     :class="selectTr===i+1?'focusing' : ''">
                     <td class="text-center pt-4 bg-light"
-                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type==='新品入库'"
-                        :rowspan="calRowspan('新品入库')">@{{ report.type }}
-                    </td>
-                    <td class="text-center pt-4 bg-light"
-                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type==='退货入库'"
-                        :rowspan="calRowspan('退货入库')">@{{ report.type }}
-                    </td>
-                    <td>@{{ report.unit_price }}(元/@{{ report.unit.name }})</td>
+                        v-for="work_name in work_names"
+                        :rowspan="calRowspan(work_name)"
+                        v-if="(i==0 || report.work_name!== reports[i-1].work_name)&&report.work_name===work_name"
+                    >@{{ report.work_name }}</td>
+                    <td>@{{ report.step }}</td>
+                    <td>@{{ report.unit_price }}元/@{{ report.unit.name }}</td>
                     <td>@{{ report.amount }}</td>
                     <td class="text-center pt-4 bg-light"
-                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type==='新品入库'"
-                        :rowspan="calRowspan('新品入库')">{{ $newFee }}</td>
-                    <td class="text-center pt-4 bg-light"
-                        v-if="(i==0 || report.type!== reports[i-1].type)&&report.type==='退货入库'"
-                        :rowspan="calRowspan('退货入库')">{{ $backFee }}</td>
+                        v-for="work_name in work_names"
+                        :rowspan="calRowspan(work_name)"
+                        v-if="(i==0 || report.work_name!== reports[i-1].work_name)&&report.work_name===work_name"
+                    >@{{ findWorkNameFee(report.work_name) }}</td>
                 </tr>
             </table>
         </div>
@@ -113,10 +102,13 @@
             data: {
                 owner: {!! $owner !!},
                 reports: {!! $reports !!},
+                work_name_fee_total: {!! $work_name_fee_total !!},
                 owners: [@foreach($owners as $owner){name: '{{ $owner->id }}', value: '{{ $owner->name}}'},@endforeach],
                 isArchived: {!! $isArchived !!},
                 request: {!! $request !!},
                 selectTr: 0,
+                work_names: [],
+                _reports: null
             },
             created() {
             },
@@ -193,16 +185,18 @@
                     appendDom: 'btn'
                 });
                 _this.form.init();
+
+                this.work_names = Array.from(new Set(this.reports.map(obj => obj.work_name)));
             },
             methods: {
-                isShowColumn(preType, type, targetType, i) {
-                    return (i === 0 || type !== preType) && type === targetType
+                findWorkNameFee(value) {
+                    return this.work_name_fee_total.filter(item => item.work_name === value)[0].fee;
                 },
                 calRowspan(type) {
-                    return this.reports.filter(item => item.type === type).length;
+                    return this.reports.filter(item => item.work_name === type).length;
                 },
                 reportExport(sign) {
-                    let url = '{{url('finance/settlementBills/storeFee/report/export')}}';
+                    let url = '{{url('finance/settlementBills/storeOutFee/report/export')}}';
                     let token = '{{ csrf_token() }}';
                     if (sign) {
                         excelExport(true, checkData, url, this.total, token);
@@ -215,7 +209,9 @@
                     }
                 },
             },
-            filters: {},
+            computed: {},
+            filters: {
+            },
         });
     </script>
 @endsection

+ 3 - 3
routes/web.php

@@ -808,11 +808,11 @@ Route::group(['prefix'=>'finance'],function(){
 
         Route::group(['prefix' => 'storeOutFee'], function () {
             Route::post('detail/confirmBill', 'OwnerStoreOutFeeDetailController@confirmBill');
-//            Route::post('report/confirmBill', 'OwnerStoreFeeReportController@confirmBill');
+            Route::post('report/confirmBill', 'OwnerStoreOutFeeReportController@confirmBill');
             Route::any('detail/export', 'OwnerStoreOutFeeDetailController@export');
-//            Route::any('report/export', 'OwnerStoreFeeReportController@export');
+            Route::any('report/export', 'OwnerStoreOutFeeReportController@export');
             Route::get('detail', 'OwnerStoreOutFeeDetailController@index');
-//            Route::get('report', 'OwnerStoreFeeReportController@index');
+            Route::get('report', 'OwnerStoreOutFeeReportController@index');
         });
     });
 });

+ 81 - 0
tests/Services/OwnerStoreOutFeeReportService/RecordReportTest.php

@@ -0,0 +1,81 @@
+<?php
+
+namespace Tests\Services\OwnerStoreOutFeeReportService;
+
+use App\OwnerBillReport;
+use App\OwnerFeeDetail;
+use App\OwnerPriceOperation;
+use App\OwnerStoreFeeDetail;
+use App\OwnerStoreFeeReport;
+use App\OwnerStoreOutFeeDetail;
+use App\Services\OwnerStoreOutFeeReportService;
+use Tests\TestCase;
+use App\OwnerStoreOutFeeReport;
+use App\Traits\TestMockSubServices;
+
+class RecordReportTest extends TestCase
+{
+    use TestMockSubServices;
+
+    /** @var OwnerStoreOutFeeReportService $service */
+    public $service;
+    private $data;
+    private $amount = 2;
+
+    function setUp(): void
+    {
+        parent::setUp();
+        $this->service = app('OwnerStoreOutFeeReportService');
+    }
+
+    public function testReturned()
+    {
+//        OwnerPriceOperation::query()->truncate();
+//        OwnerFeeDetail::query()->truncate();
+//        OwnerStoreOutFeeDetail::query()->truncate();
+//        OwnerBillReport::query()->truncate();
+//        OwnerStoreOutFeeReport::query()->truncate();
+//        $ownerPriceOperationIds = factory(OwnerPriceOperation::class)->times(10)->create()->pluck('id');
+//        $ownerFeeDetailIds = [];
+//        foreach ($ownerPriceOperationIds as $ownerPriceOperationId) {
+//            $ownerFeeDetailIds[] = factory(OwnerFeeDetail::class)->create(['owner_price_operation_id' => $ownerPriceOperationId]);
+//        }
+//        foreach ($ownerFeeDetailIds as $ownerFeeDetailId) {
+//            $details = factory(OwnerStoreOutFeeDetail::class)->times(2)->create(['owner_fee_detail_id' => $ownerFeeDetailId]);
+//            foreach ($details as $detail) {
+//                factory(OwnerBillReport::class)->create(['owner_id' => $detail->owner_id, 'counting_month' => $detail->created_at->startOfMonth()->toDateString()]);
+//            }
+//        }
+
+//        $this->service->recordReport();
+        $this->assertTrue(true);
+    }
+
+    public function testReturned2()
+    {
+//        OwnerFeeDetail::query()->truncate();
+//        OwnerStoreOutFeeDetail::query()->truncate();
+//        OwnerStoreOutFeeReport::query()->truncate();
+//        $feeDetails = factory(OwnerFeeDetail::class)->times(10)->create(['owner_id' => 8]);
+//        foreach ($feeDetails as $feeDetail) {
+//            factory(OwnerStoreOutFeeDetail::class)->create([
+//                'owner_fee_detail_id' => $feeDetail->id,
+//                'owner_id' => 8,
+//                'work_name' => 'aaa',
+//                'unit_price' => '1000',
+//                'unit_id' => 1,
+//                'amount' => 10,
+//                'remark' => 'vbbbb',
+//                'step' => '100-200',
+//            ]);
+//        }
+//        $this->service->recordReport();
+        $this->assertTrue(true);
+
+    }
+
+    function tearDown(): void
+    {
+        parent::tearDown();
+    }
+}