瀏覽代碼

税率规则变更,触发变更
鉴权字段由name变为alias_name

Zhouzhendong 5 年之前
父節點
當前提交
2c1cb0cb17

+ 16 - 5
app/Console/Commands/CreateOwnerBillReport.php

@@ -64,7 +64,7 @@ class CreateOwnerBillReport extends Command
                     ->calculationAmount($area->ownerStoragePriceModel,$area->accounting_area,$area->owner_id,$area->counting_month);
             }
         }
-        foreach (OwnerPriceSystem::query()->with("timeUnit")->select("owner_id","usage_fee")->whereNull("operation")->orWhere("operation","")->get() as $system){
+        foreach (OwnerPriceSystem::query()->with(["timeUnit","taxRate"])->select("owner_id","usage_fee")->whereNull("operation")->orWhere("operation","")->get() as $system){
             if (!$system->timeUnit)$systemFee[$system->owner_id] = $system->usage_fee;
             else $systemFee[$system->owner_id] = $this->systemFee($system,$year."-".$lastMonth);
         }
@@ -100,15 +100,26 @@ class CreateOwnerBillReport extends Command
      */
     private function systemFee(OwnerPriceSystem $system,$month)
     {
+        $money = null;
         switch ($system->timeUnit->name){
             case "日":
-                return $system->usage_fee*(Carbon::parse($month)->lastOfMonth()->format("d"));
+                $money = $system->usage_fee*(Carbon::parse($month)->lastOfMonth()->format("d"));
+                break;
             case "单":
-                return $system->usage_fee * (app("OrderService")->getOrderQuantity($system->owner_id));
+                $money = $system->usage_fee * (app("OrderService")->getOrderQuantity($system->owner_id));
+                break;
             case "年":
-                return $system->usage_fee/12;
+                $money = $system->usage_fee/12;
+                break;
             default:
-                return $system->usage_fee;
+                $money = $system->usage_fee;
         }
+        if ($system->taxRate)$taxFee = $money * ($system->taxRate->value/100);
+        else{
+            $system->load("owner.taxRate");
+            if ($system->owner && $system->owner->taxRate)$taxFee = $money * ($system->owner->taxRate->value/100);
+            else $taxFee = null;
+        }
+        return $money;
     }
 }

+ 3 - 2
app/Http/Controllers/CustomerController.php

@@ -173,8 +173,8 @@ class CustomerController extends Controller
         /** @var Owner $owner */
         $owner = app('OwnerService')->find(request("id"));
         if (!$owner)$this->error("项目已被删除,无法操作");
-        if ($owner->tax_rate_id && !request("tax_rate_id"))app('OwnerService')->attachTaxRate($owner);
-        if (!$owner->tax_rate_id && request("tax_rate_id"))app('OwnerService')->removeTaxRate($owner);
+        //if ($owner->tax_rate_id && !request("tax_rate_id"))app('OwnerService')->attachTaxRate($owner);
+        //if (!$owner->tax_rate_id && request("tax_rate_id"))app('OwnerService')->removeTaxRate($owner);
         $owner = app('OwnerService')->update($owner,[
             "customer_id"           => request("customer_id"),
             "warehouse_id"          => request("warehouse_id"),
@@ -186,6 +186,7 @@ class CustomerController extends Controller
             "waring_line_on"        => request("waring_line_on"),
             "description"           => request("description"),
             "subjection"            => request("subjection"),
+            "is_tax_exist"          => request("is_tax_exist") ? 'Y' : 'N',
         ]);
         $this->success($owner);
     }

+ 4 - 3
app/Http/Controllers/TestController.php

@@ -175,9 +175,10 @@ class TestController extends Controller
 
     public function test()
     {
-        $service = new StoreService();
-        $store = Store::query()->find(151036);
-        $service->createInstantBill($store);
+        $owner = Owner::query()->with("taxRate")
+            ->whereHas("taxRate")
+            ->find(1);
+        dd($owner);
     }
     public function a(int $c)
     {

+ 3 - 2
app/Owner.php

@@ -33,8 +33,9 @@ class Owner extends Model
         "description",          //描述
         "warehouse_id",         //仓库ID
         "user_workgroup_id",    //仓库小组(工作组)
-        "relevance",             //关联模型的JSON数组
-        'subjection'             //主体公司
+        "relevance",            //关联模型的JSON数组
+        'subjection',           //主体公司
+        'is_tax_exist'          //是否必填税率
     ];
     //relevance说明 0:仓储 1:作业 2:快递 3:物流 4:直发 5:系统 存储示例:["0","1"]存在仓储与作业计费
     protected $casts = [

+ 8 - 0
app/OwnerPriceSystem.php

@@ -18,4 +18,12 @@ class OwnerPriceSystem extends Model
     {   //时间单位
         return $this->belongsTo(Unit::class,"time_unit_id","id");
     }
+    public function taxRate()
+    {   //税率
+        return $this->belongsTo(TaxRate::class);
+    }
+    public function owner()
+    {   //货主
+        return $this->belongsTo(Owner::class);
+    }
 }

