link report

conv_bal
watcha.h 2015-02-17 23:28:44 +07:00
parent 85712d9e25
commit 513c2a3059
15 changed files with 425 additions and 12 deletions

View File

@ -0,0 +1,8 @@
<action>
<field name="string">Report Labor Cost Daily</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.labor.cost.daily</field>
<field name="report_template">report_labor_cost_daily</field>
<field name="report_template_xls">report_labor_cost_daily</field>
<field name="menu">account_menu</field>
</action>

View File

@ -0,0 +1,8 @@
<action>
<field name="string">Report Labor Cost Detail</field>
<field name="view_cls">report</field>
<field name="model">clinic.report.labor.cost.detail</field>
<field name="report_template">report_labor_cost_detail</field>
<field name="report_template_xls">report_labor_cost_detail</field>
<field name="menu">account_menu</field>
</action>

View File

@ -10,6 +10,7 @@
<header string="REPORTS"/> <header string="REPORTS"/>
<item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/> <item string="Labor Cost Summary" action="clinic_report_labor_cost_summary"/>
<item string="Labor Cost Detail" action="clinic_report_labor_cost_detail"/> <item string="Labor Cost Detail" action="clinic_report_labor_cost_detail"/>
<item string="Labor Cost Daily" action="clinic_report_labor_cost_daily"/>
<!--<item string="Staff" action="clinic_report_staff"/>--> <!--<item string="Staff" action="clinic_report_staff"/>-->
<!--<item string="Staff Fee" action="clinic_report_staff_fee"/>--> <!--<item string="Staff Fee" action="clinic_report_staff_fee"/>-->
<!--<item string="Staff Fee Detail" action="clinic_report_staff_fee_detail"/>--> <!--<item string="Staff Fee Detail" action="clinic_report_staff_fee_detail"/>-->

View File

@ -0,0 +1,5 @@
<form model="clinic.report.labor.cost.daily">
<field name="date" required="1" span="2"/>
<field name="type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/>
</form>

View File

@ -0,0 +1,8 @@
<form model="clinic.report.labor.cost.detail">
<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" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/>
<field name="department_id" span="2"/>
</form>

View File

@ -2,7 +2,7 @@
<field name="date" mode="month" onchange="onchange_date" span="2"/> <field name="date" mode="month" onchange="onchange_date" span="2"/>
<field name="date_from" required="1" span="2"/> <field name="date_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/> <field name="date_to" required="1" span="2"/>
<field name="type" span="2"/> <field name="type" onchange="onchange_type" span="2"/>
<field name="staff_id" domain='[["type","=",type]]' span="2"/> <field name="staff_id" domain='[["type","=",type]]' span="2"/>
<field name="only_value" span="2"/> <field name="only_value" span="2"/>
</form> </form>

View File

@ -76,6 +76,8 @@ from . import report_staff_fee_detail
from . import report_staff_fee_sum from . import report_staff_fee_sum
from . import report_payment_matching from . import report_payment_matching
from . import report_labor_cost_summary from . import report_labor_cost_summary
from . import report_labor_cost_detail
from . import report_labor_cost_daily
from . import branch from . import branch
from . import period from . import period
from . import period_line from . import period_line
@ -100,9 +102,9 @@ from . import make_apt
from . import make_apt_line from . import make_apt_line
from . import matching_payment from . import matching_payment
from . import matching_hdcase from . import matching_hdcase
from . import sale_order
from . import shop from . import shop
from . import shop_line from . import shop_line
from . import sale_order
from . import product from . import product
from . import base_user from . import base_user
from . import select_company from . import select_company

View File

@ -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()

View File

@ -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()

View File

