nurse fee detail

conv_bal
watcha.h 2014-11-24 15:05:07 +07:00
parent 8f5cd8a899
commit a4683ca610
2 changed files with 81 additions and 26 deletions

View File

@ -1,4 +1,6 @@
import time
from datetime import datetime, timedelta
from calendar import monthrange
from netforce.model import Model,fields,get_model
@ -50,24 +52,68 @@ class ReportNurseFeeSum(Model):
month=obj.date_from.split("-")[1]
time_start=obj.date_from
time_stop=obj.date_to
# new patient of this month
dom=[]
dom.append(['resign_date','>=',time_start])
dom.append(['resign_date','<=',time_stop])
dom.append(['active','=',False])
records=get_model('clinic.patient').search_browse(dom)
# generate list of date
fmt='%Y-%m-%d'
start=datetime.strptime(time_start,fmt)
stop=datetime.strptime(time_stop,fmt)
days=(stop-start).days
day_list=[]
for day in range(days+1):
dt=start+timedelta(days=day)
day_list.append(dt.strftime(fmt))
cols=[]
for date in day_list:
cols.append({'name': date[8:10]})
lines=[]
no=1
for record in records:
lines.append({
'no': no,
'name': record.name or '',
'pid': record.id,
'note': record.note or '',
'resign_date': record.resign_date or '',
total_all={}
total_sum=0.0
for nurse in get_model("clinic.personal").search_browse([['type','=','nurse']]):
line={
'nurse_id': nurse.id,
'nurse_name': nurse.name or '',
'sub_lines': [],
}
total_amt=0.0
for date in day_list:
if not total_all.get(date):
total_all[date]=0.0
dom=[]
dom.append(['date','=',date])
dom.append(['personal_id','=',nurse.id])
amt=0
results=get_model("clinic.cycle.dialy.line").search_read(dom,['amount','cycle_dialy_id'])
cycle_dialy_id=None
if results:
for result in results:
amt+=result['amount'] or 0.0
cycle_dialy_id=result['cycle_dialy_id'][0]
line['sub_lines'].append({
'cycle_dialy_id': cycle_dialy_id,
'amt': amt,
'last': False,
})
total_all[date]+=amt # all day
total_amt+=amt
# total of each nurse
line['sub_lines'].append({
'amt': round(total_amt,2),
'last': True,
})
no+=1
lines.append(line)
total_sum+=total_amt
total_lines=[]
for date in day_list:
total_lines.append({
'amt': total_all[date],
})
total_lines.append({
'amt': total_sum,
})
month_str=utils.MONTHS['th_TH'][int(month)]
start=int(time_start[8:10])
stop=int(time_stop[8:10])
@ -75,7 +121,9 @@ class ReportNurseFeeSum(Model):
data={
'company_name': company.name or "",
'parent_company_name': company.parent_id.name or "",
'cols': cols,
'lines': lines,
'total_lines': total_lines,
'month': month_str,
'from': time_start,
'to': time_stop,

View File

@ -14,24 +14,31 @@
{{#if lines}}
<table class="table">
<thead>
<th>#</th>
<th>วันที่</th>
<th>ชื่อ</th>
<th>หมายเหตุ</th>
<th style="text-align:left;">พยาบาล</th>
{{#each cols}}
<th style="text-align:right;">{{name}}</th>
{{/each}}
<th style="text-align:right;">รวม</th>
</thead>
<tbody>
{{#each lines}}
<tr>
<td>{{no}}</td>
<td>{{resign_date}}</td>
<td>
{{view "link" string=name action="clinic_patient" action_options="mode=form" active_id=pid}}
</td>
<td>{{note}}</td>
<td style="text-align:left;">{{nurse_name}}</td>
{{#each sub_lines}}
{{#if last}}
<td style="text-align:right"><b>{{amt}}</b></td>
{{else}}
<td style="text-align:right">{{amt}}</td>
{{/if}}
{{/each}}
</tr>
{{/each}}
</tbody>
<tfoot>
<th>รวม</th>
{{#each total_lines}}
<th style="text-align:right">{{amt}}</th>
{{/each}}
</tfoot>
</table>
{{else}}