+ 1 - 1
app/Providers/AuthServiceProvider.php

@@ -60,7 +60,7 @@ class AuthServiceProvider extends ServiceProvider
             return Authority::with('roles')->get();
         });
         foreach($authorities as $authority) {
-            Gate::define($authority->name, function($user) use ($authority,$cacheService) {
+            Gate::define($authority->alias_name, function($user) use ($authority,$cacheService) {
                 if(Cache::get('isSuperAdmin'.$user['id'])){
                     if($authority['permission']=='允许'){
                         return true;

+ 9 - 1
app/Services/OwnerPriceDirectLogisticService.php

@@ -196,7 +196,15 @@ class OwnerPriceDirectLogisticService
         $initialMoney = $model->details[0]->base_fee;
         $amount -= $model->base_km;
         $money = ($amount*$model->details[0]->additional_fee)+$initialMoney;
-        $taxFee = $model->tax_rate_id && $model->taxRate ? $money*($model->taxRate->value/100) : null;
+        if ($model->tax_rate_id && $model->taxRate){
+            $taxFee = $money*($model->taxRate->value/100);
+        }else{
+            /** @var Owner|\stdClass $owner */
+            $owner = Owner::query()->with("taxRate")
+                ->whereHas("taxRate")->find($owner_id);
+            if ($owner)$taxFee = $money*($owner->taxRate->value/100);
+            else $taxFee = null;
+        }
         return array($money,$taxFee);
     }
 }

+ 10 - 1
app/Services/OwnerPriceExpressService.php

@@ -295,7 +295,16 @@ sql
         if ($weight <= $model->initial_weight)return $initPrice;
         $weight -= $model->initial_weight;
         $money = (ceil($weight/$model->additional_weight)*$additionalPrice)+$initPrice;
-        $taxFee = $model->tax_rate_id && $model->taxRate ? $money*($model->taxRate->value/100) : null;
+        if ($model->tax_rate_id && $model->taxRate){
+            $taxFee = $money*($model->taxRate->value/100);
+        }else{
+            /** @var Owner|\stdClass $owner */
+            $owner = Owner::query()->with("taxRate")
+                ->whereHas("taxRate")->find($owner_id);
+            if ($owner)$taxFee = $money*($owner->taxRate->value/100);
+            else $taxFee = null;
+        }
+
         return array($money,$taxFee);
     }
 }

+ 10 - 1
app/Services/OwnerPriceLogisticService.php

@@ -2,6 +2,7 @@
 
 namespace App\Services;
 
+use App\Owner;
 use App\OwnerPriceLogistic;
 use App\OwnerPriceLogisticDetail;
 use App\Services\common\QueryService;
@@ -231,7 +232,15 @@ class OwnerPriceLogisticService
             }
             if ($money)break;
         }
-        $taxFee = $model->tax_rate_id && $model->taxRate ? $money*($model->taxRate->value/100) : null;
+        if ($model->tax_rate_id && $model->taxRate){
+            $taxFee = $money*($model->taxRate->value/100);
+        }else{
+            /** @var Owner|\stdClass $owner */
+            $owner = Owner::query()->with("taxRate")
+                ->whereHas("taxRate")->find($owner_id);
+            if ($owner)$taxFee = $money*($owner->taxRate->value/100);
+            else $taxFee = null;
+        }
         return array($money,$taxFee);
     }
 

+ 7 - 0
app/Services/OwnerPriceOperationService.php

@@ -4,6 +4,7 @@ namespace App\Services;
 
 use App\Feature;
 use App\Jobs\HandlePastBill;
+use App\Owner;
 use App\OwnerFeeDetail;
 use App\OwnerPriceOperation;
 use App\OwnerPriceOperationItem;
