add labor cost report
parent
64a075e131
commit
b1c9344dc6
|
@ -0,0 +1,8 @@
|
|||
<action>
|
||||
<field name="string">Report Labor Cost</field>
|
||||
<field name="view_cls">report</field>
|
||||
<field name="model">clinic.report.labor.cost</field>
|
||||
<field name="report_template">report_labor_cost</field>
|
||||
<field name="report_template_xls">report_labor_cost</field>
|
||||
<field name="menu">account_menu</field>
|
||||
</action>
|
|
@ -9,6 +9,7 @@
|
|||
<item string="HD Case Expenses" action="clinic_hd_case_expense"/>
|
||||
<divider/>
|
||||
<header string="REPORTS"/>
|
||||
<item string="Labor Cost" action="clinic_report_labor_cost"/>
|
||||
<item string="Staff" action="clinic_report_staff"/>
|
||||
<item string="Staff Fee" action="clinic_report_staff_fee"/>
|
||||
<item string="Staff Fee Detail" action="clinic_report_staff_fee_detail"/>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<form model="clinic.report.labor.cost">
|
||||
<field name="date" mode="month" onchange="onchange_date" span="2"/>
|
||||
<field name="date_from" required="1" span="2"/>
|
||||
<field name="date_to" required="1" span="2"/>
|
||||
<field name="type" span="2"/>
|
||||
</form>
|
|
@ -74,6 +74,7 @@ from . import report_staff_fee
|
|||
from . import report_staff_fee_detail
|
||||
from . import report_staff_fee_sum
|
||||
from . import report_payment_matching
|
||||
from . import report_labor_cost
|
||||
from . import branch
|
||||
from . import period
|
||||
from . import period_line
|
||||
|
|
|
@ -58,7 +58,7 @@ class Patient(Model):
|
|||
"weight": fields.Float("Weight (kg.)"),
|
||||
"height": fields.Float("Height (cm.)"),
|
||||
"card_type": fields.Selection([("identification","Identification"),("passport","Passport")],"ID Type"),
|
||||
'card_no' : fields.Char("ID",size=13),
|
||||
'card_no' : fields.Char("ID"),
|
||||
'card_exp' : fields.Date("ID Exp."),
|
||||
"app_no": fields.Char("Application No."),
|
||||
"salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"),
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
import time
|
||||
from calendar import monthrange
|
||||
|
||||
from netforce.model import Model,fields,get_model
|
||||
from netforce.access import get_active_company
|
||||
|
||||
class ReportLaborCost(Model):
|
||||
_name="clinic.report.labor.cost"
|
||||
_string="Report Labor Cost"
|
||||
_transient=True
|
||||
|
||||
_fields={
|
||||
"date": fields.Date("Month"),
|
||||
"date_from": fields.Date("From", required=True),
|
||||
"date_to": fields.Date("To", required=True),
|
||||
'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,
|
||||
}
|
||||
|
||||
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)
|
||||
_type=None
|
||||
dom=[]
|
||||
if ids:
|
||||
obj=self.browse(ids)[0]
|
||||
date_from=obj.date_from
|
||||
date_to=obj.date_to
|
||||
_type=obj.type
|
||||
dom.append(['date','>=',date_from])
|
||||
dom.append(['date','<=',date_to])
|
||||
if _type:
|
||||
dom.append(['type','=',_type])
|
||||
staffs={}
|
||||
for line in get_model("clinic.labor.cost.line").search_browse(dom):
|
||||
lcost=line.labor_cost_id
|
||||
citem=lcost.cycle_item_id
|
||||
dpt=citem.department_id
|
||||
amt=line.amount or 0
|
||||
staff=line.staff_id
|
||||
if not staffs.get(staff.name):
|
||||
staffs[staff.name]={
|
||||
dpt.name: {
|
||||
'type': staff.type,
|
||||
'amt': 0,
|
||||
},
|
||||
}
|
||||
if not staffs[staff.name].get(dpt.name):
|
||||
staffs[staff.name][dpt.name]={
|
||||
'type': staff.type,
|
||||
'amt': 0,
|
||||
}
|
||||
staffs[staff.name][dpt.name]['amt']+=amt
|
||||
|
||||
lines=[]
|
||||
dpts=get_model("clinic.department").search_read([],['name'])
|
||||
dpts=sorted(dpts, key=lambda b: b['name'])
|
||||
no=1
|
||||
|
||||
staff_types=set()
|
||||
snames=sorted(staffs.keys()) #sort by staff name
|
||||
for sname in snames:
|
||||
vals=staffs[sname]
|
||||
lvals={
|
||||
'no': no,
|
||||
'staff_name': sname,
|
||||
}
|
||||
total=0
|
||||
lvals['sub_lines']=[]
|
||||
for dpt in dpts:
|
||||
dname=dpt['name'] or ''
|
||||
vals2=vals.get(dname)
|
||||
if vals2:
|
||||
amt=vals2.get("amt",0)
|
||||
staff_type=vals2.get("type",'')
|
||||
staff_types.update({staff_type})
|
||||
lvals['sub_lines'].append({'amt': amt})
|
||||
total+=amt
|
||||
lvals['total']=total
|
||||
lines.append(lvals)
|
||||
no+=1
|
||||
|
||||
title=''
|
||||
for stype in list(staff_types):
|
||||
if stype=='doctor':
|
||||
title+='Doctor'
|
||||
elif stype=='nurse':
|
||||
title+='Nurse'
|
||||
title=' and'.join(t for t in title.split(" "))
|
||||
|
||||
total_lines=[{'amt': 0} for dpt in dpts]
|
||||
for line in lines:
|
||||
i=0
|
||||
for sub_line in line['sub_lines']:
|
||||
amt=sub_line['amt'] or 0
|
||||
total_lines[i]['amt']+=amt
|
||||
i+=1
|
||||
total=0
|
||||
for tline in total_lines:
|
||||
amt=tline['amt'] or 0
|
||||
total+=amt
|
||||
|
||||
total_lines.append({'amt': total})
|
||||
data={
|
||||
'title': title,
|
||||
'date_from': obj.date_from,
|
||||
'date_to': obj.date_to,
|
||||
'dpts': dpts,
|
||||
'comp_name': comp.name or 0,
|
||||
'comp_span': len(dpts),
|
||||
'lines': lines,
|
||||
'total_lines': total_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
|
||||
|
||||
ReportLaborCost.register()
|
Binary file not shown.
|
@ -0,0 +1,41 @@
|
|||
<table class="table table-condensed table-striped">
|
||||
<thead>
|
||||
<th rowspan="2">#</th>
|
||||
<th rowspan="2">Name</th>
|
||||
<th colspan="{{comp_span}}">
|
||||
<table class="table" style="margin-bottom:0px">
|
||||
<thead>
|
||||
<th style="text-align:center" colspan="{{comp_span}}">{{comp_name}}</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
{{#each dpts}}
|
||||
<td>{{name}}</td>
|
||||
{{/each}}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</th>
|
||||
<th rowspan="2" style="text-align:center;">Total</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each lines }}
|
||||
<tr>
|
||||
<td>{{no}}</th>
|
||||
<td>{{staff_name}}</td>
|
||||
{{#each sub_lines}}
|
||||
<td style="text-align:right;">{{amt}}</td>
|
||||
{{/each}}
|
||||
<td style="text-align:right;">{{total}}</th>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<th></th>
|
||||
<th style="text-align:right"></th>
|
||||
{{#each total_lines}}
|
||||
<th style="text-align:right;">{{amt}}</th>
|
||||
{{/each}}
|
||||
<th></th>
|
||||
</tfoot>
|
||||
</table>
|
Loading…
Reference in New Issue