Browse Source

采购管理-发起采购

haozi 5 years ago
parent
commit
133ccdc3a6

+ 79 - 0
app/Console/Commands/CreateProcurementTotalBill.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace App\Console\Commands;
+
+use App\ProcurementCheckSheet;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class CreateProcurementTotalBill extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'createProcurementTotalBill';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '采购生成总账单';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $date=$this->getDate();
+        $procurementCheckSheets=ProcurementCheckSheet::query()
+            ->selectRaw('procurements.supplier_id supplier_id,procurement_check_sheets.created_at created_at,procurement_check_sheets.status status,SUM(procurement_check_sheets.account_payable) account_payable')
+            ->leftJoin('procurement_deliveries','procurement_check_sheets.procurement_delivery_id','procurement_deliveries.id')
+            ->leftJoin('procurements','procurement_deliveries.procurement_id','procurements.id')
+            ->where('procurement_check_sheets.created_at','like',$date."%")
+            ->groupBy('supplier_id')
+            ->get();
+        $totalBill=[];
+        foreach ($procurementCheckSheets as $procurementCheckSheet){
+            $totalBill[]=[
+                'counting_month'=>$date.'-01',
+                'supplier_id'=>$procurementCheckSheet->supplier_id,
+                'total_payable'=>$procurementCheckSheet->account_payable,
+                'status'=>$procurementCheckSheet->status,
+                'created_at'=>date('Y-m-01 00:00:00'),
+                'updated_at'=>date('Y-m-01 00:00:00'),
+            ];
+        }
+        if (count($totalBill)>0){
+            DB::table("procurement_total_bills")->insert($totalBill);
+            app('LogService')->log(__METHOD__,"采购管理-生成月账单报表",json_encode($totalBill));
+        }
+    }
+
+    private function getDate(){//获取当前日期的上月 月份
+        $month = (int)date('m');
+        $year = (int)date('Y');
+        if ($month == 1){
+            $year--;
+            $lastMonth = '12';
+        }else{
+            $lastMonth = ($month-1) < 10 ? "0".($month-1) : ($month-1);
+        }
+        $date=$year."-".$lastMonth;
+        return $date;
+    }
+}

+ 4 - 1
app/Filters/ProcurementFilters.php

@@ -121,7 +121,7 @@ class ProcurementFilters
     }
     public function supplier_id($supplier_id)
     {
-        $this->searchWay($this->queryBuilder,$supplier_id,'id');
+        $this->searchWay($this->getSupplierQuery(),$supplier_id,'id');
     }
 
     public function material_id($material_id)
@@ -151,5 +151,8 @@ class ProcurementFilters
         if($this->ownerMaterialQuery)
             $this->queryBuilder->whereIn('owner_material_id',$this->ownerMaterialQuery);
 
+        if($this->supplierQuery)
+            $this->queryBuilder->whereIn('supplier_id',$this->supplierQuery);
+
     }
 }

+ 1 - 1
app/Http/Controllers/LaborReportController.php

@@ -114,7 +114,7 @@ class LaborReportController extends Controller
 
     //门卫打卡审核
     public function guardClockAudit(Request $request){
-        if(!Gate::allows('人事管理-门卫审核')){ return ["success"=>false,"data"=>"您无此权限操作!!!"];  }
+        if(!Gate::allows('人事管理-门卫审核')){ return ["success"=>false,"data"=>"您无此权限操作!"];  }
         $id=$request->input('id');
         $userDutyCheckId=$request->input('user_duty_check_id');
         $laborReportStatus=new LaborReportStatus([

+ 69 - 6
app/Http/Controllers/ProcurementController.php

@@ -3,9 +3,11 @@
 namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
+use App\Configuration;
 use App\Filters\ProcurementCheckSheetFilters;
 use App\Filters\ProcurementFilters;
 use App\Http\Requests\Procurement\EnquiryRequest;
+use App\Http\Requests\Procurement\ProcurementAmountRequest;
 use App\Http\Requests\Procurement\ProcurementRequest;
 use App\Http\Requests\Procurement\ProofRequest;
 use App\Material;
@@ -15,11 +17,13 @@ use App\ProcurementDeliverie;
 use App\ProcurementTotalBill;
 use App\Services\common\ExportService;
 use App\Services\OwnerMaterialService;
+use App\Services\ProcurementService;
 use App\Services\ProcurementTotalBillService;
 use App\Supplier;
 use Carbon\Traits\Date;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Gate;
 
 class ProcurementController extends Controller
 {
@@ -44,7 +48,7 @@ class ProcurementController extends Controller
 
     public function index(Request $request,ProcurementFilters $filters)
     {
-        $this->gate('采购管理-采购-查询');
+        if(!Gate::allows('采购管理-采购-查询')){ return ["success"=>false,"data"=>"您无此权限操作!"];  }
         $paginateParams=$request->input();
         $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
         $procurements = Procurement::query()
@@ -65,7 +69,7 @@ class ProcurementController extends Controller
 
     public function create()
     {
-        $this->gate('采购管理-采购-新建');
+        if(!Gate::allows('采购管理-采购-新建')){ return ["success"=>false,"data"=>"您无此权限操作!"];  }
         /** @var OwnerMaterialService $ownerMaterialService*/
         $ownerMaterialService=app(OwnerMaterialService::class);
         $owners=$ownerMaterialService->getOwnerPermittingWithMaterial();
@@ -93,6 +97,7 @@ class ProcurementController extends Controller
             return ['success' => false,'message' => $e->getMessage()];
         }
     }
+    //新增询价
     public function createEnquiry(EnquiryRequest $request)
     {
         $this->gate('采购管理-采购-新建');
@@ -106,6 +111,8 @@ class ProcurementController extends Controller
                 'unit_price'=>0,
                 'initiator'=>Auth::user()['id'],
                 'type'=>1,
+                'status'=>9,
+                //'is_enquiry'=>'是',
             ]);
             $procurement->save();
             $number_id=$procurement['id'];
@@ -119,6 +126,7 @@ class ProcurementController extends Controller
             return ['success' => false,'message' => $e->getMessage()];
         }
     }
+    //新增打样
     public function createProof(ProofRequest $request)
     {
         $this->gate('采购管理-采购-新建');
@@ -145,6 +153,59 @@ class ProcurementController extends Controller
             return ['success' => false,'message' => $e->getMessage()];
         }
     }