@@ -353,6 +354,12 @@ class OwnerPriceOperationService
                 $money = $rule->max_fee&&$money>$rule->max_fee ? $rule->max_fee : $money;//封顶费
                 if ($money<=0)$money=null;//计算失误
                 if ($rule->tax_rate_id && $rule->taxRate)$taxFee = $money*($rule->taxRate->value/100);
+                else{
+                    /** @var Owner|\stdClass $owner */
+                    $owner = Owner::query()->with("taxRate")
+                        ->whereHas("taxRate")->find($ownerId);
+                    if ($owner)$taxFee = $money*($owner->taxRate->value/100);
+                }
                 break;
             }
         }

+ 32 - 0
database/migrations/2021_05_01_153301_change_owners_table_add_is_tax_exist_column.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeOwnersTableAddIsTaxExistColumn extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table("owners",function (Blueprint $table){
+            $table->char("is_tax_exist")->default("N")->comment("是否必填税率");
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table("owners",function (Blueprint $table){
+            $table->dropColumn("is_tax_exist");
+        });
+    }
+}

+ 12 - 20
resources/views/customer/project/create.blade.php

@@ -103,6 +103,7 @@
                     description : "{{$owner->description ?? ''}}",
                     waring_line_on : "{{$owner->waring_line_on ?? ''}}",
                     subjection : "{{$owner->subjection ?? ''}}",
