diff --git a/netforce_clinic/layouts/clinic_account_menu.xml b/netforce_clinic/layouts/clinic_account_menu.xml
index 2b9c2a4..98139d3 100644
--- a/netforce_clinic/layouts/clinic_account_menu.xml
+++ b/netforce_clinic/layouts/clinic_account_menu.xml
@@ -17,6 +17,7 @@
+
-
diff --git a/netforce_clinic/layouts/clinic_report_wizard_labor_cost.xml b/netforce_clinic/layouts/clinic_report_wizard_labor_cost.xml
new file mode 100644
index 0000000..11d4d88
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_report_wizard_labor_cost.xml
@@ -0,0 +1,18 @@
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 37b40fe..9a690ab 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -148,3 +148,4 @@ from . import payment_matching
from . import create_invoice_payment
from . import report_stock_card
from . import report_receipt_summary
+from . import report_wizard_labor_cost
diff --git a/netforce_clinic/models/report_labor_cost.py b/netforce_clinic/models/report_labor_cost.py
index 2fe7531..c68c6f8 100644
--- a/netforce_clinic/models/report_labor_cost.py
+++ b/netforce_clinic/models/report_labor_cost.py
@@ -404,7 +404,7 @@ class ReportLaborCost(Model):
if key=='name':
vals['desc']=True
for line in lines:
- vals[no]=con2float(line[key])
+ vals['l%s'%(no)]=con2float(line[key])
no+=1
lines2.append(vals)
return lines2
diff --git a/netforce_clinic/models/report_labor_cost_detail.py b/netforce_clinic/models/report_labor_cost_detail.py
index 0a7e05d..1b64c01 100644
--- a/netforce_clinic/models/report_labor_cost_detail.py
+++ b/netforce_clinic/models/report_labor_cost_detail.py
@@ -279,12 +279,12 @@ class ReportLaborCostDetail(Model):
'dpt_lines': dpt_lines,
'show_all': show_count <=1 and True or False,
}
- data['dpts_txt']=[{0: '#', 1: 'วันที่'}]
+ data['dpts_txt']=[{'l0': '#', 'l1': 'วันที่'}]
vals={}
no=0
dpt_len=len(data['dpts_txt'][0])
for dpt in dpts:
- data['dpts_txt'][0][no+dpt_len]=dpt['name']
+ data['dpts_txt'][0]['l%s'% (no+dpt_len)]=dpt['name']
vals[no]=0
no+=1
count=1
diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py
index 1beb7f0..bc0e021 100644
--- a/netforce_clinic/models/report_labor_cost_summary.py
+++ b/netforce_clinic/models/report_labor_cost_summary.py
@@ -69,7 +69,7 @@ class ReportLaborCostSummary(Model):
'level_id': level_id or None,
'cycle_id': cycle_id or None,
}
- print('res ', res)
+ #print('res ', res)
return res
def get_report_data(self,ids,context={}):
@@ -295,7 +295,7 @@ class ReportLaborCostSummary(Model):
no=0
dpt_len=len(data['dpts_txt'][0])
for dpt in dpts:
- data['dpts_txt'][0][no+dpt_len]=dpt['name']
+ data['dpts_txt'][0]['l%s'%(no+dpt_len)]=dpt['name']
vals[no]=0
no+=1
count=1
diff --git a/netforce_clinic/models/report_wizard_labor_cost.py b/netforce_clinic/models/report_wizard_labor_cost.py
new file mode 100644
index 0000000..06ffc46
--- /dev/null
+++ b/netforce_clinic/models/report_wizard_labor_cost.py
@@ -0,0 +1,266 @@
+import time
+from datetime import datetime
+from calendar import monthrange
+
+from netforce.model import Model,fields,get_model
+from netforce.access import get_active_company, set_active_company, get_active_user, set_active_user
+from netforce.database import get_connection
+
+class ReportLaborCost(Model):
+ _name="clinic.report.wizard.labor.cost"
+ _string="Report Wizard Labor Cost"
+ _transient=True
+
+ _fields={
+ "date": fields.Date("Month"),
+ "period_id": fields.Many2One("clinic.period.line","Period"),
+ "date_from": fields.Date("From", required=True),
+ "date_to": fields.Date("To", required=True),
+ "branch_id": fields.Many2One("clinic.branch","Branch"),
+ "cycle_id": fields.Many2One("clinic.cycle","Cycle"),
+ "department_id": fields.Many2One("clinic.department","Department"),
+ "staff_type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
+ "staff_id": fields.Many2One("clinic.staff","Staff")
+ }
+
+ def _get_date_from(self,context={}):
+ year,month,day=time.strftime("%Y-%m-%d").split("-")
+ #return '%s-%s-01'%(year,month)
+ return '%s-%s-%s'%(year,month,day)
+
+ 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)
+ return "%s-%s-%s"%(year,month,day)
+
+ def default_get(self,field_names=None,context={},**kw):
+ defaults=context.get("defaults",{})
+ date_from=defaults.get("date_from", self._get_date_from())
+ date_to=defaults.get("date_to", self._get_date_to())
+ print('defaults ', defaults)
+ yearnow=date_from.split("-")[0]
+ period_id=None
+ for period in get_model('clinic.period').search_browse([[]]):
+ for line in period.lines:
+ if line.state=='open':
+ period_id=line.id
+ date_from=line.date_start
+ date_to=line.date_stop
+ break
+ res={
+ 'period_id': period_id,
+ 'date': time.strftime("%Y-%m-%d"),
+ 'date_from': date_from,
+ 'date_to': date_to,
+ }
+ return res
+
+ def wizard_report_summany(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ return {
+ "next": {
+ "type": "report_odt2",
+ "model": self._name,
+ "template": "report_wizard_labor_cost_summany",
+ "refer_id": obj.id,
+ "method": "get_report_wizard_summany",
+ "convert": "pdf",
+ }
+ }
+
+ def wizard_report_details(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ return {
+ "next": {
+ "type": "report_odt2",
+ "model": self._name,
+ "template": "report_wizard_labor_cost_details",
+ "refer_id": obj.id,
+ "method": "get_report_wizard_details",
+ "convert": "pdf",
+ }
+ }
+
+ def get_report_data(self,ids,context={}):
+ return
+
+ def get_report_wizard_summany(self,ids,context={}):
+ obj=[]
+ if ids:
+ obj=self.browse(ids)[0]
+ company_id=get_active_company()
+ if not company_id:
+ set_active_company(1)
+ company_id=1
+ company=get_model("company").browse(company_id)
+ pages1=[]
+ pages2=[]
+ t1=datetime.now()
+ lc_vals={
+ 'date': obj.date_form,
+ 'period_id': obj.period_id.id,
+ 'date_from': obj.date_form,
+ 'date_to': obj.date_to,
+ 'cycle_id': obj.cycle_id.id or None,
+ 'branch_id': obj.branch_id.id or None,
+ 'report_type': 'cross',
+ 'department_id': obj.department_id.id or None,
+ }
+ lc_id=get_model('clinic.report.labor.cost').create(lc_vals)
+ lc_data=get_model('clinic.report.labor.cost').get_report_data([lc_id])
+ #data['lc_data'].append(lc_data) # END STEP 1
+ data={
+ "comp_name":company.name,
+ "date_from_1": obj.date_from,
+ "date_to_1": obj.date_to,
+ "dlines2": lc_data['dlines2'] or None,
+ "nlines2": lc_data['nlines2'] or None,
+ "ctlines2": lc_data['ctlines2'] or None,
+ }
+ pages1.append(data)
+ t2=datetime.now()
+ print('step 1 : ',t2-t1)
+
+ #STEP 2
+ staff_data=[]
+ if obj.staff_type:
+ staff_data.append(obj.staff_type)
+ else:
+ staff_data=['doctor','nurse']
+ for s_line in staff_data:
+ sum_id=get_model('clinic.report.labor.cost.summary').create({
+ 'date': obj.date_from,
+ 'date_from': obj.date_from,
+ 'date_to': obj.date_to,
+ 'staff_type': obj.staff_type or s_line,
+ 'staff_id': obj.staff_id or None,
+ 'cycle_id': obj.cycle_id.id or None,
+ 'branch_id': obj.branch_id.id or None,
+ 'department_id': obj.department_id.id or None,
+ })
+ sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
+ if s_line=='doctor':
+ sum_data.update({'staff_name':'ตารางหมอ'})
+ elif s_line=='nurse':
+ sum_data.update({'staff_name':'ตารางพยาบาล'})
+ data={
+ "comp_name":company.name,
+ "date_from_1": obj.date_from,
+ "date_to_1": obj.date_to,
+ "emp_type": sum_data['staff_type'] or None,
+ "dpts_txt": sum_data['dpts_txt'] or None,
+ "items": sum_data['items'] or None,
+ "total_lines_txt": sum_data['total_lines_txt'] or None,
+ }
+ pages2.append(data)
+ t2=datetime.now()
+ print('step 2 : ',t2-t1)
+ if pages1 and pages2:
+ pages1[-1]['is_last_page']=True
+ pages2[-1]['is_last_page']=True
+ return {
+ "pages1": pages1,
+ "pages2": pages2,
+ }
+
+ def get_report_wizard_details(self,ids,context={}):
+ obj=[]
+ if ids:
+ obj=self.browse(ids)[0]
+ company_id=get_active_company()
+ if not company_id:
+ set_active_company(1)
+ company_id=1
+ company=get_model("company").browse(company_id)
+ pages=[]
+ t1=datetime.now()
+
+ #STEP 2
+ i=0
+ staff_data=[]
+ if obj.staff_type:
+ staff_data.append(obj.staff_type)
+ else:
+ staff_data=['doctor','nurse']
+ for s_line in staff_data:
+ sum_id=get_model('clinic.report.labor.cost.summary').create({
+ 'date': obj.date_from,
+ 'date_from': obj.date_from,
+ 'date_to': obj.date_to,
+ #'staff_type': s_line,
+ 'staff_type': obj.staff_type or s_line,
+ 'staff_id': obj.staff_id or None,
+ 'cycle_id': obj.cycle_id.id or None,
+ 'branch_id': obj.branch_id.id or None,
+ 'department_id': obj.department_id.id or None,
+ })
+ sum_data=get_model('clinic.report.labor.cost.summary').get_report_data([sum_id])
+ t2=datetime.now()
+ print('step 2 : ',t2-t1)
+
+ #STEP 3
+ for detail_line in sum_data['lines']:
+ detail_id=get_model('clinic.report.labor.cost.detail').create({
+ 'date': obj.date_from,
+ 'date_from': obj.date_from,
+ 'date_to': obj.date_to,
+ 'staff_type': detail_line['staff_type'] or None,
+ 'staff_id': detail_line['staff_id'] or None,
+ 'cycle_id': None,
+ 'branch_id': obj.branch_id.id or None,
+ 'department_id': obj.department_id.id or None,
+ })
+ detail_data=get_model('clinic.report.labor.cost.detail').get_report_data([detail_id])
+ data={
+ "date_from_1": obj.date_from,
+ "date_to_1": obj.date_to,
+ "emp_type": detail_line['staff_type'] or None,
+ "emp_name": detail_line['staff_name'] or None,
+ "detail_dpts_txt": detail_data['dpts_txt'] or None,
+ "detail_items": detail_data['items'] or None,
+ "detail_total_lines_txt": detail_data['total_lines_txt'] or None,
+ }
+ pages.append(data)
+ t2=datetime.now()
+ i=i+1
+ print('step 3 : ',t2-t1,' item in %d and name %s >>>>>>>> %s'%(i,detail_line['staff_name'],detail_line['staff_type']))
+ if pages:
+ pages[-1]['is_last_page']=True
+ return {
+ "pages": pages,
+ }
+
+ 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_branch(self,context={}):
+ data=context['data']
+ data['department_id']=None
+ return data
+
+ def onchange_from(self,context={}):
+ data=context['data']
+ data['date_to']=data['date_from']
+ return data
+
+ def onchange_period(self,context={}):
+ data=context['data']
+ period_id=data['period_id']
+ period=get_model('clinic.period.line').browse(period_id)
+ data['date_from']=period.date_start
+ data['date_to']=period.date_stop
+ return data
+
+ def onchange_type(self,context={}):
+ data=context['data']
+ data['staff_id']=None
+ return data
+
+ReportLaborCost.register()
diff --git a/netforce_clinic/reports/report_labor_cost.xlsx b/netforce_clinic/reports/report_labor_cost.xlsx
index 57c4f2e..b4ee819 100644
Binary files a/netforce_clinic/reports/report_labor_cost.xlsx and b/netforce_clinic/reports/report_labor_cost.xlsx differ
diff --git a/netforce_clinic/reports/report_labor_cost_detail.xlsx b/netforce_clinic/reports/report_labor_cost_detail.xlsx
index de92a0f..2d6e807 100644
Binary files a/netforce_clinic/reports/report_labor_cost_detail.xlsx and b/netforce_clinic/reports/report_labor_cost_detail.xlsx differ
diff --git a/netforce_clinic/reports/report_labor_cost_summary.xlsx b/netforce_clinic/reports/report_labor_cost_summary.xlsx
index a5797c0..d457871 100644
Binary files a/netforce_clinic/reports/report_labor_cost_summary.xlsx and b/netforce_clinic/reports/report_labor_cost_summary.xlsx differ
diff --git a/netforce_clinic/reports/report_wizard_labor_cost_details.odt b/netforce_clinic/reports/report_wizard_labor_cost_details.odt
new file mode 100644
index 0000000..50a5e69
Binary files /dev/null and b/netforce_clinic/reports/report_wizard_labor_cost_details.odt differ
diff --git a/netforce_clinic/reports/report_wizard_labor_cost_summany.odt b/netforce_clinic/reports/report_wizard_labor_cost_summany.odt
new file mode 100644
index 0000000..8bdf0d1
Binary files /dev/null and b/netforce_clinic/reports/report_wizard_labor_cost_summany.odt differ