Quellcode durchsuchen

采购管理-修改采购单价

haozi vor 5 Jahren
Ursprung
Commit
ea52b3ec57

+ 15 - 0
app/Http/Controllers/ProcurementController.php

@@ -206,6 +206,21 @@ class ProcurementController extends Controller
             return ['success' => false,'message' => $e->getMessage()];
         }
     }
+    public function costPrice(Request $request){
+        $this->gate('采购管理-财务-采购账单');
+        $id=$request->input('id');
+        $cost_price=$request->input('cost_price');
+        try {
+            $procurement=Procurement::query()->find($id);
+            if ($procurement->cost_price!=$cost_price)$procurement->update(['cost_price'=>$cost_price]);
+            $procurement = $procurement->loadMissing(['initiator','supplier','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 show(Procurement $procurement)

+ 24 - 0
resources/views/procurement/finance/_changeCostPrice.blade.php

@@ -0,0 +1,24 @@
+<div class="modal " id="change-costPrice" 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="cost_price" class="col-2 col-form-label text-right">采购单价</label>
+                        <div class="col-8">
+                            <input type="text" class="form-control "  name="cost_price" autocomplete="off"  v-model="cost_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="costPrice">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 40 - 28
resources/views/procurement/finance/procurementBill.blade.php

@@ -33,14 +33,14 @@
                 <td class="">@{{ procurement.created_at }}</td>
                 <td class=""></td>
                 <td class=""></td>
-                <td class="">@{{ procurement.owner_name }}</td>
-                <td class="">@{{ procurement.company_name }}</td>
-                <td class="">@{{ procurement.supplier_name }}</td>
-                <td class="tooltipTarget" style="max-width: 200px;overflow:hidden">@{{ procurement.material_code }}</td>
-                <td class="text-muted">@{{ procurement.material_name }}</td>
-                <td class="text-muted">@{{ procurement.size }}</td>
-                <td class="text-muted">@{{ procurement.special }}</td>
-                <td class="text-muted">@{{ procurement.specification }}</td>
+                <td v-if="procurement.owner_material.owner">@{{ procurement.owner_material.owner.name }}</td>
+                <td v-if="procurement.owner_material.owner.customer">@{{ procurement.owner_material.owner.customer.company_name }}</td>
+                <td v-if="procurement.supplier">@{{ procurement.supplier.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>@{{ procurement.quantity }}</td>{{--采购数量--}}
                 <td>@{{ procurement.amount }}</td> {{--销售数量--}}
                 <td></td>
@@ -51,10 +51,13 @@
                 <td><span>@{{ procurement_status[procurement.status] }}</span></td>
                 <td>
                     <span class="btn btn-sm btn-outline-danger">锁定</span>
-                    <span class="btn btn-sm btn-outline-success">修改采购单价</span>
+                    <span class="btn btn-sm btn-outline-success" @click="changeCostPrice(procurement.id,procurement.cost_price)">修改采购单价</span>
                 </td>
             </tr>
         </table>
+        @can('采购管理-财务-采购账单')
+            @include('procurement.finance._changeCostPrice')
+        @endcan
         <div class="text-info h5 btn btn">{{$procurements->count()}}/@{{ sum }}</div>
         <div>{{$procurements->appends($paginateParams)->links()}}</div>
     </div>
@@ -67,25 +70,7 @@
         let vue = new Vue({
             el: '#list',
             data: {
-                procurements: [
-                        @foreach($procurements as $procurement)
-                    {
-                        id:'{{$procurement->id}}',code:'{{$procurement->code}}',type:'{{$procurement->type}}',created_at:'{{$procurement->created_at}}',
-                        quantity:'{{$procurement->quantity}}',unit_price:'{{$procurement->unit_price}}',status:'{{$procurement->status}}',cost_price:'{{$procurement->cost_price}}',
-                        @if($procurement->ownerMaterial)
-                        owner_id:'{{$procurement->ownerMaterial->owner_id}}',size:'{{$procurement->ownerMaterial->size}}',
-                        special:'{{$procurement->ownerMaterial->special}}',specification:'{{$procurement->ownerMaterial->specification}}',@endif
-                            @if($procurement->ownerMaterial->material)
-                        material_id:'{{$procurement->ownerMaterial->material->id}}',material_code:'{{$procurement->ownerMaterial->material->code}}',
-                        material_name:'{{$procurement->ownerMaterial->material->name}}',@endif
-                            @if($procurement->ownerMaterial->owner)owner_name:'{{$procurement->ownerMaterial->owner->name}}',@endif
-                            @if($procurement->supplier)supplier_name:'{{$procurement->supplier->name}}',@endif
-                            @if($procurement->ownerMaterial->owner->customer)
-                        company_name:'{{$procurement->ownerMaterial->owner->customer->company_name}}',customer_id:'{{$procurement->ownerMaterial->owner->customer->id}}',
-                        phone:'{{$procurement->ownerMaterial->owner->customer->phone}}',@endif
-                    },
-                    @endforeach
-                ],
+                procurements: {!! $procurements->toJson() !!}['data'],
                 owners:[
                         @foreach($owners as $owner)
                     {name:'{{$owner->id}}',value:'{{$owner->name}}'},
@@ -104,6 +89,7 @@
                 checkData: [],
                 sum:{!! $procurements->total() !!},
                 procurement_status:{!! json_encode(\App\Procurement::status,JSON_UNESCAPED_UNICODE) !!},
+                procurement_id:'',cost_price:'',
 
             },
             mounted: function () {
@@ -188,6 +174,32 @@
                         this.checkData = [];
                     }
                 },
+                changeCostPrice(id,cost_price){
+                    this.procurement_id=id;
+                    this.cost_price=cost_price;
+                    $("#change-costPrice").modal('show');
+                },
+                costPrice(){
+                    let _this=this;
+                    let url='{{url('procurement/finance/costPrice')}}';
+                    let param={id:_this.procurement_id,cost_price:_this.cost_price};
+                    window.axios.post(url,param).then(function (res) {
+                        if (res.data.success){
+                            _this.procurements.forEach(function (procurement) {
+                                if (procurement.id===res.data.data.id){
+                                    procurement.cost_price=res.data.data.cost_price;
+                                    $("#change-costPrice").modal('hide');
+                                }
+                            })
+                        }else {
+                            tempTip.setDuration(3000);
+                            tempTip.show(res.data.message);
+                        }
+                    }).catch(function (err) {
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("网络错误:" + err);
+                    })
+                },
                 procurementBillExport(selectAll){
                     let url = '{{url('procurement/finance/procurementBillExport')}}';
                     let token='{{ csrf_token() }}';

+ 1 - 0
routes/web.php

@@ -743,6 +743,7 @@ Route::group(['prefix'=>'procurement'],function () {
         Route::any('procurementTotalBillExport','ProcurementController@procurementTotalBillExport');
         Route::any('procurementBillExport','ProcurementController@procurementBillExport');
         Route::any('checkBillExport','ProcurementController@checkBillExport');
+        Route::post('costPrice','ProcurementController@costPrice');
     });
     Route::get('relating',function (){return view('procurement.menuProcurement');});
 });