improve report

conv_bal
watcha.h@almacom.co.th 2015-04-30 22:10:55 +07:00
parent 70dc4dbb6a
commit fe20240d78
16 changed files with 228 additions and 27 deletions

View File

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

View File

@ -2,7 +2,7 @@
<field name="date" span="2" mode="month" onchange="onchange_date"/>
<field name="date_from" span="2"/>
<field name="date_to" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="3"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="3"/>
<!--<button string="PDF" method="run_report" icon="print" size="small"/>-->
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="report_type" span="2"/>
</form>

View File

@ -0,0 +1,9 @@
<form model="clinic.report.labor.cost.staff">
<field name="date" mode="month" onchange="onchange_date" span="2"/>
<field name="date_from" onchange="onchange_from" required="1" span="2"/>
<field name="date_to" required="1" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="cycle_id" span="2"/>
<field name="walkin" span="2"/>
</form>

View File

@ -6,6 +6,7 @@
<field name="product_id" domain='[["categ_id","=",prod_categ_id]]' span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="report_type" span="2"/>
<field name="types" span="4">
<list>
<field name="name"/>

View File

@ -5,4 +5,5 @@
<field name="prod_categ_id" span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="report_type" span="2"/>
</form>

View File

@ -82,6 +82,7 @@ from . import report_staff_fee_detail
from . import report_staff_fee_sum
from . import report_payment_matching
from . import report_labor_cost
from . import report_labor_cost_staff
from . import report_labor_cost_summary
from . import report_labor_cost_detail
from . import report_labor_cost_sub_detail

View File

