public function index()
 {
     if (!$this->hasPermission($this->menuPermissionName)) {
         return view($this->viewPermissiondeniedName);
     }
     if (Auth::user()->isadmin) {
         $redlabels = RedLabel::get(['id', 'no']);
     } else {
         $redlabels = RedLabel::where('provinceid', Auth::user()->provinceid)->get(['id', 'no']);
     }
     $redlabelselectlist = array();
     foreach ($redlabels as $item) {
         array_push($redlabelselectlist, $item->id . ':' . $item->no);
     }
     if (Auth::user()->isadmin) {
         $carpayments = CarPayment::whereHas('carpreemption', function ($q) {
             $q->whereHas('redlabelhistories', function ($q2) {
                 $q2->whereNotNull('returndate');
             });
         })->with('carpreemption.buyerCustomer', 'car')->get();
     } else {
         $carpayments = CarPayment::where('provinceid', Auth::user()->provinceid)->whereHas('carpreemption', function ($q) {
             $q->whereHas('redlabelhistories', function ($q2) {
                 $q2->whereNotNull('returndate');
             });
         })->with('carpreemption.buyerCustomer', 'car')->get();
     }
     $carselectlist = array();
     $customerselectlist = array();
     $cashpledgeselectlist = array();
     foreach ($carpayments as $item) {
         array_push($carselectlist, $item->carpreemption->id . ':' . $item->car->engineno . '/' . $item->car->chassisno);
         array_push($customerselectlist, $item->carpreemption->id . ':' . $item->carpreemption->buyerCustomer->title . $item->carpreemption->buyerCustomer->firstname . ' ' . $item->carpreemption->buyerCustomer->lastname);
         array_push($cashpledgeselectlist, $item->carpreemption->id . ':' . $item->carpreemption->cashpledgeredlabel);
     }
     return view('returncashpledgeredlabel', ['redlabelselectlist' => implode(";", $redlabelselectlist), 'carselectlist' => implode(";", $carselectlist), 'customerselectlist' => implode(";", $customerselectlist), 'cashpledgeselectlist' => implode(";", $cashpledgeselectlist)]);
 }
Пример #2
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->issuedate = date('Y-m-d', strtotime($model->issuedate));
         $model->returndate = null;
         $model->createdby = Auth::user()->id;
         $model->createddate = date("Y-m-d H:i:s");
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::created(function ($model) {
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         $redlabel = RedLabel::find($model->redlabelid);
         $redlabel->customerid = $carpreemption->buyercustomerid;
         $redlabel->deposit = $carpreemption->cashpledgeredlabel;
         $redlabel->save();
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
     });
     static::updating(function ($model) {
         $model->issuedate = date('Y-m-d', strtotime($model->issuedate));
         if ($model->returndate != null && $model->returndate != '') {
             $model->returndate = date('Y-m-d', strtotime($model->returndate));
         } else {
             $model->returndate = null;
         }
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::updated(function ($model) {
         $maxid = Redlabelhistory::where('redlabelid', $model->redlabelid)->max('id');
         if ($model->returndate != null && $model->returndate != '') {
             if ($model->id == $maxid) {
                 $redlabel = RedLabel::find($model->redlabelid);
                 $redlabel->customerid = null;
                 $redlabel->carid = null;
                 $redlabel->deposit = null;
                 $redlabel->save();
             }
         } else {
             if ($model->id == $maxid) {
                 $carpreemption = CarPreemption::find($model->carpreemptionid);
                 $redlabel = RedLabel::find($model->redlabelid);
                 $redlabel->customerid = $carpreemption->buyercustomerid;
                 $redlabel->deposit = $carpreemption->cashpledgeredlabel;
                 $redlabel->save();
             }
         }
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
     });
     static::deleted(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
         $maxid = Redlabelhistory::where('redlabelid', $model->redlabelid)->max('id');
         if ($maxid == null || $maxid == '' || $model->id > $maxid) {
             $redlabel = RedLabel::find($model->redlabelid);
             $redlabel->customerid = null;
             $redlabel->carid = null;
             $redlabel->deposit = null;
             $redlabel->save();
         }
     });
 }