diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index 7a3a21e..8f460b9 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -46,7 +46,7 @@
         
- 
-        +
diff --git a/netforce_clinic/layouts/clinic_staff_rotate_form.xml b/netforce_clinic/layouts/clinic_staff_rotate_form.xml
index b457138..f025126 100644
--- a/netforce_clinic/layouts/clinic_staff_rotate_form.xml
+++ b/netforce_clinic/layouts/clinic_staff_rotate_form.xml
@@ -17,6 +17,6 @@
     
     
     
-        
+        
     
 
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index 0d73797..64d3552 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -250,8 +250,10 @@ class Patient(Model):
                 vals['state']='dispose'
                 if not vals.get("resign_date"):
                     vals['resign_date']=time.strftime("%Y-%m-%d")
+                vals['rm_remain_visit']=True
             else:
                 vals['state']='admit'
+                vals['rm_remain_visit']=False
         if 'card_no' in vals.keys():
             self.check_idcard(vals['card_no'])
         ctx={}
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index c5fe3f8..4af3e96 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -105,36 +105,50 @@ class ClinicSetting(Model):
             schd.confirm()
         return True
 
+    def remove_rotation(self,ids,context={}):
+        staffs={}
+        for rt in get_model("clinic.staff.rotation").search_browse([]):
+            staff=rt.staff_id 
+            if staff.name not in staffs:
+                staffs[staff.name]=[rt.id]
+            else:
+                staffs[staff.name].append(rt.id)
+        for st_name, vals in staffs.items():
+            for rt_id in vals:
+                rt=get_model("clinic.staff.rotation").browse(rt_id)
+                if not rt.level_id:
+                    rt.delete() 
+        print("Done!")
+        return
+
     def run_script(self,ids,context={}):
         user_id=get_active_user()
         if user_id !=1:
             print("Only admin!!")
             return
-        for cpt in get_model("clinic.patient.cycle").search_browse([]):
-            patient=cpt.patient_id
-            if patient.state!='admit':
-                print(patient.name)
-                cpt.delete()
+        lines=[]
+        for rt in get_model("clinic.staff.rotation").search_browse([]):
+            staff=rt.staff_id
+            if staff.type!='nurse':
+                continue
+            level_name=''
+            if staff.level_id:
+                level_name=staff.level_id.name
+            lines.append({
+                'id': rt.id,
+                'name': staff.name,
+                'level': level_name,
+                'categ': staff.categ_id.name or "",
+            })
+        st="Database ID,Staff,Level,Category\n" 
+        for line in sorted(lines,key=lambda x: x['name']):
+            st+="%s,%s,%s,%s\n"%(line['id'],line['name'],line['level'],line['categ'])
+        f=open("/tmp/rotation.csv","w")
+        f.write(st)
+        f.close()
         print("Done!")
         return
 
-        for pt in get_model("clinic.patient").search_browse([]):
-            pt.write({
-                'state': 'admit',
-            })
-        print("Done!")
-        return 
-        for citem in get_model("clinic.cycle.item").search_browse([]):
-            for line in citem.lines:
-                nurse=line.nurse_id
-                level=nurse.level_id
-                if not line.level_id:
-                    if level:
-                        line.write({
-                            'level_id': level.id
-                        })
-        print("Done!")
-
     def update_departments(self,ids,context={}):
         user_id=get_active_user()
         if user_id !=1:
diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py
index e3701b3..a8375e5 100644
--- a/netforce_clinic/models/staff.py
+++ b/netforce_clinic/models/staff.py
@@ -20,15 +20,6 @@ class Staff(Model):
             res[obj.id]=age
         return res
     
-    def _get_level(self,ids,context={}):
-        res={}
-        for obj in self.browse(ids):
-            level_id=None
-            for rotate in obj.rotations:
-                level_id=rotate.level_id.id
-            res[obj.id]=level_id
-        return res
-
     def _get_cycle(self,ids,context={}):
         res={}
         for obj in self.browse(ids):