@ -17,7 +17,7 @@ class ReportLaborCostSummary(Model):
"type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"), "type": fields.Selection([["doctor","Doctor"],["nurse","Nurse"],["staff","Staff"]],"Type"),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"), '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={}): def _get_date_from(self,context={}):
@ -37,9 +37,9 @@ class ReportLaborCostSummary(Model):
} }
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
fmt='%Y-%m-%d' res=get_model("clinic.report.labor.cost.summary").default_get()
date_from=time.strftime(fmt) date_from=res['date_from']
date_to=time.strftime(fmt) date_to=res['date_to']
company_id=get_active_company() company_id=get_active_company()
comp=get_model("company").browse(company_id) comp=get_model("company").browse(company_id)
staff_type=None staff_type=None
@ -61,7 +61,6 @@ class ReportLaborCostSummary(Model):
dom.append(['type','=',staff_type]) dom.append(['type','=',staff_type])
if only_value: if only_value:
dom.append(['amount','!=',0]) dom.append(['amount','!=',0])
staffs={} staffs={}
for line in get_model("clinic.labor.cost.line").search_browse(dom): for line in get_model("clinic.labor.cost.line").search_browse(dom):
lcost=line.labor_cost_id lcost=line.labor_cost_id
@ -72,8 +71,8 @@ class ReportLaborCostSummary(Model):
if not staffs.get(staff.name): if not staffs.get(staff.name):
staffs[staff.name]={ staffs[staff.name]={
'staff_id': staff.id, 'staff_id': staff.id,
'staff_type': staff.type,
dpt.name: { dpt.name: {
'type': staff.type,
'amt': 0, 'amt': 0,
}, },
} }
@ -82,7 +81,6 @@ class ReportLaborCostSummary(Model):
dpt.name: { dpt.name: {
'amt': 0, 'amt': 0,
}}) }})
staffs[staff.name][dpt.name]['amt']+=amt staffs[staff.name][dpt.name]['amt']+=amt
lines=[] lines=[]
dpts=get_model("clinic.department").search_read([],['name']) dpts=get_model("clinic.department").search_read([],['name'])
@ -96,6 +94,7 @@ class ReportLaborCostSummary(Model):
'no': no, 'no': no,
'staff_name': sname, 'staff_name': sname,
'staff_id': vals.get('staff_id'), 'staff_id': vals.get('staff_id'),
'staff_type': vals.get('staff_type'),
} }
total=0 total=0
lvals['sub_lines']=[] lvals['sub_lines']=[]
@ -134,6 +133,7 @@ class ReportLaborCostSummary(Model):
total+=amt total+=amt
total_lines.append({'amt': total}) total_lines.append({'amt': total})
print(date_from, ' ', date_to)
data={ data={
'title': title, 'title': title,
'date_from': date_from, 'date_from': date_from,
@ -155,4 +155,9 @@ class ReportLaborCostSummary(Model):
data['date_to']="%s-%s-%s"%(year,month,total_day) data['date_to']="%s-%s-%s"%(year,month,total_day)
return data return data
def onchange_type(self,context={}):
data=context['data']
data['staff_id']=None
return data
ReportLaborCostSummary.register() ReportLaborCostSummary.register()

View File

@ -0,0 +1,27 @@
<p></p>
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>HN</th>
<th>Patient</th>
<th>Type</th>
<th>Cycle</th>
<th>Department</th>
</tr>
</thead>
<tbody>
{{#each lines }}
<tr>
<td>{{no}}</td>
<td>{{hn}}</td>
<td>{{patient_name}}</td>
<td>{{patient_type_name}}</td>
<td>{{cycle_name}}</td>
<td>{{dpt_name}}</td>
</tr>
{{/each}}
</tbody>
<tfoot>
</tfoot>
</table>

View File

@ -0,0 +1,55 @@
<p></p>
<!--<table class="table table-condensed table-striped">-->
<table class="table table-bordered">
<thead>
<tr>
<th></th>
<th></th>
<th style="text-align:center" colspan="{{comp_span}}">{{comp_name}}</th>
<th></th>
</tr>
<tr>
<th rowspan="2">#</th>
<th rowspan="2">วันที่</th>
{{#each dpts}}
<th rowspan="2" colspan="2" style="text-align:center">{{name}}</th>
{{/each}}
<th rowspan="2" colspan="2" style="text-align:center;">รวม</th>
</tr>
<tr></tr>
<tr>
<th rowspan="2"></th>
<th rowspan="2"></th>
{{#each dpts}}
<th rowspan="2" style="text-align:center">{{qty_text}}</th>
<th rowspan="2" style="text-align:center">{{amt_text}}</th>
{{/each}}
<th rowspan="2" style="text-align:center;">คนไข้</th>
<th rowspan="2" style="text-align:center;">จำนวนเงิน</th>
</tr>
</thead>
<tbody>
{{#each lines }}
<tr>
<td>{{no}}</th>
<td>
{{date}}
</td>
{{#each sub_lines}}
<td style="text-align:right;">{{qty}}</td>
<td style="text-align:right;">{{currency amt zero=""}}</td>
{{/each}}
<td style="text-align:right;">{{currency total_qty zero=""}}</th>
<td style="text-align:right;">{{currency total_amt zero=""}}</th>
</tr>
{{/each}}
</tbody>
<tfoot>
<th>รวม</th>
<th style="text-align:right"></th>
{{#each dpt_lines}}
<th style="text-align:right;">{{qty}}</th>
<th style="text-align:right;">{{currency amt zero=""}}</th>
{{/each}}
</tfoot>
</table>

View File

@ -1,3 +1,4 @@
<p></p>
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead> <thead>
<tr> <tr>
@ -13,7 +14,7 @@
<th style="text-align:right">{{name}}</th> <th style="text-align:right">{{name}}</th>
{{/each}} {{/each}}
</th> </th>
<th rowspan="2" style="text-align:right;">Total</th> <th rowspan="2" style="text-align:right;">รวม</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -24,14 +25,18 @@
{{view "link" string=staff_name action="clinic_staff" action_options="mode=form" active_id=staff_id}} {{view "link" string=staff_name action="clinic_staff" action_options="mode=form" active_id=staff_id}}
</td> </td>
{{#each sub_lines}} {{#each sub_lines}}
<td style="text-align:right;">{{currency amt zero=""}}</td> <td style="text-align:right;">
<a href="#name=clinic_report_labor_cost_detail&defaults.date_from={{../../date_from}}&defaults.date_to={{../../date_to}}&defaults.staff_type={{../staff_type}}&defaults.staff_id={{../staff_id}}">
{{currency amt zero=""}}
</a>
</td>
{{/each}} {{/each}}
<td style="text-align:right;">{{currency total zero=""}}</th> <td style="text-align:right;">{{currency total zero=""}}</th>
</tr> </tr>
{{/each}} {{/each}}
</tbody> </tbody>
<tfoot> <tfoot>
<th></th> <th>รวม</th>
<th style="text-align:right"></th> <th style="text-align:right"></th>
{{#each total_lines}} {{#each total_lines}}
<th style="text-align:right;">{{currency amt zero=""}}</th> <th style="text-align:right;">{{currency amt zero=""}}</th>