コード例 #1
0
ファイル: Branch.php プロジェクト: x-Zyte/nhp
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $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) {
         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()]);
         if ($model->isheadquarter) {
             for ($i = 1; $i <= $model->keyslot; $i++) {
                 $m = new KeySlot();
                 $m->provinceid = $model->provinceid;
                 $m->no = $i;
                 $m->active = true;
                 $m->save();
             }
         }
     });
     static::updating(function ($model) {
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::updated(function ($model) {
         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()]);
         if ($model->isheadquarter) {
             $max = KeySlot::where('provinceid', $model->provinceid)->max('no');
             if ($max == null) {
                 $max = 0;
             }
             if ($model->keyslot > $max) {
                 for ($i = $max + 1; $i <= $model->keyslot; $i++) {
                     $m = new KeySlot();
                     $m->provinceid = $model->provinceid;
                     $m->no = $i;
                     $m->active = true;
                     $m->save();
                 }
             } elseif ($model->keyslot < $max) {
                 KeySlot::where('provinceid', $model->provinceid)->where('no', '>', $model->keyslot)->delete();
             }
         }
     });
     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()]);
         if ($model->isheadquarter) {
             KeySlot::where('provinceid', $model->provinceid)->delete();
         }
     });
 }
コード例 #2
0
ファイル: Car.php プロジェクト: x-Zyte/nhp
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->issold = false;
         $model->isregistered = false;
         $model->isdelivered = false;
         $model->dodate = date('Y-m-d', strtotime($model->dodate));
         $model->receiveddate = date('Y-m-d', strtotime($model->receiveddate));
         $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) {
         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()]);
         $rs = DB::select('call running_number("' . $model->provinceid . date("Y") . '","' . $model->receivetype . '")');
         $model->no = $rs[0]->no;
         $min = KeySlot::where('provinceid', $model->provinceid)->where('active', true)->min('no');
         if ($min == null) {
             $branch = Branch::where('provinceid', $model->provinceid)->where('isheadquarter', true)->first();
             $branch->keyslot = $branch->keyslot + 1;
             $branch->save();
             $model->keyno = $branch->keyslot;
         } else {
             $model->keyno = $min;
         }
         $model->save();
         KeySlot::where('provinceid', $model->provinceid)->where('no', $model->keyno)->update(['active' => false]);
     });
     static::updating(function ($model) {
         $model->dodate = date('Y-m-d', strtotime($model->dodate));
         $model->receiveddate = date('Y-m-d', strtotime($model->receiveddate));
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::updated(function ($model) {
         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()]);
         if ($model->receivecarfilepath != '') {
             File::delete(public_path() . $model->receivecarfilepath);
         }
         if ($model->deliverycarfilepath != '') {
             File::delete(public_path() . $model->deliverycarfilepath);
         }
         KeySlot::where('provinceid', $model->provinceid)->where('no', $model->keyno)->update(['active' => true]);
     });
 }