@@ -39,20 +30,24 @@ class Staff(Model):
             res[obj.id]=cycle_id
         return res
     
-    def _get_base(self,ids,context={}):
+    def _get_rotation(self,ids,context={}):
         res={}
         for obj in self.browse(ids):
             wage=0
             max_cycle=0
             ot_per_cycle=0
+            level_id=None
             for rotate in obj.rotations:
-                wage=rotate.wage
-                max_cycle=rotate.max_cycle
-                ot_per_cycle=rotate.ot_per_cycle or 0
+                if rotate.state=='approved':
+                    level_id=rotate.level_id.id
+                    wage=rotate.wage
+                    max_cycle=rotate.max_cycle
+                    ot_per_cycle=rotate.ot_per_cycle or 0
             res[obj.id]={
                 'wage': wage,
                 'max_cycle': max_cycle,
                 'ot_per_cycle': ot_per_cycle,
+                'level_id': level_id,
             }
         return res
     
@@ -132,12 +127,12 @@ class Staff(Model):
         'image': fields.File("Image"),
         'note': fields.Text("Note"),
         'categ_id': fields.Many2One("clinic.staff.categ", "Category",search=True),
-        'level_id': fields.Many2One("clinic.staff.level", "Level", function="_get_level"),
+        'level_id': fields.Many2One("clinic.staff.level", "Level", function="_get_rotation",function_multi=True),
         'active': fields.Boolean("Active"),
         'date': fields.Date("Register Date"),
-        'wage': fields.Float("Wage", function="_get_base",function_multi=True),
-        'max_cycle': fields.Integer("Max Cycle", function="_get_base",function_multi=True),
-        'ot_per_cycle': fields.Integer("OT Per Cycle", function="_get_base",function_multi=True),
+        'wage': fields.Float("Wage", function="_get_rotation",function_multi=True),
+        'max_cycle': fields.Integer("Max Cycle", function="_get_rotation",function_multi=True),
+        'ot_per_cycle': fields.Integer("OT Per Cycle", function="_get_rotation",function_multi=True),
         'check_max_cycle': fields.Boolean("Check Max Cycle"),
         'hire_date': fields.Date("Hire Date"),
         'resign_date': fields.Date("Resign Date"),
diff --git a/netforce_clinic/models/staff_rotation.py b/netforce_clinic/models/staff_rotation.py
index 5095654..5b0d2d7 100644
--- a/netforce_clinic/models/staff_rotation.py
+++ b/netforce_clinic/models/staff_rotation.py
@@ -8,6 +8,15 @@ class StaffRotation(Model):
     _string="Staff Rotation"
     _multi_company=True
 
+    def _get_all(self,ids,context={}):
+        res={}
+        for obj in self.browse(ids):
+            staff=obj.staff_id
+            res[obj.id]={
+                'staff_name': staff.name or "",
+            }
+        return res
+
     _fields={
         "type": fields.Selection([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type",search=True),
         "staff_id": fields.Many2One("clinic.staff","Staff", search=True),
@@ -21,6 +30,7 @@ class StaffRotation(Model):
         "note": fields.Text("Note"),
         'company_id': fields.Many2One("company","Company"),
         'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
+        'staff_name': fields.Char("Staff Name", function="_get_all",function_multi=True,store=True), #XXX
     }
 
     _defaults={
@@ -41,5 +51,14 @@ class StaffRotation(Model):
             obj.write({
                 'state': 'approved',
             })
+    
+    def create(self,vals,**kw):
+        id=super().create(vals,**kw)
+        self.function_store([id])
+        return id
+
+    def write(self,ids,vals,**kw):
+        super().write(ids,vals,**kw)
+        self.function_store(ids)
 
 StaffRotation.register()
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 971fb8b..199d469 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -1,6 +1,10 @@
 todo:
-    - report k. boy (sub detail)
-    - change by department
+    - report k. boy (sub detail) -> ok
+    - staff rotation
+        - update level for staff
+            - add script to
+    - multi department access
+    - merge staff same name but different department
 ===============================
 
     - compute labor cost