+    public function cancel($id){
+        $this->gate('采购管理-采购-编辑');
+        try {
+            $procurement=Procurement::query()->find($id);
+            $procurement->update(['status'=>3]);
+            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            if ($procurement) return ['success' => true,'data' => $procurement];
+            else return ['success' => false, 'message' => '取消失败'];
+        } catch (\Exception $e) {
+            return ['success' => false,'message' => $e->getMessage()];
+        }
+    }
+    //询价单提交采购申请
+    public function submitProcurement(ProcurementAmountRequest $request){
+        $this->gate('采购管理-采购-编辑');
+        $request->validated();
+        $param=$request->all();
+        try {
+            $procurement=Procurement::query()->find($param['id']);
+            $unit_price=$param['unit_price'];
+            if (!$unit_price){
+                $priceCoefficient=Configuration::query()->where('name','priceCoefficient')->value('value');
+                $unit_price=$priceCoefficient*$param['offer'];
+            }
+            $procurement->update([
+                'type'=>0,
+                'status'=>0,
+                'quantity'=>$param['quantity'],
+                'amount'=>$param['amount'],
+                'unit_price'=>$unit_price,
+                'cost_price'=>$param['offer'],
+                'supplier_id'=>$param['supplier_id'],
+            ]);
+            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            if ($procurement) return ['success' => true,'data' => $procurement];
+            else return ['success' => false, 'message' => '取消失败'];
+        } catch (\Exception $e) {
+            return ['success' => false,'message' => $e->getMessage()];
+        }
+    }
+    public function initiateProcurement(Request $request){
+        $this->gate('采购管理-采购-编辑');
+        $id=$request->input('id');
+        /** @var ProcurementService $procurementService*/
+        $procurementService=app(ProcurementService::class);
+        try {
+            $procurementQuotation=$procurementService->screenLowestQuotation($id);
+            if ($procurementQuotation) return ['success' => true,'data' => $procurementQuotation];
+            else return ['success' => false, 'message' => '暂无供应商报价!'];
+        } catch (\Exception $e) {
+            return ['success' => false,'message' => $e->getMessage()];
+        }
+    }
 
 
     public function show(Procurement $procurement)
@@ -172,7 +233,7 @@ class ProcurementController extends Controller
 
     public function checkBill(Request $request,ProcurementCheckSheetFilters $filters)
     {
-        $this->gate('采购管理-财务-对账单');
+        if(!Gate::allows('采购管理-财务-对账单')){ return ["success"=>false,"data"=>"您无此权限操作!"];  }
         $paginateParams=$request->input();
         $procurementCheckSheets=ProcurementCheckSheet::query()
             ->filter($filters)
@@ -197,7 +258,7 @@ class ProcurementController extends Controller
 
     public function procurementBill(Request $request,ProcurementFilters $filters)
     {
-        $this->gate('采购管理-财务-采购账单');
+        if(!Gate::allows('采购管理-财务-采购账单')){ return ["success"=>false,"data"=>"您无此权限操作!"];  }
         $paginateParams=$request->input();
         $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
         $owners=app("OwnerService")->getIntersectPermitting();
@@ -207,13 +268,15 @@ class ProcurementController extends Controller
             ->filter($filters)
             ->with(['initiator','supplier','ownerMaterial.material','ownerMaterial.owner'=>function($query)use($owner_ids){
                 $query->with('customer')->whereIn('id',$owner_ids);
-            }])->paginate($param['paginate'] ?? 50);
+            }])
+            ->where('type',0) //只取采购单
+            ->paginate($param['paginate'] ?? 50);
         return view('procurement/finance/procurementBill',compact('suppliers','materials','owners','paginateParams','procurements'));
     }
 
     public function monthlyBillReport(Request $request)
     {
-        $this->gate('采购管理-财务-月账单报表');
+        if(!Gate::allows('采购管理-财务-月账单报表')){ return ["success"=>false,"data"=>"您无此权限操作!"];  }
         $paginateParams=$request->input();
         /** @var ProcurementTotalBillService $procurementTotalBillService*/
         $procurementTotalBillService=app(ProcurementTotalBillService::class);

+ 12 - 0
app/Http/Controllers/TestController.php

@@ -55,6 +55,8 @@ use App\Package;
 use App\Process;
 use App\ProcessDaily;
 use App\ProcessStatistic;
+use App\ProcurementCheckSheet;
+use App\ProcurementQuotation;
 use App\Province;
 use App\Region;
 use App\RejectedBill;
@@ -1527,4 +1529,14 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
             app('LogService')->log(__CLASS__, __METHOD__,'Error clearCancelledOrder'.json_encode($order_nos).json_encode($wave_nos));
         }
     }
+
+    public function testProcurement()
+    {
+        $procurementQuotation=ProcurementQuotation::query()
+            ->with('supplier')
+            ->select('supplier_id','offer')
+            ->orderBy('offer','asc')
+            ->where('procurement_id',7)->first();
+        dd($procurementQuotation);
+    }
 }

+ 40 - 0
app/Http/Requests/Procurement/ProcurementAmountRequest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Http\Requests\Procurement;
+
+use App\Traits\RequestApiFormValidation;
+use Illuminate\Foundation\Http\FormRequest;
+
+class ProcurementAmountRequest extends FormRequest
+{
+    use RequestApiFormValidation;
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'quantity'=>'required',
+            'amount'=>'required',
+        ];
+    }
+    public function messages()
+    {
+        return [
+            'quantity.required' => '采购数量不可为空',
+            'amount.required' => '销售数量不可为空',
+        ];
+    }
+}

+ 4 - 0
app/Http/Requests/Procurement/ProcurementRequest.php

@@ -28,6 +28,8 @@ class ProcurementRequest extends FormRequest
         return [
             'owner_id'=>'required',
             'owner_material_id'=>'required',
+            'quantity'=>'required',
+            'amount'=>'required',
         ];
     }
     public function messages()
@@ -35,6 +37,8 @@ class ProcurementRequest extends FormRequest
         return [
             'owner_id.required' => '项目必选',
             'owner_material_id.required' => '项目耗材编码必选',
+            'quantity.required' => '采购数量不可为空',
+            'amount.required' => '销售数量不可为空',
         ];
     }
 }

+ 1 - 0
app/Procurement.php

@@ -28,6 +28,7 @@ class Procurement extends Model
         6 => "下单失败",
         7 => "待出账",
         8 => "待接单(已过期)",