+                    is_tax_exist : "{{$owner->is_tax_exist}}"=='Y',
                 },
                 ownerTemp : {},
                 customers : [
@@ -489,7 +490,7 @@
                     if (!this.owner.owner_group_id) error["owner_group_id"] = ["必须选择项目小组"];
                     if (!this.owner.warehouse_id) error["warehouse_id"] = ["必须选择仓库"];
                     if (!this.owner.user_workgroup_id) error["user_workgroup_id"] = ["必须选择仓库小组"];
-                    if (!this.owner.tax_rate_id) error["tax_rate_id"] = ["必须选择税率"];
+                    //if (!this.owner.tax_rate_id) error["tax_rate_id"] = ["必须选择税率"];
                     if (JSON.stringify(error) !== "{}"){
                         this.errors = error;
                         return;
@@ -505,6 +506,7 @@
                     params.waring_line_on !== old.waring_line_on ||
                     params.phone_number !== old.phone_number ||
                     params.subjection !== old.subjection ||
+                    params.is_tax_exist !== old.is_tax_exist ||
                     params.description !== old.description){
                         let result = undefined;
                         window.tempTip.postBasicRequest(url,params,res=>{
@@ -525,6 +527,7 @@
                             this.ownerTemp.customer_name = params.customer_name;
                             this.ownerTemp.owner_group_name = params.owner_group_name;
                             this.ownerTemp.subjection = params.subjection;
+                            this.ownerTemp.is_tax_exist = params.is_tax_exist;
                             result = true;
                         });
                         while (result){
@@ -741,12 +744,8 @@
                         this.errors = {time_unit_id:["未选择计时单位"]};
                         return;
                     }
-                    if(this.owner.tax_rate_id && this.model.system.tax_rate_id){
-                        this.errors = {tax_rate_id:["总项税率已存在"]};
-                        return;
-                    }
-                    if(!this.owner.tax_rate_id && !this.model.system.tax_rate_id){
-                        this.errors = {tax_rate_id:["总项税率不存在,子项税率必填"]};
+                    if(this.owner.is_tax_exist && !this.model.system.tax_rate_id){
+                        this.errors = {tax_rate_id:["税率不可为空"]};
                         return;
                     }
                     let url = "{{url('maintenance/priceModel/apiStoreSystem')}}";
@@ -774,8 +773,7 @@
                     if (!this.model.storage.discount_type)error["discount_type"] = ["未选择减免类型"];
                     if (!this.model.storage.unit_id)error["unit_id"] = ["未选择单位"];
                     if (!this.model.storage.time_unit_id)error["time_unit_id"] = ["未选择计时单位"];
-                    if(this.owner.tax_rate_id && this.model.storage.tax_rate_id)error = {tax_rate_id:["总项税率已存在"]};
-                    if(!this.owner.tax_rate_id && !this.model.storage.tax_rate_id)error = {tax_rate_id:["总项税率不存在,子项税率必填"]};
+                    if(this.owner.is_tax_exist && !this.model.storage.tax_rate_id)error = {tax_rate_id:["税率不可为空"]};
                     if (this.model.storage.isInterval){
                         if (this.model.storage.amount_interval.length<1 || this.model.storage.price.length<1){
                             error["amount_interval.0"] = ["未设定数量区间"];
@@ -850,11 +848,8 @@
                         this.$set(this.errors,"name",["名称不得为空"]);
                         return;
                     }
-                    if(this.owner.tax_rate_id && this.model.operation.tax_rate_id){
-                        this.error = {tax_rate_id:["总项税率已存在"]};return;
-                    }
-                    if(!this.owner.tax_rate_id && !this.model.operation.tax_rate_id){
-                        this.error = {tax_rate_id:["总项税率不存在,子项税率必填"]};return;
+                    if(this.owner.is_tax_exist && !this.model.operation.tax_rate_id){
+                        this.error = {tax_rate_id:["税率不可为空"]};return;
                     }
                     if (this.model.operation.isDiscount){
                         let sign = false;
@@ -978,8 +973,7 @@
                     if (!this.model.express.name)error.name = ["名称不得为空"];
                     if (!this.model.express.initial_weight)error.initial_weight = ["首重不得为空"];
                     if (!this.model.express.additional_weight)error.additional_weight = ["续重不得为空"];
-                    if(this.owner.tax_rate_id && this.model.express.tax_rate_id)error = {tax_rate_id:["总项税率已存在"]};
-                    if(!this.owner.tax_rate_id && !this.model.express.tax_rate_id)error = {tax_rate_id:["总项税率不存在,子项税率必填"]};
+                    if(this.owner.is_tax_exist && !this.model.express.tax_rate_id)error = {tax_rate_id:["税率不可为空,子项税率必填"]};
                     if (this.model.express.items.length>0){
                         this.model.express.items.forEach((item,index)=>{
                             if (!item.province_id)error["item."+index+".province_id"] = ["不存在"];
@@ -1071,8 +1065,7 @@
                     if (!this.model.logistic.unit_range) error.unit_range = ["区间值不得为空"];
                     if (!this.model.logistic.other_unit_id) error.other_unit_id = ["单位二不得为空"];
                     if (!this.model.logistic.other_unit_range) error.other_unit_range = ["区间值不得为空"];
-                    if(this.owner.tax_rate_id && this.model.logistic.tax_rate_id)error = {tax_rate_id:["总项税率已存在"]};
-                    if(!this.owner.tax_rate_id && !this.model.logistic.tax_rate_id)error = {tax_rate_id:["总项税率不存在,子项税率必填"]};
+                    if(this.owner.is_tax_exist && !this.model.logistic.tax_rate_id)error = {tax_rate_id:["税率不可为空"]};
                     if (JSON.stringify(error) !== "{}"){
                         this.errors = error;
                         return;
@@ -1113,8 +1106,7 @@
                     let error = {};
                     if (!this.model.directLogistic.name) error.name = ["名称不得为空"];
                     if (!this.model.directLogistic.base_km) error.base_km = ["起步公里数不得为空"];
-                    if(this.owner.tax_rate_id && this.model.directLogistic.tax_rate_id)error = {tax_rate_id:["总项税率已存在"]};
-                    if(!this.owner.tax_rate_id && !this.model.directLogistic.tax_rate_id)error = {tax_rate_id:["总项税率不存在,子项税率必填"]};
+                    if(this.owner.is_tax_exist && !this.model.directLogistic.tax_rate_id)error = {tax_rate_id:["税率不可为空"]};
                     if (JSON.stringify(error) !== "{}"){
                         this.errors = error;
                         return;

+ 4 - 0
resources/views/customer/project/part/_two.blade.php

@@ -53,6 +53,10 @@
         <strong>@{{ errors.tax_rate_id[0] }}</strong>
     </span>
 </div>
+<div class="row mt-3">
+    <label for="is_tax_exist" class="col-2">子模型必填税率</label>
+    <input type="checkbox" class="switch" id="is_tax_exist" v-model="owner.is_tax_exist">
+</div>
 <div class="row mt-3">
     <label for="waring_line_on" class="col-2">月单量预警</label>
     <input type="number" v-model="owner.waring_line_on" id="waring_line_on" class="form-control form-control-sm col-3 mb-0" :class="errors.waring_line_on ? 'is-invalid' : ''">