public function updateLeasingReturnQty($data)
 {
     $update = SalesOrderItem::where($this->key_detail, $data->id)->where('type', 2)->get();
     if (!empty($update)) {
         foreach ($update as $key => $value) {
             $params = ['leasing_return_quantity' => $value->quantity];
             if (!$value->update($params)) {
                 DB::rollback();
                 throw $this->response->error('failed_update_leasing_return_quantity', 500);
             }
         }
     }
 }
 public function validationLeasingReturn()
 {
     Validator::extend('unique_leasing_item', function ($attribute, $value, $parameters, $validator) {
         $idSalesOrderItem = Request::get('id_sales_order_item');
         //cek list dengan status harus 0  kalo sudah 0 berarti sudah di confirm bisa masuk lagi
         $data = LeasingReturnItem::where('id_sales_order_item', $idSalesOrderItem)->join('leasing_returns', 'leasing_return_items.id_leasing_return', '=', 'leasing_returns.id')->where('leasing_returns.status', 0)->where('leasing_return_items.deleted_at');
         // ignore when edit detail
         if (isset(Request::get('detail')['id_detail'])) {
             $data->where('leasing_return_items.id', '!=', Request::get('detail')['id_detail']);
         }
         if ($data->count() > 0) {
             return false;
         }
         return true;
     });
     Validator::extend('exist_in_so', function ($attribute, $value, $parameters, $validator) {
         $idSalesOrder = Request::get('id_sales_order');
         $idSalesOrderItem = Request::get('id_sales_order_item');
         //cek list detail merupakan anak dari so yang dipilih
         $data = SalesOrder::where('sales_orders.id', $idSalesOrder)->join('sales_order_items', 'sales_order_items.id_sales_order', '=', 'sales_orders.id')->where('sales_order_items.id', $idSalesOrderItem)->where('sales_order_items.deleted_at')->count();
         if ($data <= 0) {
             return false;
         }
         return true;
     });
     Validator::extend('so_confirmed', function ($attribute, $value, $parameters, $validator) {
         $idSalesOrder = Request::get('id_sales_order');
         //cek so harus punya status confirm
         $data = SalesOrder::where('sales_orders.id', $idSalesOrder)->join('sales_order_items', 'sales_order_items.id_sales_order', '=', 'sales_orders.id')->where('sales_orders.status', 1)->where('sales_order_items.deleted_at')->count();
         if ($data <= 0) {
             return false;
         }
         return true;
     });
     Validator::extend('lr_before_confirm_destroy_update', function ($attribute, $value, $parameters, $validator) {
         $idLeasingReturn = Request::get('id');
         //cek lr harus punya status open
         $data = LeasingReturn::where('leasing_returns.id', $idLeasingReturn)->where('leasing_returns.status', 0)->count();
         if ($data <= 0) {
             return false;
         }
         return true;
     });
     Validator::extend('lr_before_void', function ($attribute, $value, $parameters, $validator) {
         $idLeasingReturn = Request::get('id');
         //cek lr harus punya status confirm
         $data = LeasingReturn::where('leasing_returns.id', $idLeasingReturn)->where('leasing_returns.status', 1)->count();
         if ($data <= 0) {
             return false;
         }
         return true;
     });
     Validator::extend('max_leasing_item', function ($attribute, $value, $parameters, $validator) {
         $idSoItem = Request::get('id_sales_order_item');
         //cek lr harus punya status confirm
         $data = SalesOrderItem::where('sales_order_items.id', $idSoItem)->first();
         $totalQty = Request::get('quantity_return') + Request::get('quantity_demaged') + Request::get('quantity_lost');
         if ($totalQty <= $data->leasing_return_quantity) {
             return true;
         }
         return false;
     });
 }