+        9 => "待报价",
     ];
 
     protected $fillable=[

+ 5 - 1
app/ProcurementQuotation.php

@@ -13,6 +13,10 @@ class ProcurementQuotation extends Model
     use ModelTimeFormat;
 
     protected $fillable=[
-        'procurement_id','offer', 'operator', 'quoted_at','status','created_at'
+        'procurement_id','offer', 'operator', 'quoted_at','status','created_at','supplier_id'
     ];
+
+    public  function supplier(){
+        return $this->hasOne('App\Supplier','id','supplier_id');
+    }
 }

+ 1 - 1
app/ProcurementTotalBill.php

@@ -19,7 +19,7 @@ class ProcurementTotalBill extends Model
     ];
 
     protected $fillable=[
-        'counting_month','supplier_id','status'
+        'counting_month','supplier_id','status','total_payable'
     ];
     public function supplier(){
         return $this->belongsTo('App\Supplier','supplier_id','id');

+ 1 - 1
app/Services/OwnerMaterialService.php

@@ -15,6 +15,6 @@ class OwnerMaterialService
     public function getOwnerPermittingWithMaterial()
     {
         $ownerIds=app('UserService')->getPermittingOwnerIds(Auth::user());
-        return Owner::query()->with('ownerMaterials.material')->select('id','name')->whereIn('id', $ownerIds)->get();
+        return Owner::query()->with(['ownerMaterials.material','customer'])->select(['id','name','customer_id'])->whereIn('id', $ownerIds)->get();
     }
 }

+ 6 - 20
app/Services/ProcurementService.php

@@ -4,6 +4,7 @@ namespace App\Services;
 
 use App\Owner;
 use App\Procurement;
+use App\ProcurementQuotation;
 use App\Services\common\QueryService;
 use Illuminate\Support\Facades\Auth;
 use App\Traits\ServiceAppAop;
@@ -13,25 +14,10 @@ class ProcurementService
 {
     use ServiceAppAop;
 
-    private function conditionQuery(array $param){
-        $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
-        $procurements = Procurement::with(['initiator','ownerMaterial.material','ownerMaterial.owner'=>function($query)use($owner_ids){
-            $query->with('customer')->whereIn('id',$owner_ids);
-        }]);
-        $columnQueryRules=[
-            'owner_id' => ['multi' => ','],
-            'material_id' => ['multi' => ','],
-            'supplier_id' => ['multi' => ','],
-            'company_name' => ['like' => ','],
-            'created_at_start' => ['alias' => 'created_at' , 'startDate' => ':00'],
-            'created_at_end' => ['alias' => 'created_at' , 'endDate' => ':59'],
-        ];
-        $procurements = app(QueryService::class)->query($param,$procurements,$columnQueryRules,"procurements");
-        return $procurements;
-    }
-
-    public function paginate(array $param){
-        $procurements = $this->conditionQuery($param);
-        return $procurements->paginate($param['paginate'] ?? 50);
+    public function screenLowestQuotation($procurement_id){
+        if (!$procurement_id) return null;
+        $procurementQuotation=ProcurementQuotation::query()->with('supplier')
+            ->select('supplier_id','offer')->orderBy('offer','asc')->where('procurement_id',$procurement_id)->first();
+        return $procurementQuotation;
     }
 }

+ 1 - 1
resources/views/procurement/finance/_fillInvoiceNumber.blade.php

@@ -1,5 +1,5 @@
 <div class="modal " id="fill-invoice-number" tabindex="-1" >
-    <div class="modal-dialog modal-lg">
+    <div class="modal-dialog modal-lg modal-dialog-centered">
         <div class="modal-content">
             <div class="modal-header">
                 <h5 class="modal-title text-center">填写发票号</h5>

+ 1 - 1
resources/views/procurement/finance/checkBill.blade.php

@@ -87,7 +87,7 @@
                         material_name:'{{$procurementCheckSheet->procurementDelivery->procurement->ownerMaterial->material->name}}',
                         material_code:'{{$procurementCheckSheet->procurementDelivery->procurement->ownerMaterial->material->code}}',@endif
 
-                    }
+                    },
                     @endforeach
                 ],
                 suppliers:[

+ 2 - 2
resources/views/procurement/finance/monthlyBillReport.blade.php

@@ -31,7 +31,7 @@
                 </td>
                 <td class="text-primary">@{{ procurementTotalBill.id }}</td>
                 <td class="text-muted">@{{ procurementTotalBill.counting_month }}</td>
-                <td class="text-muted">@{{ procurementTotalBill.created_at }}</td>
+                <td class="text-muted">@{{ procurementTotalBill.created_at.substr(0,10) }}</td>
                 <td class="text-muted">@{{ procurementTotalBill.supplier_name }}</td>
                 <td>@{{ procurementTotalBill.total_payable }}</td>
                 <td><span>@{{ procurement_total_bill_status[procurementTotalBill.status] }}</span></td>
@@ -59,7 +59,7 @@
                         created_at:'{{$procurementTotalBill->created_at}}',status:'{{$procurementTotalBill->status}}',total_payable:'{{$procurementTotalBill->total_payable}}',
                             @if($procurementTotalBill->supplier)
                             supplier_id:'{{$procurementTotalBill->supplier->id}}',supplier_name:'{{$procurementTotalBill->supplier->name}}',@endif
-                    }
+                    },
                     @endforeach
                 ],
                 suppliers:[

+ 7 - 7
resources/views/procurement/finance/procurementBill.blade.php

@@ -41,13 +41,13 @@
                 <td class="text-muted">@{{ procurement.size }}</td>
                 <td class="text-muted">@{{ procurement.special }}</td>
                 <td class="text-muted">@{{ procurement.specification }}</td>
-                <td>@{{ procurement.quantity }}</td>
-                <td>@{{ procurement.amount }}</td>
-                <td></td>
-                <td>@{{ procurement.cost_price }}</td>
-                <td>@{{ procurement.unit_price }}</td>
-                <td></td>
+                <td>@{{ procurement.quantity }}</td>{{--采购数量--}}
+                <td>@{{ procurement.amount }}</td> {{--销售数量--}}
                 <td></td>
+                <td>@{{ procurement.cost_price }}</td> {{--采购单价--}}
+                <td>@{{ procurement.unit_price }}</td>  {{--销售单价--}}
+                <td>@{{ procurement.amount*procurement.cost_price }}</td> {{--应收--}}
+                <td>@{{ procurement.quantity*procurement.unit_price }}</td> {{--应付--}}
                 <td><span>@{{ procurement_status[procurement.status] }}</span></td>
                 <td>
                     <span class="btn btn-sm btn-outline-danger">锁定</span>
@@ -122,7 +122,7 @@
                             placeholder: ['耗材', '定位或多选耗材'], data: this.materials
                         },
                         {
-                            name: 'supplier_id', type: 'select_multiple_select', tip: ['输入关键词快速定位下拉列表,回车确定', '选择要显示的耗材'],
+                            name: 'supplier_id', type: 'select_multiple_select', tip: ['输入关键词快速定位下拉列表,回车确定', '选择要显示的供应商'],
                             placeholder: ['供应商', '定位或多选供应商'], data: this.suppliers
                         },
                         {name: 'company_name', type: 'input', tip: '采购公司:可在两侧增加百分号(%)进行模糊搜索', placeholder: '采购公司'},

