labor cost report

conv_bal
watcha.h@almacom.co.th 2015-04-09 11:16:59 +07:00
parent b88bf1b337
commit 4b51b8be9d
3 changed files with 75 additions and 19 deletions

View File

@ -32,7 +32,7 @@ class ReportLaborCost(Model):
defaults=context.get("defaults",{})
date_from=defaults.get("date_from", self._get_date_from())
date_to=defaults.get("date_to", self._get_date_to())
report_type=defaults.get("report_type","detail")
report_type=defaults.get("report_type","cross")
print('defaults ', defaults)
res={
'date': time.strftime("%Y-%m-%d"),
@ -150,29 +150,47 @@ class ReportLaborCost(Model):
ctdata={}
for line in get_model('clinic.labor.cost.line').search_browse(dom,order="department_id.name"):
cost_id=line.labor_cost_id
categ_name=line.categ_id.name or ""
categ=line.categ_id
categ_name=categ.name or "unknow"
citem=cost_id.cycle_item_id
department=citem.department_id
dpt_name=department.name or ''
qty=line.qty or 0
if line.type=='doctor':
if dpt_name not in ddata.keys():
ddata[dpt_name]=0
ddata[dpt_name]+=qty
ddata[dpt_name]={
'qty': 0,
'department_id': department.id,
'branch_id':department.branch_id.id,
}
ddata[dpt_name]['qty']+=qty
elif line.type=='nurse':
if categ_name not in ctdata.keys():
ctdata[categ_name]=0
ctdata[categ_name]+=line.pay_amount or 0
ctdata[categ_name]={
'amount': 0,
'categ_id': categ.id,
}
ctdata[categ_name]['amount']+=line.pay_amount or 0
if dpt_name not in ndata.keys():
ndata[dpt_name]=set()
ndata[dpt_name]={
'hdcases': set(),
'department_id': department.id,
'branch_id':department.branch_id.id,
}
for hdcase in citem.hd_cases:
ndata[dpt_name].update({hdcase.id})
ndata[dpt_name]['hdcases'].update({hdcase.id})
total_amount=0
for categ_name,amount in ctdata.items():
for categ_name,vals in ctdata.items():
amount=vals['amount'] or 0
categ_id=vals['categ_id']
total_amount+=amount
ctlines.append({
'name': categ_name,
'amount': amount,
'branch_id': branch_id,
'categ_id': categ_id,
'department_id': department_id,
'staff_type': 'nurse',
})
ctlines.append({
'name': 'รวม',
@ -185,8 +203,14 @@ class ReportLaborCost(Model):
'total_qty': 'รวมจำนวนครั้ง',
'cost': 'เป็นยอดเงินรวม',
'desc': True,
'department_id': None,
'branch_id':None,
'staff_type': 'doctor',
})
for dt_name,qty in ddata.items():
for dt_name,vals in ddata.items():
qty=vals['qty'] or 0
department_id=vals['department_id']
branch_id=vals['branch_id']
walkin=0
cost=(walkin+qty)*cost_per_case
dlines.append({
@ -196,6 +220,9 @@ class ReportLaborCost(Model):
'total_qty': walkin+qty,
'cost': cost,
'total': 0,
'department_id': department_id,
'branch_id': branch_id,
'staff_type': 'doctor',
})
dlines.append({
'name': 'รวม',
@ -203,6 +230,9 @@ class ReportLaborCost(Model):
'qty2': 0,
'total_qty':0,
'cost': 0,
'department_id': None,
'branch_id':None,
'staff_type': 'doctor',
})
for dline in dlines[1:-1]:
dlines[-1]['qty']+=dline['qty'] or 0
@ -215,21 +245,33 @@ class ReportLaborCost(Model):
'qty': 'จำนวนครั้ง',
'cost': 'เป็นยอดเงินรวม',
'total': 'รวม',
'department_id': None,
'branch_id': None,
'desc': True,
'staff_type': 'nurse',
})
for dt_name, hdcases in ndata.items():
for dt_name, vals in ndata.items():
hdcases=vals['hdcases']
department_id=vals['department_id']
branch_id=vals['branch_id']
total_hdcase=len(hdcases)
nlines.append({
'name': dt_name,
'qty': total_hdcase,
'cost': total_hdcase*vark,
'department_id': department_id,
'branch_id': branch_id,
'total': 0,
'staff_type': 'nurse',
})
nlines.append({
'name': 'รวม',
'qty': 0,
'cost': 0,
'total': 0,
'department_id': None,
'branch_id':None,
'staff_type': 'nurse',
})
for nline in nlines[1:-1]:
nlines[-1]['qty']+=nline['qty'] or 0

View File

@ -37,6 +37,9 @@ class ReportLaborCostSummary(Model):
date_from=defaults.get("date_from", self._get_date_from())
date_to=defaults.get("date_to", self._get_date_to())
branch_id=defaults.get("branch_id")
categ_id=defaults.get("categ_id")
if categ_id:
categ_id=int(categ_id)
if branch_id:
branch_id=int(branch_id)
department_id=defaults.get("department_id")
@ -46,15 +49,20 @@ class ReportLaborCostSummary(Model):
if staff_id:
staff_id=int(staff_id)
staff_type=defaults.get("staff_type","doctor")
level_id=defaults.get("level_id")
if level_id:
level_id=int(level_id)
res={
'date': date,
'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,
'branch_id': branch_id,
'department_id': department_id or None,
'branch_id': branch_id or None,
'only_value': True,
'categ_id': categ_id,
'level_id': level_id,
}
return res
@ -67,8 +75,8 @@ class ReportLaborCostSummary(Model):
only_value=defaults['only_value']
department_id=defaults['department_id']
branch_id=defaults['branch_id']
level_id=None
categ_id=None
categ_id=defaults['categ_id']
level_id=defaults['level_id']
dom=[]
if ids:
obj=self.browse(ids)[0]
@ -97,7 +105,7 @@ class ReportLaborCostSummary(Model):
dom.append(['labor_cost_id.cycle_item_id.department_id','=',department_id])
staffs={}
citems={}
print('dom ', dom)
print('>> dom: ', dom)
total_hdcase=0
for line in get_model("clinic.labor.cost.line").search_browse(dom):
lcost=line.labor_cost_id

View File

@ -100,7 +100,9 @@
{{#if desc}}
<th style="text-align:left;width:10%">{{cost}}</th>
{{else}}
<td style="text-align:right">{{currency cost}}</td>
<td style="text-align:right">
<a href="#name=clinic_report_labor_cost_summary&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}&defaults.staff_type={{staff_type}}">{{currency cost}}</a>
</td>
{{/if}}
{{/each}}
</tr>
@ -131,7 +133,9 @@
{{#if desc}}
<th>{{cost}}</th>
{{else}}
<td style="text-align:right">{{currency cost}}</td>
<td style="text-align:right">
<a href="#name=clinic_report_labor_cost_summary&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}&defaults.staff_type={{staff_type}}">{{currency cost}}</a>
</td>
{{/if}}
{{/each}}
</tr>
@ -142,7 +146,9 @@
{{#each ctlines }}
<tr>
<th style="text-align:left;width:14%">{{name}}</th>
<td style="text-align:right">{{currency amount}}</td>
<td style="text-align:right">
<a href="#name=clinic_report_labor_cost_summary&defaults.categ_id={{categ_id}}&defaults.date={{../../date}}&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}&defaults.staff_type={{staff_type}}">{{currency amount}}</a>
</td>
</tr>
{{/each}}
</tbody>