diff --git a/netforce_clinic/actions/clinic_report_labor_cost_daily.xml b/netforce_clinic/actions/clinic_report_labor_cost_daily.xml new file mode 100644 index 0000000..6550858 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_labor_cost_daily.xml @@ -0,0 +1,8 @@ + + Report Labor Cost Daily + report + clinic.report.labor.cost.daily + report_labor_cost_daily + report_labor_cost_daily + account_menu + diff --git a/netforce_clinic/actions/clinic_report_labor_cost_detail.xml b/netforce_clinic/actions/clinic_report_labor_cost_detail.xml new file mode 100644 index 0000000..9c54ecf --- /dev/null +++ b/netforce_clinic/actions/clinic_report_labor_cost_detail.xml @@ -0,0 +1,8 @@ + + Report Labor Cost Detail + report + clinic.report.labor.cost.detail + report_labor_cost_detail + report_labor_cost_detail + account_menu + diff --git a/netforce_clinic/layouts/clinic_account_menu.xml b/netforce_clinic/layouts/clinic_account_menu.xml index 48fb75d..7c6c8d6 100644 --- a/netforce_clinic/layouts/clinic_account_menu.xml +++ b/netforce_clinic/layouts/clinic_account_menu.xml @@ -10,6 +10,7 @@
+ diff --git a/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml b/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml new file mode 100644 index 0000000..ac3bb96 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_labor_cost_daily.xml @@ -0,0 +1,5 @@ +
+ + + + diff --git a/netforce_clinic/layouts/clinic_report_labor_cost_detail.xml b/netforce_clinic/layouts/clinic_report_labor_cost_detail.xml new file mode 100644 index 0000000..1462a97 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_labor_cost_detail.xml @@ -0,0 +1,8 @@ +
+ + + + + + + diff --git a/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml b/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml index 3b43778..63843f5 100644 --- a/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml +++ b/netforce_clinic/layouts/clinic_report_labor_cost_summary.xml @@ -2,7 +2,7 @@ - + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index b30808b..e67173d 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -76,6 +76,8 @@ from . import report_staff_fee_detail 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_daily from . import branch from . import period from . import period_line @@ -100,9 +102,9 @@ from . import make_apt from . import make_apt_line from . import matching_payment from . import matching_hdcase +from . import sale_order from . import shop from . import shop_line -from . import sale_order from . import product from . import base_user from . import select_company diff --git a/netforce_clinic/models/report_labor_cost_daily.py b/netforce_clinic/models/report_labor_cost_daily.py new file mode 100644 index 0000000..e4e6743 --- /dev/null +++ b/netforce_clinic/models/report_labor_cost_daily.py @@ -0,0 +1,114 @@ +import time +from calendar import monthrange + +from netforce.model import Model,fields,get_model +from netforce.access import get_active_company + +class ReportLaborCostDaily(Model): + _name="clinic.report.labor.cost.daily" + _string="Report Labor Cost Daily" + _transient=True + + _fields={ + "date": fields.Date("Date"), + "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=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) + + _defaults={ + 'date': lambda *a: time.strftime("%Y-%m-%d"), + } + + def get_report_data(self,ids,context={}): + fmt='%Y-%m-%d' + date=time.strftime(fmt) + company_id=get_active_company() + comp=get_model("company").browse(company_id) + staff_type=None + staff_id=None + dom=[] + if ids: + obj=self.browse(ids)[0] + date=obj.date + staff_id=obj.staff_id.id + staff_type=obj.type + dom.append(['date','>=',date]) + dom.append(['date','<=',date]) + # prevent to load more + if not staff_id: + return {} + if staff_id: + dom.append(['staff_id','=',staff_id]) + if staff_type: + dom.append(['type','=',staff_type]) + lines=[] + no=1 + for line in get_model("clinic.labor.cost.line").search_browse(dom): + lcost=line.labor_cost_id + citem=lcost.cycle_item_id + cycle=citem.cycle_id + staff=line.staff_id + dpt=citem.department_id + amt=line.amount or 0 + if staff_type=='doctor': + for hdcase in citem.hd_cases: + doctor=hdcase.doctor_id + pt_type=hdcase.patient_type_id + pt=hdcase.patient_id + if staff.id==doctor.id: + lines.append({ + 'no': no, + 'hn': pt.number, + 'patient_id': pt.id, + 'patient_name': pt.name or '', + 'patient_type_name': pt_type.name or '', + 'amount': amt, + 'dpt_id': dpt.id, + 'dpt_name': dpt.name or "", + 'cycle_name': cycle.name, + 'cycle_id': cycle.id, + }) + no+=1 + elif staff_type=='nurse': + for hdcase in citem.hd_cases: + doctor=hdcase.doctor_id + pt_type=hdcase.patient_type_id + pt=hdcase.patient_id + lines.append({ + 'no': no, + 'hn': pt.number, + 'patient_id': pt.id, + 'patient_type_name': pt_type.name or '', + 'patient_name': pt.name or '', + 'dpt_id': dpt.id, + 'dpt_name': dpt.name or "", + 'amount': 0, + 'cycle_name': cycle.name, + 'cycle_id': cycle.id, + }) + no+=1 + else: + continue + data={ + 'staff_type': staff_type, + 'date': date, + 'comp_name': comp.name or 0, + 'lines': lines, + } + return data + + def onchange_type(self,context={}): + data=context['data'] + data['staff_id']=None + return data + +ReportLaborCostDaily.register() diff --git a/netforce_clinic/models/report_labor_cost_detail.py b/netforce_clinic/models/report_labor_cost_detail.py new file mode 100644 index 0000000..8177d9b --- /dev/null +++ b/netforce_clinic/models/report_labor_cost_detail.py @@ -0,0 +1,175 @@ +import time +from calendar import monthrange + +from netforce.model import Model,fields,get_model +from netforce.access import get_active_company + +class ReportLaborCostDetail(Model): + _name="clinic.report.labor.cost.detail" + _string="Report Labor Cost 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"), + "type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"), + 'department_id': fields.Many2One("clinic.department","Department"), + 'branch_id': fields.Many2One("clinic.branch","Branch"), + } + + 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) + + _defaults={ + 'date': lambda *a: time.strftime("%Y-%m-%d"), + 'date_from': _get_date_from, + 'date_to': _get_date_to, + 'type': 'doctor', + } + + def get_report_data(self,ids,context={}): + fmt='%Y-%m-%d' + date_from=time.strftime(fmt) + date_to=time.strftime(fmt) + company_id=get_active_company() + comp=get_model("company").browse(company_id) + staff_type=None + staff_id=None + department_id=None + defaults=context.get("defaults",{}) + if defaults: + print('get from default ', defaults) + date_from=defaults.get("date_from") + date_to=defaults.get("date_to") + department_id=defaults.get("department_id") + staff_type=defaults.get("staff_type") + staff_id=defaults.get("staff_id") + dom=[] + if ids: + print("get from ids") + obj=self.browse(ids)[0] + date_from=obj.date_from + date_to=obj.date_to + staff_id=obj.staff_id.id + staff_type=obj.type + department_id=obj.department_id.id + dom.append(['date','>=',date_from]) + dom.append(['date','<=',date_to]) + if staff_id: + dom.append(['staff_id','=',staff_id]) + if staff_type: + dom.append(['type','=',staff_type]) + if department_id: + dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id]) + #prevent to load more data + if not staff_id: + return {} + dates={} + 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 + if not date: + continue + dpt=citem.department_id + amt=line.amount or 0 + qty=len(citem.hd_cases) or 0 # qty of patient + if not dates.get(date): + dates[date]={ + dpt.name: { + 'amt': 0, + 'qty': 0, + }, + } + if not dates[date].get(dpt.name): + dates[date].update({ + dpt.name: { + 'amt': 0, + 'qty': 0, + }}) + dates[date][dpt.name]['amt']+=amt + dates[date][dpt.name]['qty']+=qty + lines=[] + dpts=get_model("clinic.department").search_read([],['name']) + dpts=sorted(dpts, key=lambda b: b['name']) + no=1 + dlines=sorted(dates.keys()) #sort by staff name + for kdate in dlines: + vals=dates[kdate] + lvals={ + 'no': no, + 'date': kdate, + } + total_qty, total_amt=0, 0 + lvals['sub_lines']=[] + for dpt in dpts: + amt,qty=0,0 + dname=dpt['name'] or '' + dpt_vals=vals.get(dname) + if dpt_vals: + amt=dpt_vals.get("amt",0) + qty=dpt_vals.get("qty",0) + lvals['sub_lines'].append({'qty': qty, 'amt': amt}) + total_amt+=amt + total_qty+=qty + lvals['total_qty']=total_qty # total show as right hand side + lvals['total_amt']=total_amt + lines.append(lvals) + no+=1 + # summary as footer + dpt_lines=[{'qty': 0, 'amt': 0} for dpt in dpts] + for line in lines: + i=0 + for sub_line in line['sub_lines']: + dpt_lines[i]['qty']+=sub_line['qty'] or 0 + dpt_lines[i]['amt']+=sub_line['amt'] or 0 + i+=1 + + ## summary as footer (total) + total_qty, total_amt=0, 0 + for tline in dpt_lines: + total_qty+=tline['qty'] or 0 + total_amt+=tline['amt'] or 0 + dpt_lines.append({'amt': total_amt, 'qty': total_qty}) + + for dpt in dpts: + dpt.update({ + 'qty_text': 'คนไข้', + 'amt_text': 'จำนวนเงิน', + }) + comp_span=(len(dpts)*2)+1 + data={ + 'date_from': date_from, + 'date_to': date_to, + 'dpts': dpts, + 'comp_name': comp.name or 0, + 'comp_span': comp_span, #qty, amt + 'lines': lines, + 'dpt_lines': dpt_lines, + } + 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 + +ReportLaborCostDetail.register() diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py index a1e76e3..2309ef0 100644 --- a/netforce_clinic/models/report_labor_cost_summary.py +++ b/netforce_clinic/models/report_labor_cost_summary.py @@ -17,7 +17,7 @@ class ReportLaborCostSummary(Model): "type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"), 'department_id': fields.Many2One("clinic.department","Department"), 'branch_id': fields.Many2One("clinic.branch","Branch"), - 'only_value': fields.Boolean("Only Value Exist"), + 'only_value': fields.Boolean("Only Amount"), } def _get_date_from(self,context={}): @@ -37,9 +37,9 @@ class ReportLaborCostSummary(Model): } def get_report_data(self,ids,context={}): - fmt='%Y-%m-%d' - date_from=time.strftime(fmt) - date_to=time.strftime(fmt) + res=get_model("clinic.report.labor.cost.summary").default_get() + date_from=res['date_from'] + date_to=res['date_to'] company_id=get_active_company() comp=get_model("company").browse(company_id) staff_type=None @@ -61,7 +61,6 @@ class ReportLaborCostSummary(Model): dom.append(['type','=',staff_type]) if only_value: dom.append(['amount','!=',0]) - staffs={} for line in get_model("clinic.labor.cost.line").search_browse(dom): lcost=line.labor_cost_id @@ -72,8 +71,8 @@ class ReportLaborCostSummary(Model): if not staffs.get(staff.name): staffs[staff.name]={ 'staff_id': staff.id, + 'staff_type': staff.type, dpt.name: { - 'type': staff.type, 'amt': 0, }, } @@ -82,7 +81,6 @@ class ReportLaborCostSummary(Model): dpt.name: { 'amt': 0, }}) - staffs[staff.name][dpt.name]['amt']+=amt lines=[] dpts=get_model("clinic.department").search_read([],['name']) @@ -96,6 +94,7 @@ class ReportLaborCostSummary(Model): 'no': no, 'staff_name': sname, 'staff_id': vals.get('staff_id'), + 'staff_type': vals.get('staff_type'), } total=0 lvals['sub_lines']=[] @@ -134,6 +133,7 @@ class ReportLaborCostSummary(Model): total+=amt total_lines.append({'amt': total}) + print(date_from, ' ', date_to) data={ 'title': title, 'date_from': date_from, @@ -155,4 +155,9 @@ class ReportLaborCostSummary(Model): 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 + ReportLaborCostSummary.register() diff --git a/netforce_clinic/reports/report_labor_cost.xlsx b/netforce_clinic/reports/report_labor_cost_detail.xlsx similarity index 100% rename from netforce_clinic/reports/report_labor_cost.xlsx rename to netforce_clinic/reports/report_labor_cost_detail.xlsx diff --git a/netforce_clinic/reports/report_labor_cost_summary.xlsx b/netforce_clinic/reports/report_labor_cost_summary.xlsx new file mode 100644 index 0000000..ce8adc3 Binary files /dev/null and b/netforce_clinic/reports/report_labor_cost_summary.xlsx differ diff --git a/netforce_clinic/templates/report_labor_cost_daily.hbs b/netforce_clinic/templates/report_labor_cost_daily.hbs new file mode 100644 index 0000000..7f9ff4e --- /dev/null +++ b/netforce_clinic/templates/report_labor_cost_daily.hbs @@ -0,0 +1,27 @@ +

+ + + + + + + + + + + + + {{#each lines }} + + + + + + + + + {{/each}} + + + +
#HNPatientTypeCycleDepartment
{{no}}{{hn}}{{patient_name}}{{patient_type_name}}{{cycle_name}}{{dpt_name}}
diff --git a/netforce_clinic/templates/report_labor_cost_detail.hbs b/netforce_clinic/templates/report_labor_cost_detail.hbs new file mode 100644 index 0000000..05875f4 --- /dev/null +++ b/netforce_clinic/templates/report_labor_cost_detail.hbs @@ -0,0 +1,55 @@ +

+ + + + + + + + + + + + + {{#each dpts}} + + {{/each}} + + + + + + + {{#each dpts}} + + + {{/each}} + + + + + + {{#each lines }} + + + {{#each sub_lines}} + + + {{/each}} + + {{/each}} + + + + + {{#each dpt_lines}} + + + {{/each}} + +
{{comp_name}}
#วันที่{{name}}รวม
{{qty_text}}{{amt_text}}คนไข้จำนวนเงิน
{{no}} + + {{date}} + {{qty}}{{currency amt zero=""}}{{currency total_qty zero=""}} + {{currency total_amt zero=""}} +
รวม{{qty}}{{currency amt zero=""}}
diff --git a/netforce_clinic/templates/report_labor_cost_summary.hbs b/netforce_clinic/templates/report_labor_cost_summary.hbs index b006c68..91425de 100644 --- a/netforce_clinic/templates/report_labor_cost_summary.hbs +++ b/netforce_clinic/templates/report_labor_cost_summary.hbs @@ -1,3 +1,4 @@ +

@@ -13,7 +14,7 @@ {{/each}} - + @@ -24,14 +25,18 @@ {{view "link" string=staff_name action="clinic_staff" action_options="mode=form" active_id=staff_id}} {{#each sub_lines}} - + {{/each}} {{/each}} - + {{#each total_lines}}
{{name}}Totalรวม
{{currency amt zero=""}} + + {{currency amt zero=""}} + + {{currency total zero=""}}
รวม {{currency amt zero=""}}