+ 7 - 1
resources/views/procurement/procurement/_addEnquiry.blade.php

@@ -21,10 +21,16 @@
                             </span>
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="customer_name" class="col-2 col-form-label text-right">客户名称</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control " name="customer_name" autocomplete="off" value="{{ old('customer_name') }}" v-model="customer_name" readonly>
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="owner_material_id" class="col-2 col-form-label text-right text-primary">项目耗材编号{{old('owner_material_id')}} *</label>
                         <div class="col-8">
-                            <select id="owner_material_id" name="owner_material_id" :class="errors.owner_material_id ? 'is-invalid' : ''" class="form-control col-4" v-model="owner_material_id" @change="ownerMaterial" required>
+                            <select id="owner_material_id" name="owner_material_id" :class="errors.owner_material_id ? 'is-invalid' : ''" class="form-control" v-model="owner_material_id" @change="ownerMaterial" required>
                                 <option v-for="ownerMaterial in ownerMaterials" :value="ownerMaterial.id">@{{ownerMaterial.material_code}}</option>
                             </select>
                             <span class="invalid-feedback" role="alert" v-if="errors.owner_material_id">

+ 19 - 4
resources/views/procurement/procurement/_addProcurement.blade.php

@@ -21,10 +21,16 @@
                             </span>
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="customer_name" class="col-2 col-form-label text-right">客户名称</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control " name="customer_name" autocomplete="off" value="{{ old('customer_name') }}" v-model="customer_name" readonly>
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="owner_material_id" class="col-2 col-form-label text-right text-primary">项目耗材编号{{old('owner_material_id')}} *</label>
                         <div class="col-8">
-                            <select id="owner_material_id" name="owner_material_id" class="form-control col-4" :class="errors.owner_material_id ? 'is-invalid' : ''" v-model="owner_material_id" @change="ownerMaterial" required>
+                            <select id="owner_material_id" name="owner_material_id" class="form-control" :class="errors.owner_material_id ? 'is-invalid' : ''" v-model="owner_material_id" @change="ownerMaterial" required>
                                 <option v-for="ownerMaterial in ownerMaterials" :value="ownerMaterial.id">@{{ownerMaterial.material_code}}</option>
                             </select>
                             <span class="invalid-feedback" role="alert" v-if="errors.owner_material_id">
@@ -59,19 +65,28 @@
                     <div class="form-group row">
                         <label for="quantity" class="col-2 col-form-label text-right">采购数量</label>
                         <div class="col-8">
-                            <input type="text" class="form-control" v-model="quantity"  name="quantity" autocomplete="off" value="{{ old('quantity') }}" required>
+                            <input type="text" class="form-control" v-model="quantity" :class="errors.quantity ? 'is-invalid' : ''"  name="quantity" autocomplete="off" value="{{ old('quantity') }}" required>
+                            <span class="invalid-feedback" role="alert" v-if="errors.quantity">
+                                <strong>@{{ errors.quantity[0] }}</strong>
+                            </span>
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="amount" class="col-2 col-form-label text-right">销售数量</label>
                         <div class="col-8">
-                            <input type="text" class="form-control" name="amount" autocomplete="off" value="{{ old('amount') }}" @input="countTotalPrice" v-model="amount" required>
+                            <input type="text" class="form-control" name="amount" :class="errors.amount ? 'is-invalid' : ''" autocomplete="off" value="{{ old('amount') }}" @input="countTotalPrice" v-model="amount" required>
+                            <span class="invalid-feedback" role="alert" v-if="errors.amount">
+                                <strong>@{{ errors.amount[0] }}</strong>
+                            </span>
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="unit_price" class="col-2 col-form-label text-right">销售单价</label>
                         <div class="col-8">
-                            <input type="text" class="form-control" name="unit_price" autocomplete="off" value="{{ old('unit_price') }}" @input="countTotalPrice" v-model="unit_price" required>
+                            <input type="text" class="form-control" name="unit_price" :class="errors.unit_price ? 'is-invalid' : ''" autocomplete="off" value="{{ old('unit_price') }}" @input="countTotalPrice" v-model="unit_price" required>
+                            <span class="invalid-feedback" role="alert" v-if="errors.unit_price">
+                                <strong>@{{ errors.unit_price[0] }}</strong>
+                            </span>
                         </div>
                     </div>
                     <div class="form-group row">

+ 7 - 1
resources/views/procurement/procurement/_addProof.blade.php

@@ -21,10 +21,16 @@
                             </span>
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="customer_name" class="col-2 col-form-label text-right">客户名称</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control " name="customer_name" autocomplete="off" value="{{ old('customer_name') }}" v-model="customer_name" readonly>
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="owner_material_id" class="col-2 col-form-label text-right text-primary">项目耗材编号{{old('owner_material_id')}} *</label>
                         <div class="col-8">
-                            <select id="owner_material_id" name="owner_material_id" :class="errors.owner_material_id ? 'is-invalid' : ''" class="form-control col-4" v-model="owner_material_id" @change="ownerMaterial" required>
+                            <select id="owner_material_id" name="owner_material_id" :class="errors.owner_material_id ? 'is-invalid' : ''" class="form-control" v-model="owner_material_id" @change="ownerMaterial" required>
                                 <option v-for="ownerMaterial in ownerMaterials" :value="ownerMaterial.id">@{{ownerMaterial.material_code}}</option>
                             </select>
                             <span class="invalid-feedback" role="alert" v-if="errors.owner_material_id">