@ -19,6 +19,7 @@ class ReportHDCaseSummary(Model):
"date_to": fields.Date("To", required=True),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'department_id': fields.Many2One("clinic.department","Departments"),
'report_type': fields.Selection([['completed','Completed'],['not_completed','Not Completed']],"Report Type"),
}
def _get_date_from(self,context={}):
@ -49,6 +50,7 @@ class ReportHDCaseSummary(Model):
'date_to': _get_date_to,
'branch_id': _get_branch,
'department_id': _get_department,
'report_type': 'completed',
}
def get_report_data(self,ids,context={}):
@ -63,6 +65,7 @@ class ReportHDCaseSummary(Model):
date_to=defaults.get('date_to',date)
branch_id=defaults.get("branch_id",None)
department_id=defaults.get("department_id",None)
report_type=defaults.get('report_type','completed')
if branch_id:
branch_id=branch_id[0]
if department_id:
@ -80,7 +83,7 @@ class ReportHDCaseSummary(Model):
year=int(date[0:4])
date_from=obj.date_from
date_to=obj.date_to
report_type=obj.report_type or 'completed'
prev_year=year
next_year=year
prev_month=crr_month-1
@ -111,13 +114,17 @@ class ReportHDCaseSummary(Model):
dom=[]
dom.append(["date",">=",date_from])
dom.append(["date","<=",date_to])
dom.append(["state","in",["completed","waiting_payment","paid"]])
if report_type=='completed':
dom.append(["state","in",["waiting_payment","paid"]])
else:
dom.append(["state","not in",["waiting_payment","paid"]])
#dom.append(['patient_id.walkin','=','no'])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
crr_total=len(get_model("clinic.hd.case").search(dom))
print('---> dom ', dom)
items={}
items['topic%s'%count]={
'month': month_str,
@ -261,12 +268,15 @@ class ReportHDCaseSummary(Model):
line['unit']=unit
lines.append(line)
index+=1
if report_type=='not_completed':
lines[0]['topic']='%s (ไม่สำเร็จ)'%lines[0]['topic']
context['defaults']={
'date': date,
'date_from': date_from,
'date_to': date_to,
'branch_id': branch_id,
'department_id': department_id,
'report_type': report_type,
}
medicals=get_model("clinic.report.medical.summary").get_report_data(ids=[],context=context)
@ -279,6 +289,7 @@ class ReportHDCaseSummary(Model):
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
data={
'report_type': report_type,
'branch_id': branch_id,
'department_id': department_id,
'date_from': date_from,

View File

@ -234,10 +234,9 @@ class ReportLaborCost(Model):
['branch_id','=',brch_id],
['date','>=',date_from],
['date','<=',date_to],
['state','in',['waiting_payment','paid']],
]
dom2=dom1+[['doctor_id2.number','=','']]
dom3=dom1+[['doctor_id2.number','!=','']]
dom2=dom1+[['walkin','=',True]]
dom3=dom1+[['walkin','=',False]]
dlines.append({
'name': dt_name,
'qty': "{0:.2f}".format(round(qty,2)),
@ -267,14 +266,13 @@ class ReportLaborCost(Model):
dom4=[
['date','>=',date_from],
['date','<=',date_to],
['state','in',['waiting_payment','paid']],
['doctor_id2.number','!=',''],
['walkin','=',False],
]
if department_id:
dom4.append(['department_id','=',department_id])
if branch_id:
dom4.append(['branch_id','=',branch_id])
dom5=dom4+[['doctor_id2.number','=','']]
dom5=dom4+[['walkin','=',True]]
dlines.append({
'name': 'รวม',
'qty': 0,

View File

@ -0,0 +1,113 @@
import time
from calendar import monthrange
from netforce.model import Model,fields,get_model
class ReportLaborCostStaff(Model):
_name="clinic.report.labor.cost.staff"
_string="Report Labor Cost Staff"
_transient=True
_fields={
"date": fields.Date("Month"),
"date_from": fields.Date("From", required=True),
"date_to": fields.Date("To", required=True),
"branch_id": fields.Many2One("clinic.branch","Branch"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
"department_id": fields.Many2One("clinic.department","Department"),
'walkin': fields.Boolean("Walkin"),
}
def _get_date_from(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
#return '%s-%s-01'%(year,month)
return '%s-%s-%s'%(year,month,day)
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)
return "%s-%s-%s"%(year,month,day)
def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{})
date_from=defaults.get("date_from", self._get_date_from())
date_to=defaults.get("date_to", self._get_date_to())
walkin=defaults.get("walkin", False)
print('defaults ', defaults)
res={
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
'walkin': walkin,
}
return res
def get_report_data(self,ids,context={}):
defaults=self.default_get(context=context)
date_from=defaults['date_from']
date_to=defaults['date_to']
branch_id=defaults.get("branch_id")
department_id=defaults.get("department_id")
cycle_id=defaults.get("cycle_id")
walkin=defaults.get("walkin")
print('walkin ', walkin)
dom=[]
if ids:
obj=self.browse(ids)[0]
date_from=obj.date_from
date_to=obj.date_to
branch_id=obj.branch_id.id
department_id=obj.department_id.id
cycle_id=obj.cycle_id.id
walkin=obj.walkin
dom.append(['date','>=',date_from])
dom.append(['date','<=',date_to])
dom.append(['hd_case_id.state','in',['waiting_payment','paid']])
if branch_id:
dom.append(['hd_case_id.branch_id','=',branch_id])
if department_id:
dom.append(['hd_case_id.department_id','=',department_id])
if cycle_id:
dom.append(['hd_case_id.cycle_id','=',cycle_id])
lines=[]
for sline in get_model("clinic.hd.case.staff").search_browse(dom):
hdcase=sline.hd_case_id
staff=sline.staff_id
if walkin and staff:
continue
lines.append({
'id': sline.id,
'date': sline.date,
'number': hdcase.number or '',
'staff_name': staff.name or '',
'staff_id': staff.id or '',
'department_name': sline.department_id.name or '',
})
data={
'date_from': date_from,
'date_to': date_to,
'lines': 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_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
def onchange_from(self,context={}):
data=context['data']
data['date_to']=data['date_from']
return data
ReportLaborCostStaff.register()

View File

@ -18,6 +18,7 @@ class ReportMedicalDetail(Model):
'types': fields.Many2Many("clinic.patient.type","Types"),
"branch_id": fields.Many2One("clinic.branch","Branch"),
"department_id": fields.Many2One("clinic.department","Department"),
'report_type': fields.Selection([['completed','Completed'],['not_completed','Not Completed']],"Report Type"),
}
# in case link from another report
@ -29,8 +30,9 @@ class ReportMedicalDetail(Model):
date_from=defaults.get('date_from','%s-%s-01'%(year,month))
date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day))
categ_id=defaults.get('categ_id',None)
report_type=defaults.get('report_type',"completed")
if not categ_id:
categ_ids=get_model("product.categ").search([['code','=','EPO']])
categ_ids=get_model("product.categ").search([['code','=','MDC']])
if categ_ids:
categ_id=categ_ids[0]
branch_id=defaults.get('branch_id',None)
@ -54,7 +56,6 @@ class ReportMedicalDetail(Model):
product_id=defaults.get("product_id",None)
if product_id:
product_id=int(product_id)
print('xx ',product_id)
res={
'date': date,
'date_from': date_from,
@ -64,7 +65,9 @@ class ReportMedicalDetail(Model):
'department_id': department_id,
'types': types,
'product_id': product_id,
'report_type': report_type,
}
print('report_type ', report_type)
return res
def get_report_data(self,ids,context={}):
@ -78,6 +81,7 @@ class ReportMedicalDetail(Model):
department_id=defaults.get("department_id")
product_id=defaults.get('product_id')
types=defaults.get('types')
report_type=defaults.get('report_type','completed')
if ids:
obj=self.browse(ids)[0]
prod_categ_id=obj.prod_categ_id.id
@ -88,6 +92,7 @@ class ReportMedicalDetail(Model):
month=obj.date_from.split("-")[1]
time_start=obj.date_from
time_stop=obj.date_to
report_type=obj.report_type or 'completed'
dom=[
['hd_case_id.date','>=',time_start],
['hd_case_id.date','<=',time_stop],
@ -97,13 +102,17 @@ class ReportMedicalDetail(Model):
if department_id:
dom.append(['hd_case_id.department_id','=',department_id])
if prod_categ_id:
dom.append(['product_categ_id','=',prod_categ_id])
dom.append(['product_categ_id.id','child_of',prod_categ_id])
if product_id:
dom.append(['product_id','=',product_id])
if types and ids:
dom.append(['hd_case_id.patient_type_id','in',[t.id for t in types]])
elif types:
dom.append(['hd_case_id.patient_type_id','in',[t_id for t_id in types]])
if report_type=='completed':
dom.append(["hd_case_id.state","in",["waiting_payment","paid"]])
else:
dom.append(["hd_case_id.state","not in",["waiting_payment","paid"]])
lines=[]
total_qty=0
for line in get_model('clinic.hd.case.line').search_browse(dom):

View File

@ -17,6 +17,7 @@ class ReportMedicalSummary(Model):
"prod_categ_id": fields.Many2One("product.categ","Category"),
"branch_id": fields.Many2One("clinic.branch","Branch"),
"department_id": fields.Many2One("clinic.department","Department"),
'report_type': fields.Selection([['completed','Completed'],['not_completed','Not Completed']],"Report Type"),
}
# in case link from another report
@ -28,8 +29,9 @@ class ReportMedicalSummary(Model):
date_from=defaults.get('date_from','%s-%s-01'%(year,month))
date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day))
categ_id=defaults.get('categ_id',None)
report_type=defaults.get('report_type',"completed")
if not categ_id:
categ_ids=get_model("product.categ").search([['parent_id.code','=','MDC']])
categ_ids=get_model("product.categ").search([['code','=','MDC']])
if categ_ids:
categ_id=categ_ids[0]
branch_id=defaults.get('branch_id',None)
@ -54,6 +56,7 @@ class ReportMedicalSummary(Model):
'prod_categ_id': categ_id,
'branch_id': branch_id,
'department_id': department_id,
'report_type': report_type,
}
return res
@ -66,6 +69,7 @@ class ReportMedicalSummary(Model):
prod_categ_id=defaults.get("prod_categ_id")
branch_id=defaults.get("branch_id")
department_id=defaults.get("department_id")
report_type=defaults.get("report_type","completed")
if ids:
obj=self.browse(ids)[0]
prod_categ_id=obj.prod_categ_id.id
@ -74,17 +78,21 @@ class ReportMedicalSummary(Model):
month=obj.date_from.split("-")[1]
time_start=obj.date_from
time_stop=obj.date_to
report_type=obj.report_type or "completed"
print('report_type ---> ', report_type)
products={}
patient_types={t['id']: t['name'] for t in get_model('clinic.patient.type').search_read([[]],['name'],order="name")}
dom=[]
dom.append(['type','=','stock'])
if prod_categ_id:
dom.append(['categ_id','=',prod_categ_id])
print('dom ', dom)
dom.append(['categ_id.id','child_of',prod_categ_id])
categ_ids=set()
for prod in get_model("product").search_browse(dom):
prod_code=prod.code or ""
categ=prod.categ_id
if categ and categ.parent_id:
categ_ids.update({categ.id})
products[prod_code]={}
for patient_type_id,type_name in patient_types.items():
products[prod_code][patient_type_id]={
@ -101,17 +109,24 @@ class ReportMedicalSummary(Model):
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
if report_type=='completed':
dom.append(["state","in",["waiting_payment","paid"]])
else:
dom.append(["state","not in",["waiting_payment","paid"]])
for hd_case in get_model('clinic.hd.case').search_browse(dom):
patient_type_id=hd_case.patient_type_id.id
for line in hd_case.lines:
prod=line.product_id
prod_code=prod.code or ""
categ=line.product_categ_id
if not prod_code or not prod.active:
continue
if line.type=='fee' or prod.type=='service':
continue
if prod_categ_id and prod_categ_id != prod.categ_id.id:
if categ and categ.id not in list(categ_ids):
continue
#if line.type=='fee' or prod.type=='service':
#continue
#if prod_categ_id and prod_categ_id != prod.categ_id.id:
#continue
products[prod_code][patient_type_id]['qty']+=line.qty
lines=[]
@ -194,6 +209,7 @@ class ReportMedicalSummary(Model):
'lines': lines,
'month': month_str,
'year': year,
'report_type': report_type,
}
return data

