diff --git a/netforce_clinic/actions/clinic_report_labor_cost_sub_detail.xml b/netforce_clinic/actions/clinic_report_labor_cost_sub_detail.xml
new file mode 100644
index 0000000..75c3dee
--- /dev/null
+++ b/netforce_clinic/actions/clinic_report_labor_cost_sub_detail.xml
@@ -0,0 +1,8 @@
+
+ Report Labor Cost Sub Detail
+ report
+ clinic.report.labor.cost.sub.detail
+ report_labor_cost_sub_detail
+ report_labor_cost_sub_detail
+ account_menu
+
diff --git a/netforce_clinic/layouts/clinic_account_menu.xml b/netforce_clinic/layouts/clinic_account_menu.xml
index 12fd036..9030a1a 100644
--- a/netforce_clinic/layouts/clinic_account_menu.xml
+++ b/netforce_clinic/layouts/clinic_account_menu.xml
@@ -9,6 +9,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_report_labor_cost_sub_detail.xml b/netforce_clinic/layouts/clinic_report_labor_cost_sub_detail.xml
new file mode 100644
index 0000000..a076092
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_report_labor_cost_sub_detail.xml
@@ -0,0 +1,8 @@
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 8059be5..41689fa 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -77,6 +77,7 @@ from . import report_staff_fee_sum
from . import report_payment_matching
from . import report_labor_cost_summary
from . import report_labor_cost_detail
+from . import report_labor_cost_sub_detail
from . import report_labor_cost_daily
from . import report_labor_cost_overtime
from . import branch
diff --git a/netforce_clinic/models/report_labor_cost_detail.py b/netforce_clinic/models/report_labor_cost_detail.py
index 0681dd6..dc04859 100644
--- a/netforce_clinic/models/report_labor_cost_detail.py
+++ b/netforce_clinic/models/report_labor_cost_detail.py
@@ -56,12 +56,11 @@ class ReportLaborCostDetail(Model):
defaults=self.default_get(context=context)
date_from=defaults.get("date_from")
date_to=defaults.get("date_to")
- staff_type=defaults.get("staff_type")
+ staff_type=defaults.get("type")
staff_id=defaults.get("staff_id")
department_id=defaults.get("department_id")
dom=[]
if ids:
- print("get from ids")
obj=self.browse(ids)[0]
date_from=obj.date_from
date_to=obj.date_to
@@ -127,6 +126,14 @@ class ReportLaborCostDetail(Model):
dates[date][dpt.name]['qty']+=qty
lines=[]
dpts=get_model("clinic.department").search_read([],['name'])
+ # link to sub detail
+ for dpt in dpts:
+ dpt.update({
+ 'staff_id': staff_id,
+ 'staff_type': staff_type,
+ 'date_from': date_from,
+ 'date_to': date_to,
+ })
dpts=sorted(dpts, key=lambda b: b['name'])
no=1
dlines=sorted(dates.keys()) #sort by staff name
@@ -192,6 +199,9 @@ class ReportLaborCostDetail(Model):
staff_name=staff.name or ''
data={
'staff_name': staff_name,
+ 'staff_id': staff_id,
+ 'staff_type': staff_type,
+ 'department_id': "0", #XXX
'date_from': date_from,
'date_to': date_to,
'dpts': dpts,
diff --git a/netforce_clinic/models/report_labor_cost_sub_detail.py b/netforce_clinic/models/report_labor_cost_sub_detail.py
new file mode 100644
index 0000000..3b25562
--- /dev/null
+++ b/netforce_clinic/models/report_labor_cost_sub_detail.py
@@ -0,0 +1,147 @@
+import time
+from calendar import monthrange
+
+from netforce.model import Model,fields,get_model
+from netforce.access import get_active_company
+
+class ReportLaborCostSubDetail(Model):
+ _name="clinic.report.labor.cost.sub.detail"
+ _string="Report Labor Cost Sub Detail"
+ _transient=True
+
+ _fields={
+ "date": fields.Date("Month"),
+ "date_from": fields.Date("From", required=True),
+ "date_to": fields.Date("To", required=True),
+ 'department_id': fields.Many2One("clinic.department","Department"),
+ 'staff_id': fields.Many2One("clinic.staff","Staff"),
+ "staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
+ 'department_id': fields.Many2One("clinic.department","Department"),
+ }
+
+ def _get_date_from(self,context={}):
+ year,month=time.strftime("%Y-%m").split("-")
+ return '%s-%s-01'%(year,month)
+
+ def _get_date_to(self,context={}):
+ year,month,day=time.strftime("%Y-%m-%d").split("-")
+ weekday, total_day=monthrange(int(year), int(month))
+ return "%s-%s-%s"%(year,month,total_day)
+
+ def default_get(self,field_names=None,context={},**kw):
+ defaults=context.get("defaults",{})
+ date_from=defaults.get("date_from")
+ if not date_from:
+ date_from=self._get_date_from()
+ date_to=defaults.get("date_to")
+ if not date_to:
+ date_to=self._get_date_to()
+ staff_type=defaults.get("staff_type","doctor")
+ staff_id=int(defaults.get('staff_id', "0"))
+ department_id=int(defaults.get('department_id', "0"))
+ res={
+ 'date': time.strftime("%Y-%m-%d"),
+ 'date_from': date_from,
+ 'date_to': date_to,
+ 'staff_type': staff_type,
+ 'staff_id': staff_id and staff_id or None,
+ 'department_id': department_id and department_id or None,
+ }
+ print('res ', res)
+ return res
+
+ def get_report_data(self,ids,context={}):
+ company_id=get_active_company()
+ comp=get_model("company").browse(company_id)
+ defaults=self.default_get(context=context)
+ date_from=defaults.get("date_from")
+ date_to=defaults.get("date_to")
+ staff_type=defaults.get("staff_type")
+ staff_id=defaults.get("staff_id")
+ department_id=defaults.get("department_id")
+ staff_name=''
+ dom=[]
+ if ids:
+ obj=self.browse(ids)[0]
+ date_from=obj.date_from
+ date_to=obj.date_to
+ staff_id=obj.staff_id.id
+ staff_name=obj.staff_id.name or ""
+ staff_type=obj.staff_type
+ department_id=obj.department_id.id
+ dom.append(['date','>=',date_from])
+ dom.append(['date','<=',date_to])
+ if staff_id and staff_type=='doctor':
+ dom.append(['staff_id','=',staff_id])
+ elif staff_id and staff_type=='nurse':
+ pass
+ if staff_type:
+ dom.append(['type','=',staff_type])
+ if department_id:
+ dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id])
+ if not staff_id:
+ return {}
+ def replace_quote(dom=""):
+ return dom.replace("'","\"")
+ lines=[]
+ amount_total=0
+ for line in get_model("clinic.labor.cost.line").search_browse(dom):
+ lcost=line.labor_cost_id
+ citem=lcost.cycle_item_id
+ date=citem.date
+ dpt=citem.department_id
+ amount=line.amount or 0
+ qty=line.qty or 0
+ if qty:
+ amount=amount/qty
+ for hdcase in citem.hd_cases:
+ patient=hdcase.patient_id
+ doctor=hdcase.doctor_id
+ vals={
+ 'date': date,
+ 'patient_name': patient.name or "",
+ 'department_name': dpt.name or "",
+ 'amount': amount,
+ }
+ if staff_type=='doctor' and doctor.id==staff_id:
+ lines.append(vals)
+ amount_total+=amount
+ elif staff_type=='nurse':
+ lines.append(vals)
+ amount_total+=amount
+ else:
+ pass
+ slines=[]
+ no=1
+ for line in sorted(lines,key=lambda x: (x['date'], x['department_name'])):
+ line['no']=no
+ slines.append(line)
+ no+=1
+
+ data={
+ 'staff_name': staff_name,
+ 'staff_id': staff_id,
+ 'staff_type': staff_type,
+ 'date_from': date_from,
+ 'date_to': date_to,
+ 'comp_name': comp.name or 0,
+ 'lines': slines,
+ 'amount_total': amount_total,
+ }
+ return data
+
+ def onchange_date(self,context={}):
+ data=context['data']
+ date=data['date']
+ year,month,day=date.split("-")
+ weekday, total_day=monthrange(int(year), int(month))
+ data['date_from']="%s-%s-01"%(year,month)
+ data['date_to']="%s-%s-%s"%(year,month,total_day)
+ return data
+
+ def onchange_type(self,context={}):
+ data=context['data']
+ data['staff_id']=None
+ return data
+
+ReportLaborCostSubDetail.register()
diff --git a/netforce_clinic/reports/report_labor_cost_sub_detail.xlsx b/netforce_clinic/reports/report_labor_cost_sub_detail.xlsx
new file mode 100644
index 0000000..ea852c3
Binary files /dev/null and b/netforce_clinic/reports/report_labor_cost_sub_detail.xlsx differ
diff --git a/netforce_clinic/templates/report_labor_cost_detail.hbs b/netforce_clinic/templates/report_labor_cost_detail.hbs
index aba60a7..3895a5f 100644
--- a/netforce_clinic/templates/report_labor_cost_detail.hbs
+++ b/netforce_clinic/templates/report_labor_cost_detail.hbs
@@ -6,14 +6,18 @@
|
|
- {{comp_name}} |
+
+ {{comp_name}}
+ |
|
# |
วันที่ |
{{#each dpts}}
- {{name}} |
+
+ {{name}}
+ |
{{/each}}
รวม |
diff --git a/netforce_clinic/templates/report_labor_cost_sub_detail.hbs b/netforce_clinic/templates/report_labor_cost_sub_detail.hbs
new file mode 100644
index 0000000..054538f
--- /dev/null
+++ b/netforce_clinic/templates/report_labor_cost_sub_detail.hbs
@@ -0,0 +1,34 @@
+
+{{#if lines}}
+
+
+
+ # |
+ Date |
+ Patient |
+ Department |
+ Amount |
+
+
+
+ {{#each lines }}
+
+ {{no}}
+ | {{date}}
+ | {{patient_name}} |
+ {{department_name}} |
+ {{currency amount zero=""}} |
+
+ {{/each}}
+
+
+ |
+ |
+ |
+ รวม |
+ {{currency amount_total zero=""}} |
+
+
+{{else}}
+ No items to show
+{{/if}}
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index f9ca269..971fb8b 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -1,20 +1,18 @@
todo:
+ - report k. boy (sub detail)
+ - change by department
+===============================
+
- compute labor cost
- update level -> ok
- set patient_id with domain state=='admit' -> ok
-
convbal -> not yet (wait yui) -> ok but have to update memo
-
post 10,000 invoices per one time -> ask david
patient & staff
- split name -> not yet
staff have multi department -> added but set have to set permission
- many2many
-
show epo(yes) in list of hd case ->ok
matching payment > ok
create contact from staff -> ok
script to clear invoice -> ok
-
-
-