+ 54 - 0
resources/views/procurement/procurement/_addQuantity.blade.php

@@ -0,0 +1,54 @@
+<div class="modal " id="add-quantity" tabindex="-1" >
+    <div class="modal-dialog modal-lg modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title text-center">添加采购数量和销售数量</h5>
+                <button type="button" class="close" data-dismiss="modal">
+                    <span>&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <div class="form-group row">
+                    <label for="supplier" class="col-2 col-form-label text-right">供应商</label>
+                    <div class="col-8">
+                        <input type="text" class="form-control " name="quantity" autocomplete="off" v-model="supplier" readonly>
+                    </div>
+                </div>
+                <div class="form-group row">
+                    <label for="offer" class="col-2 col-form-label text-right">采购单价(最低报价)</label>
+                    <div class="col-8">
+                        <input type="text" class="form-control " name="offer" autocomplete="off" v-model="offer" readonly>
+                    </div>
+                </div>
+                    <div class="form-group row">
+                        <label for="quantity" class="col-2 col-form-label text-right">采购数量</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control " :class="errors.quantity ? 'is-invalid' : ''" name="quantity" autocomplete="off" v-model="quantity" required>
+                            <span class="invalid-feedback" role="alert" v-if="errors.quantity">
+                                <strong>@{{ errors.quantity[0] }}</strong>
+                            </span>
+                        </div>
+                    </div>
+                     <div class="form-group row">
+                        <label for="amount" class="col-2 col-form-label text-right">销售数量</label>
+                            <div class="col-8">
+                                <input type="text" class="form-control " :class="errors.amount ? 'is-invalid' : ''" name="amount" autocomplete="off" v-model="amount" required>
+                                <span class="invalid-feedback" role="alert" v-if="errors.amount">
+                                <strong>@{{ errors.amount[0] }}</strong>
+                            </span>
+                            </div>
+                    </div>
+                    <div class="form-group row">
+                        <label for="unit_price" class="col-2 col-form-label text-right">销售单价</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control " name="unit_price" autocomplete="off" v-model="unit_price">
+                        </div>
+                    </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary"  data-dismiss="modal" >关闭</button>
+                <button type="button" class="btn btn-primary" @click="submitProcurement">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 15 - 20
resources/views/procurement/procurement/create.blade.php

@@ -23,10 +23,16 @@
                             <p class="form-control-static text-danger small font-weight-bold" >{{ $errors->first('owner_id') }}</p>
                         </div>
                     </div>
+                    <div class="form-group row">
+                        <label for="customer_name" class="col-2 col-form-label text-right">客户名称</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control " name="customer_name" autocomplete="off" value="{{ old('customer_name') }}" v-model="customer_name" readonly>
+                        </div>
+                    </div>
                     <div class="form-group row">
                         <label for="owner_material_id" class="col-2 col-form-label text-right text-primary">项目耗材编号{{old('owner_material_id')}} *</label>
                         <div class="col-8">
-                            <select id="owner_material_id" name="owner_material_id" class="form-control @error('owner_material_id') is-invalid @enderror col-4" v-model="owner_material_id" @change="ownerMaterial" required>
+                            <select id="owner_material_id" name="owner_material_id" class="form-control @error('owner_material_id') is-invalid @enderror " v-model="owner_material_id" @change="ownerMaterial" required>
                                 <option v-for="ownerMaterial in ownerMaterials" :value="ownerMaterial.id">@{{ownerMaterial.material_code}}</option>
                             </select>
                             @error('owner_material_id')
@@ -63,37 +69,22 @@
                     <div class="form-group row">
                         <label for="quantity" class="col-2 col-form-label text-right">采购数量</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('quantity') is-invalid @enderror"
+                            <input type="text" class="form-control"
                                    name="quantity" autocomplete="off" value="{{ old('quantity') }}" v-model="quantity" required>
-                            @error('quantity')
-                            <span class="invalid-feedback" role="alert">
-                                <strong>{{ $message }}</strong>
-                            </span>
-                            @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="amount" class="col-2 col-form-label text-right">销售数量</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('amount') is-invalid @enderror"
+                            <input type="text" class="form-control"
                                    name="amount" autocomplete="off" value="{{ old('amount') }}" @input="countTotalPrice" v-model="amount" required>
-                            @error('amount')
-                            <span class="invalid-feedback" role="alert">
-                                <strong>{{ $message }}</strong>
-                            </span>
-                            @enderror
                         </div>
                     </div>
                     <div class="form-group row">
                         <label for="unit_price" class="col-2 col-form-label text-right">销售单价</label>
                         <div class="col-8">
-                            <input type="text" class="form-control @error('unit_price') is-invalid @enderror"
-                                   name="unit_price" autocomplete="off" value="{{ old('unit_price') }}" @input="countTotalPrice" v-model="unit_price" required>
-                            @error('unit_price')
-                            <span class="invalid-feedback" role="alert">
-                                <strong>{{ $message }}</strong>
-                            </span>
-                            @enderror
+                            <input type="text" class="form-control"
+                                   name="unit_price" autocomplete="off" value="{{ old('unit_price') }}" @input="countTotalPrice" v-model="unit_price">
                         </div>
                     </div>
                     <div class="form-group row">
@@ -130,12 +121,14 @@
                             },
                             @endforeach
                         ],
+                        @if($owner->customer)customer_name:'{{$owner->customer->name}}',@endif
                     },
                     @endforeach
                 ],
                 owner_id:'{{old('owner_id')}}',
                 owner_material_id:'{{old('owner_material_id')}}',
                 material_name:'{{old('material_name')}}',
+                customer_name:'{{old('customer_name')}}',
                 size:'{{old('size')}}',
                 special:'{{old('special')}}',
                 specification:'{{old('specification')}}',
@@ -157,6 +150,7 @@
                             if (owner.name.includes($val)){
                                 _this.owner_id=owner.id;
                                 _this.ownerMaterials=owner.ownerMaterials;
+                                _this.customer_name=owner.customer_name;
                             }
                         });
                     }
@@ -177,6 +171,7 @@
                     _this.owners.forEach(function (owner) {
                         if (_this.owner_id===owner.id){
                             _this.ownerMaterials=owner.ownerMaterials;
+                            _this.customer_name=owner.customer_name;
                         }
                     })
                 },