View File

@ -166,9 +166,11 @@ class VisitBoard(Model):
hd_case_number=hd_case.number
hd_case_state=hd_case.state
if hd_case_state=='completed':
visit_color='#99ff99'
#visit_color='#99ff99'
visit_color=''
elif hd_case_state=='in_progress':
visit_color='#f9e37d'
#visit_color='#f9e37d'
visit_color=''
pass
number=visit.number
if number=='/':

View File

@ -122,7 +122,7 @@
<span>
<center>
<b>
<a href="/ui#name=clinic_report_medical_summary&defaults.date={{date}}&defaults.date_from={{date_from}}&defaults.date_to={{date_to}}&defaults.branch_id={{branch_id}}&defaults.department_id={{department_id}}">รวมจำนวนยาที่ใช้ประจำเดือน</a>
<a href="/ui#name=clinic_report_medical_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.report_type={{report_type}}">รวมจำนวนยาที่ใช้ประจำเดือน</a>
</b>
</center>
</span>
@ -140,7 +140,7 @@
</td>
{{#each sub_lines}}
<td style="text-align:center">
<a href="/ui#name=clinic_report_medical_detail&defaults.date_from={{time_start}}&defaults.date_to={{time_stop}}&defaults.types={{types}}&defaults.product_id={{product_id}}&defaults.product_categ_id={{product_categ_id}}">{{qty}} </a>
<a href="/ui#name=clinic_report_medical_detail&defaults.date_from={{time_start}}&defaults.date_to={{time_stop}}&defaults.types={{types}}&defaults.product_id={{product_id}}&defaults.product_categ_id={{product_categ_id}}&defaults.report_type={{../../report_type}}">{{qty}} </a>
</td>
{{/each}}
</tr>

View File

@ -72,7 +72,7 @@
<th style="text-align:left;width:10%">{{qty}}</th>
{{else}}
<td style="text-align:right">
{{view "link" string=qty action="clinic_hd_case" action_options=option_qty}}
{{view "link" string=qty action="clinic_report_labor_cost_staff" action_options=option_qty}}
</td>
{{/if}}
{{/each}}
@ -84,7 +84,7 @@
{{else}}
<td style="text-align:right">
{{#if walkin_qty}}
{{view "link" string=qty2 action="clinic_hd_case" action_options=option_qty2}}
{{view "link" string=qty2 action="clinic_report_labor_cost_staff" action_options=option_qty2}}
{{else}}
0.00
{{/if}}

View File

@ -0,0 +1,32 @@
<center>
</center>
<table class="table">
<thead class="scroll-header">
<tr>
<th>HDCase</th>
<th>Doctor</th>
<th>Department</th>
</tr>
</thead>
<tbody>
{{#each lines}}
<tr>
<td>
{{view "link" string=number action="clinic_hd_case_staff" action_options="mode=form" active_id=id}}
</td>
<td>
{{view "link" string=staff_name action="clinic_staff" action_options="mode=form" active_id=staff_id}}
</td>
<td>
{{department_name}}
</td>
</tr>
{{/each}}
</tbody>
<tfoot>
<th></th>
<th></th>
<th></th>
</tfoot>
</table>