コード例 #3
0
ファイル: CarPayment.php プロジェクト: x-Zyte/nissanhippro
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         $model->provinceid = $carpreemption->provinceid;
         $model->branchid = $carpreemption->branchid;
         if ($model->insurancecompanyid == '') {
             $model->insurancecompanyid = null;
         }
         if ($model->capitalinsurance == '') {
             $model->capitalinsurance = null;
         }
         if ($model->buyerpay == '') {
             $model->buyerpay = null;
         }
         if ($model->overdue == '') {
             $model->overdue = null;
         }
         if ($model->overdueinterest == '') {
             $model->overdueinterest = null;
         }
         if ($model->totaloverdue == '') {
             $model->totaloverdue = null;
         }
         if ($model->paybytype == '') {
             $model->paybytype = null;
         }
         if ($model->paybyotherdetails == '') {
             $model->paybyotherdetails = null;
         }
         if ($model->overdueinstallments == '') {
             $model->overdueinstallments = null;
         }
         if ($model->overdueinstallmentdate1 == '') {
             $model->overdueinstallmentdate1 = null;
         }
         if ($model->overdueinstallmentamount1 == '') {
             $model->overdueinstallmentamount1 = null;
         }
         if ($model->overdueinstallmentdate2 == '') {
             $model->overdueinstallmentdate2 = null;
         }
         if ($model->overdueinstallmentamount2 == '') {
             $model->overdueinstallmentamount2 = null;
         }
         if ($model->overdueinstallmentdate3 == '') {
             $model->overdueinstallmentdate3 = null;
         }
         if ($model->overdueinstallmentamount3 == '') {
             $model->overdueinstallmentamount3 = null;
         }
         if ($model->overdueinstallmentdate4 == '') {
             $model->overdueinstallmentdate4 = null;
         }
         if ($model->overdueinstallmentamount4 == '') {
             $model->overdueinstallmentamount4 = null;
         }
         if ($model->overdueinstallmentdate5 == '') {
             $model->overdueinstallmentdate5 = null;
         }
         if ($model->overdueinstallmentamount5 == '') {
             $model->overdueinstallmentamount5 = null;
         }
         if ($model->overdueinstallmentdate6 == '') {
             $model->overdueinstallmentdate6 = null;
         }
         if ($model->overdueinstallmentamount6 == '') {
             $model->overdueinstallmentamount6 = null;
         }
         if ($model->oldcarbuyername == '') {
             $model->oldcarbuyername = null;
         }
         if ($model->oldcarpayamount == '') {
             $model->oldcarpayamount = null;
         }
         if ($model->oldcarpaytype == '') {
             $model->oldcarpaytype = null;
         }
         if ($model->oldcarpaydate == '') {
             $model->oldcarpaydate = null;
         }
         if ($model->payeeemployeeid == '') {
             $model->payeeemployeeid = null;
         }
         if ($model->deliverycarbookno == '') {
             $model->deliverycarbookno = null;
         }
         if ($model->deliverycarno == '') {
             $model->deliverycarno = null;
         }
         if ($model->deliverycardate == '') {
             $model->deliverycardate = 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) {
         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()]);
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         if ($carpreemption->carobjectivetype == 0) {
             $redlabelhistory = Redlabelhistory::where('carpreemptionid', $carpreemption->id)->first();
             $redlabel = Redlabel::find($redlabelhistory->redlabelid);
             $redlabel->carid = $model->carid;
             $redlabel->customerid = $carpreemption->buyercustomerid;
             $redlabel->deposit = $carpreemption->cashpledgeredlabel;
             $redlabel->save();
         }
         if ($model->isdraft) {
             $carpreemption->status = 3;
         } else {
             $carpreemption->status = 1;
         }
         $carpreemption->save();
         $car = Car::find($model->carid);
         $car->issold = true;
         $car->buyercustomerid = $carpreemption->buyercustomerid;
         if ($model->deliverycarbookno != null && $model->deliverycarbookno != '') {
             $car->isdelivered = true;
             KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->update(['carid' => null, 'active' => true]);
         }
         $car->save();
     });
     static::updating(function ($model) {
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         $model->provinceid = $carpreemption->provinceid;
         $model->branchid = $carpreemption->branchid;
         if ($model->insurancecompanyid == '') {
             $model->insurancecompanyid = null;
         }
         if ($model->capitalinsurance == '') {
             $model->capitalinsurance = null;
         }
         if ($model->buyerpay == '') {
             $model->buyerpay = null;
         }
         if ($model->overdue == '') {
             $model->overdue = null;
         }
         if ($model->overdueinterest == '') {
             $model->overdueinterest = null;
         }
         if ($model->totaloverdue == '') {
             $model->totaloverdue = null;
         }
         if ($model->paybytype == '') {
             $model->paybytype = null;
         }
         if ($model->paybyotherdetails == '') {
             $model->paybyotherdetails = null;
         }
         if ($model->overdueinstallments == '') {
             $model->overdueinstallments = null;
         }
         if ($model->overdueinstallmentdate1 == '') {
             $model->overdueinstallmentdate1 = null;
         }
         if ($model->overdueinstallmentamount1 == '') {
             $model->overdueinstallmentamount1 = null;
         }
         if ($model->overdueinstallmentdate2 == '') {
             $model->overdueinstallmentdate2 = null;
         }
         if ($model->overdueinstallmentamount2 == '') {
             $model->overdueinstallmentamount2 = null;
         }
         if ($model->overdueinstallmentdate3 == '') {
             $model->overdueinstallmentdate3 = null;
         }
         if ($model->overdueinstallmentamount3 == '') {
             $model->overdueinstallmentamount3 = null;
         }
         if ($model->overdueinstallmentdate4 == '') {
             $model->overdueinstallmentdate4 = null;
         }
         if ($model->overdueinstallmentamount4 == '') {
             $model->overdueinstallmentamount4 = null;
         }
         if ($model->overdueinstallmentdate5 == '') {
             $model->overdueinstallmentdate5 = null;
         }
         if ($model->overdueinstallmentamount5 == '') {
             $model->overdueinstallmentamount5 = null;
         }
         if ($model->overdueinstallmentdate6 == '') {
             $model->overdueinstallmentdate6 = null;
         }
         if ($model->overdueinstallmentamount6 == '') {
             $model->overdueinstallmentamount6 = null;
         }
         if ($model->oldcarbuyername == '') {
             $model->oldcarbuyername = null;
         }
         if ($model->oldcarpayamount == '') {
             $model->oldcarpayamount = null;
         }
         if ($model->oldcarpaytype == '') {
             $model->oldcarpaytype = null;
         }
         if ($model->oldcarpaydate == '') {
             $model->oldcarpaydate = null;
         }
         if ($model->payeeemployeeid == '') {
             $model->payeeemployeeid = null;
         }
         if ($model->deliverycarbookno == '') {
             $model->deliverycarbookno = null;
         }
         if ($model->deliverycarno == '') {
             $model->deliverycarno = null;
         }
         if ($model->deliverycardate == '') {
             $model->deliverycardate = null;
         }
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::updated(function ($model) {
         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()]);
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         if ($model->isdraft) {
             $carpreemption->status = 3;
         } else {
             $carpreemption->status = 1;
         }
         $carpreemption->save();
         $car = Car::find($model->carid);
         if ($model->deliverycarbookno != null && $model->deliverycarbookno != '') {
             $car->isdelivered = true;
             KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->where('carid', $car->id)->update(['carid' => null, 'active' => true]);
         } else {
             $car->isdelivered = false;
             KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->whereNull('carid')->update(['carid' => $car->id, 'active' => false]);
         }
         $car->save();
     });
     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()]);
         $carpreemption = CarPreemption::find($model->carpreemptionid);
         if ($carpreemption->carobjectivetype == 0) {
             $redlabelhistory = Redlabelhistory::where('carpreemptionid', $carpreemption->id)->first();
             $redlabel = Redlabel::find($redlabelhistory->redlabelid);
             $redlabel->carid = null;
             $redlabel->save();
         }
         $carpreemption->status = 0;
         $carpreemption->save();
         $car = Car::find($model->carid);
         $car->issold = false;
         $car->isdelivered = false;
         KeySlot::where('provinceid', $car->provinceid)->where('no', $car->keyno)->whereNull('carid')->update(['carid' => $car->id, 'active' => false]);
     });
 }