+ 208 - 85
resources/views/procurement/procurement/index.blade.php

@@ -65,10 +65,13 @@
             @can('采购管理-采购-新建')
                 @include('procurement.procurement._addEnquiry')
             @endcan
-            <span class="btn btn-sm btn-outline-danger ml-2"  @click="addProof">新增打样</span>
+            <span class="btn btn-sm btn-outline-danger ml-2" @click="addProof">新增打样</span>
             @can('采购管理-采购-新建')
                 @include('procurement.procurement._addProof')
             @endcan
+            @can('采购管理-采购-编辑')
+                @include('procurement.procurement._addQuantity')
+            @endcan
             <span class="btn btn-sm btn-outline-primary ml-2">重新发起</span>
         </div>
         <label for="all" id="cloneCheckAll" class="d-none">
@@ -84,23 +87,37 @@
                 </td>
                 <td class="">@{{ procurement.code }}</td>
                 <td v-if="procurement.owner_material.owner">@{{ procurement.owner_material.owner.name }}</td>
-                <td >@{{ procurement_type[procurement.type] }}</td>
-                <td v-if="procurement.owner_material.owner.customer">@{{ procurement.owner_material.owner.customer.company_name }}</td>
-                <td class="tooltipTarget" style="max-width: 200px;overflow:hidden" v-if="procurement.owner_material.material">@{{ procurement.owner_material.material.code }}</td>
-                <td class="text-muted" v-if="procurement.owner_material.material">@{{ procurement.owner_material.material.name }}</td>
+                <td>@{{ procurement_type[procurement.type] }}</td>
+                <td v-if="procurement.owner_material.owner.customer">@{{
+                    procurement.owner_material.owner.customer.company_name }}
+                </td>
+                <td class="tooltipTarget" style="max-width: 200px;overflow:hidden"
+                    v-if="procurement.owner_material.material">@{{ procurement.owner_material.material.code }}
+                </td>
+                <td class="text-muted" v-if="procurement.owner_material.material">@{{
+                    procurement.owner_material.material.name }}
+                </td>
                 <td class="text-muted" v-if="procurement.owner_material">@{{ procurement.owner_material.size }}</td>
                 <td class="text-muted" v-if="procurement.owner_material">@{{ procurement.owner_material.special }}</td>
-                <td class="text-muted" v-if="procurement.owner_material">@{{ procurement.owner_material.specification }}</td>
+                <td class="text-muted" v-if="procurement.owner_material">@{{ procurement.owner_material.specification
+                    }}
+                </td>
                 <td></td>
                 <td>@{{ procurement.quantity }}</td>
                 <td><span>@{{ procurement.unit_price }}</span></td>
                 <td><span></span></td>
-                <td><span></span></td>
+                <td>@{{ procurement.quantity*procurement.unit_price }}</td>
                 <td><span>@{{ procurement_status[procurement.status] }}</span></td>
-                <td v-if="procurement.owner_material.owner.customer">@{{ procurement.owner_material.owner.customer.phone }}</td>
+                <td v-if="procurement.owner_material.owner.customer">@{{ procurement.owner_material.owner.customer.phone
+                    }}
+                </td>
                 <td>
-                    <span class="btn btn-sm btn-outline-danger" v-if="procurement.supplier_id">取消</span>
-                    <span class="btn btn-sm btn-outline-success" v-if="procurement.type==1">发起采购</span>
+                    <span v-if="procurement_status[procurement.status]!='取消订单'">
+                        <span class="btn btn-sm btn-outline-danger" v-if="!procurement.supplier_id"
+                              @click="cancel(procurement.id,procurement.type,procurement.code)">取消</span>
+                        <span class="btn btn-sm btn-outline-success" v-if="procurement_type[procurement.type]=='询价单'"
+                              @click="initiateProcurement(procurement.id)">发起采购</span>
+                    </span>
                 </td>
             </tr>
         </table>
@@ -118,43 +135,52 @@
             data: {
                 countReceive:{!! $countReceive !!},
                 countProcurement:{!! $countProcurement !!},
-                procurements:{!! $procurements->toJson() !!}['data'],
-                owners:[
+                procurements: {!! $procurements->toJson() !!}['data'],
+                owners: [
                         @foreach($owners as $owner)
                     {
-                        name:'{{$owner->id}}',value:'{{$owner->name}}',
-                        ownerMaterials:[
+                        name: '{{$owner->id}}', value: '{{$owner->name}}',
+                        ownerMaterials: [
                                 @foreach($owner->ownerMaterials ? $owner->ownerMaterials :[] as $ownerMaterial)
                             {
-                                id:'{{$ownerMaterial->id}}',material_code:'{{$ownerMaterial->material_code}}',material_name:'{{$ownerMaterial->material->name}}',
-                                size:'{{$ownerMaterial->size}}',special:'{{$ownerMaterial->special}}',specification:'{{$ownerMaterial->specification}}',
+                                id: '{{$ownerMaterial->id}}',
+                                material_code: '{{$ownerMaterial->material_code}}',
+                                material_name: '{{$ownerMaterial->material->name}}',
+                                size: '{{$ownerMaterial->size}}',
+                                special: '{{$ownerMaterial->special}}',
+                                specification: '{{$ownerMaterial->specification}}',
                             },
                             @endforeach
                         ],
+                        @if($owner->customer)customer_name: '{{$owner->customer->name}}',@endif
                     },
                     @endforeach
                 ],
                 materials: [
                         @foreach($materials as $material)
-                    {name:'{{$material->id}}',value:'{{$material->name}}'},
+                    {
+                        name: '{{$material->id}}', value: '{{$material->name}}'
+                    },
                     @endforeach
                 ],
                 procurement_type:{!! json_encode(\App\Procurement::type,JSON_UNESCAPED_UNICODE) !!},
                 procurement_status:{!! json_encode(\App\Procurement::status,JSON_UNESCAPED_UNICODE) !!},
                 checkData: [],
                 sum:{!! $procurements->total() !!},
-                owner_id:'{{old('owner_id')}}',
-                owner_material_id:'{{old('owner_material_id')}}',
-                material_name:'{{old('material_name')}}',
-                size:'{{old('size')}}',
-                special:'{{old('special')}}',
-                specification:'{{old('specification')}}',
-                quantity:'{{old('quantity')}}',
-                amount:'{{old('amount')}}',
-                unit_price:'{{old('unit_price')}}',
-                total_price:'{{old('total_price')}}',
-                ownerMaterials:[],
-                errors:{},
+                owner_id: '{{old('owner_id')}}',
+                owner_material_id: '{{old('owner_material_id')}}',
+                material_name: '{{old('material_name')}}',
+                customer_name: '{{old('customer_name')}}',
+                size: '{{old('size')}}',
+                special: '{{old('special')}}',
+                specification: '{{old('specification')}}',
+                quantity: '{{old('quantity')}}',
+                amount: '{{old('amount')}}',
+                unit_price: '{{old('unit_price')}}',
+                total_price: '{{old('total_price')}}',
+                procurement_id:'',supplier:'',offer:'',supplier_id:'',
+                ownerMaterials: [],
+                errors: {},
 
             },
             mounted: function () {
@@ -169,8 +195,11 @@
                             placeholder: ['项目', '定位或多选项目'], data: this.owners
                         },
                         {
-                            name: 'material_id', type: 'select_multiple_select', tip: ['输入关键词快速定位下拉列表,回车确定', '选择要显示的耗材'],
-                            placeholder: ['耗材', '定位或多选耗材'], data: this.materials
+                            name: 'material_id',
+                            type: 'select_multiple_select',
+                            tip: ['输入关键词快速定位下拉列表,回车确定', '选择要显示的耗材'],
+                            placeholder: ['耗材', '定位或多选耗材'],
+                            data: this.materials
                         },
                         {name: 'company_name', type: 'input', tip: '采购公司:可在两侧增加百分号(%)进行模糊搜索', placeholder: '采购公司'},
                     ],
@@ -182,7 +211,7 @@
                 this.form.init();
                 let column = [
                     {
-                        name: 'cloneCheckAll', customization: true, type: 'checkAll',column:'id',
+                        name: 'cloneCheckAll', customization: true, type: 'checkAll', column: 'id',
                         dom: $('#cloneCheckAll').removeClass('d-none'), neglect: true
                     },
                     {name: 'code', value: '采购编号', neglect: true},
@@ -231,114 +260,208 @@
                         this.checkData = [];
                     }
                 },
-                addProcurement(){
+                addProcurement() {
+                    this.errors = {};
                     $('#add-procurement').modal('show');
                 },
-                addEnquiry(){
+                addEnquiry() {
+                    this.errors = {};
                     $('#add-enquiry').modal('show');
                 },
-                addProof(){
+                addProof() {
+                    this.errors = {};
                     $('#add-proof').modal('show');
                 },
-                owner_seek:function (e) {
+                initiateProcurement(id) {
                     let _this=this;
-                    let $val=e.target.value;
-                    if($val===''){
-                        _this.owner_id='';
-                    }else{
+                    this.procurement_id=id;
+                    let url="{{url('procurement/procurement/initiateProcurement')}}";
+                    let params={id:id};
+                    window.axios.post(url,params).then(res => {
+                            if (res.data.success) {
+                              _this.supplier=res.data.data.supplier.name;
+                              _this.supplier_id=res.data.data.supplier_id;
+                              _this.offer=res.data.data.offer;
+                              $('#add-quantity').modal('show');
+                            } else {
+                                tempTip.setDuration(3000);
+                                tempTip.show(res.data.message);
+                            }
+                        }).catch(err => {
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:" + err);
+                    });
+                },
+                owner_seek: function (e) {
+                    let _this = this;
+                    let $val = e.target.value;
+                    if ($val === '') {
+                        _this.owner_id = '';
+                    } else {
                         _this.owners.forEach(function (owner) {
-                            if (owner.value.includes($val)){
-                                _this.owner_id=owner.name;
-                                _this.ownerMaterials=owner.ownerMaterials;
+                            if (owner.value.includes($val)) {
+                                _this.owner_id = owner.name;
+                                _this.ownerMaterials = owner.ownerMaterials;
+                                _this.customer_name = owner.customer_name;
                             }
                         });
                     }
                 },
-                ownerMaterial:function () {
-                    let _this=this;
+                ownerMaterial: function () {
+                    let _this = this;
                     _this.ownerMaterials.forEach(function (ownerMaterial) {
-                        if (_this.owner_material_id===ownerMaterial.id){
-                            _this.material_name=ownerMaterial.material_name;
-                            _this.size=ownerMaterial.size;
-                            _this.special=ownerMaterial.special;
-                            _this.specification=ownerMaterial.specification;
+                        if (_this.owner_material_id === ownerMaterial.id) {
+                            _this.material_name = ownerMaterial.material_name;
+                            _this.size = ownerMaterial.size;
+                            _this.special = ownerMaterial.special;
+                            _this.specification = ownerMaterial.specification;
                         }
                     })
                 },
-                selectOwner:function () {
-                    let _this=this;
+                selectOwner: function () {
+                    let _this = this;
                     _this.owners.forEach(function (owner) {
-                        if (_this.owner_id===owner.name){
-                            _this.ownerMaterials=owner.ownerMaterials;
+                        if (_this.owner_id === owner.name) {
+                            _this.ownerMaterials = owner.ownerMaterials;
+                            _this.customer_name = owner.customer_name;
                         }
                     })
                 },
-                countTotalPrice:function () {
-                    let _this=this;
-                    if (_this.unit_price===''|| _this.amount==='')_this.total_price=null;
-                    _this.total_price=_this.unit_price*_this.amount;
+                countTotalPrice: function () {
+                    let _this = this;
+                    if (_this.unit_price === '' || _this.amount === '') _this.total_price = null;
+                    _this.total_price = _this.unit_price * _this.amount;
                 },
-                createProcurement(){
-                    let _this=this;
+                createProcurement() {
+                    let _this = this;
                     let url = '{{url('procurement/procurement/createProcurement')}}';
-                    let params = {owner_material_id:_this.owner_material_id,quantity:_this.quantity,amount:_this.amount,unit_price:_this.unit_price};
-                    window.axios.post(url,params).then(function (res) {
-                        if (!res.data.success){
-                            _this.errors=res.data.errors;
-                        }else {
+                    let params = {
+                        owner_id: _this.owner_id,
+                        owner_material_id: _this.owner_material_id,
+                        quantity: _this.quantity,
+                        amount: _this.amount,
+                        unit_price: _this.unit_price
+                    };
+                    window.axios.post(url, params).then(function (res) {
+                        if (!res.data.success) {
+                            _this.errors = res.data.errors;
+                        } else {
                             _this.procurements.push(res.data.data);
                             $("#add-procurement").modal('hide');
+                            _this.clearData();
                             tempTip.setDuration(3000);
                             tempTip.showSuccess('新增采购单成功!');
 
                         }
                     }).catch(function (err) {
                         tempTip.setDuration(3000);
-                        tempTip.show('新增采购单失败!网络错误:'+err);
+                        tempTip.show('新增采购单失败!网络错误:' + err);
                     });
                 },
-                createEnquiry(){
-                    let _this=this;
+                createEnquiry() {
+                    let _this = this;
                     let url = '{{url('procurement/procurement/createEnquiry')}}';
-                    let params = {owner_id:_this.owner_id,owner_material_id:_this.owner_material_id};
-                    window.axios.post(url,params).then(function (res) {
-                        if (!res.data.success){
-                            _this.errors=res.data.errors;
-                        }else {
+                    let params = {owner_id: _this.owner_id, owner_material_id: _this.owner_material_id};
+                    window.axios.post(url, params).then(function (res) {
+                        if (!res.data.success) {
+                            _this.errors = res.data.errors;
+                        } else {
                             _this.procurements.push(res.data.data);
                             $("#add-enquiry").modal('hide');
+                            _this.clearData();
                             tempTip.setDuration(3000);
                             tempTip.showSuccess('新增询价单成功!');
 
                         }
                     }).catch(function (err) {
                         tempTip.setDuration(3000);
-                        tempTip.show('新增询价单失败!网络错误:'+err);
+                        tempTip.show('新增询价单失败!网络错误:' + err);
                     });
                 },
-                createProof(){
-                    let _this=this;
+                createProof() {
+                    let _this = this;
                     let url = '{{url('procurement/procurement/createProof')}}';
-                    let params = {owner_id:_this.owner_id,owner_material_id:_this.owner_material_id};
-                    window.axios.post(url,params).then(function (res) {
-                        if (!res.data.success){
-                            _this.errors=res.data.errors;
-                        }else {
+                    let params = {owner_id: _this.owner_id, owner_material_id: _this.owner_material_id};
+                    window.axios.post(url, params).then(function (res) {
+                        if (!res.data.success) {
+                            _this.errors = res.data.errors;
+                        } else {
                             _this.procurements.push(res.data.data);
                             $("#add-proof").modal('hide');
+                            _this.clearData();
                             tempTip.setDuration(3000);
                             tempTip.showSuccess('新增打样单成功!');
 
                         }
                     }).catch(function (err) {
                         tempTip.setDuration(3000);
-                        tempTip.show('新增打样单失败!网络错误:'+err);
+                        tempTip.show('新增打样单失败!网络错误:' + err);
                     });
                 },
-                procurementExport(selectAll){
+                clearData() {
+                    this.owner_id = '';this.owner_material_id = '';
+                    this.material_name = '';this.customer_name = '';
+                    this.size = '';this.special = '';
+                    this.specification = '';this.quantity = '';
+                    this.amount = '';this.unit_price = '';
+                    this.total_price = '';this.procurement_id='';
+                    this.supplier_id='',this.offer='';
+                },
+                procurementExport(selectAll) {
                     let url = '{{url('procurement/procurement/procurementExport')}}';
-                    let token='{{ csrf_token() }}';
-                    excelExport(selectAll,this.checkData,url,this.sum,token);
+                    let token = '{{ csrf_token() }}';
+                    excelExport(selectAll, this.checkData, url, this.sum, token);
+                },
+                cancel(id, type, code) {
+                    window.tempTip.confirm('确定取消' + this.procurement_type[type] + ' ' + code, () => {
+                        window.axios.get("{{url('procurement/procurement/cancel')}}/" + id)
+                            .then(res => {
+                                if (res.data.success) {
+                                    this.procurements.forEach(function (procurement) {
+                                        if (procurement.id === res.data.data.id) {
+                                            procurement.status = res.data.data.status;
+                                            window.tempTip.setDuration(2000);
+                                            window.tempTip.showSuccess("已成功取消该条采购申请");
+                                        }
+                                    })
+                                } else {
+                                    tempTip.setDuration(3000);
+                                    tempTip.show(res.data.message);
+                                }
+                            }).catch(err => {
+                            window.tempTip.setDuration(3000);
+                            window.tempTip.show("网络错误:" + err);
+                        });
+                    });
+                },
+                submitProcurement() {
+                    let _this=this;
+                    let id=this.procurement_id;
+                    if (!id)return;
+                    let url="{{url('procurement/procurement/submitProcurement')}}";
+                    let params={id:id,quantity:this.quantity,amount:this.amount,unit_price:this.unit_price,offer:this.offer,supplier_id:this.supplier_id};
+                    window.axios.post(url,params).then(res => {
+                            if (!res.data.success) {
+                                _this.errors = res.data.errors;
+                            } else {
+                                this.procurements.forEach(function (procurement) {
+                                    if (procurement.id === res.data.data.id) {
+                                        procurement.status = res.data.data.status;
+                                        procurement.amount = res.data.data.amount;
+                                        procurement.type = res.data.data.type;
+                                        procurement.quantity = res.data.data.quantity;
+                                        procurement.unit_price = res.data.data.unit_price;
+                                        $("#add-quantity").modal('hide');
+                                        _this.clearData();
+                                        window.tempTip.setDuration(2000);
+                                        window.tempTip.showSuccess("已成功发起采购申请");
+                                    }
+                                })
+                            }
+                        }).catch(err => {
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:" + err);
+                    });
                 },
 
             }

+ 3 - 0
routes/web.php

@@ -730,6 +730,9 @@ Route::group(['prefix'=>'procurement'],function () {
         Route::post('createEnquiry','ProcurementController@createEnquiry');
         Route::post('createProof','ProcurementController@createProof');
         Route::any('procurementExport','ProcurementController@procurementExport');
+        Route::get('cancel/{id}','ProcurementController@cancel');
+        Route::post('initiateProcurement','ProcurementController@initiateProcurement');
+        Route::post('submitProcurement','ProcurementController@submitProcurement');
     });
     /** 财务 */
     Route::group(['prefix'=>'finance'],function(){