report labor cost

conv_bal
watcha.h@almacom.co.th 2015-04-06 16:22:39 +07:00
parent d4b3598a99
commit d355abcda4
6 changed files with 63 additions and 21 deletions

View File

@ -295,7 +295,6 @@ class LaborCost(Model):
'categ_id': nurse.categ_id.id, 'categ_id': nurse.categ_id.id,
'rate': rate, 'rate': rate,
'type': 'nurse', 'type': 'nurse',
#'qty': qty,
'qty': 1, 'qty': 1,
})) }))
@ -303,10 +302,13 @@ class LaborCost(Model):
st=get_model('clinic.setting').browse(1) st=get_model('clinic.setting').browse(1)
cost_per_case=obj.cost_per_case or st.cost_per_case or 0 cost_per_case=obj.cost_per_case or st.cost_per_case or 0
staff_total={} staff_total={}
dwalkin=None
for staff in get_model("clinic.staff").search_browse([['number','=','walkin']]):
dwalkin=staff
for hd_case in item.hd_cases: for hd_case in item.hd_cases:
staffs=hd_case.staffs staffs=hd_case.staffs
for ps in staffs: for ps in staffs:
staff=ps.staff_id staff=ps.staff_id or dwalkin
if not staff: if not staff:
continue continue
base=staff.base base=staff.base
@ -317,7 +319,7 @@ class LaborCost(Model):
'base': 0, 'base': 0,
'type': staff.type, 'type': staff.type,
'categ_id': staff.categ_id.id, 'categ_id': staff.categ_id.id,
'level_id': staff.level_id.id, #XXX 'level_id': staff.level_id.id,
'qty': 0, 'qty': 0,
} }
if staff.type!='doctor': if staff.type!='doctor':

View File

@ -310,10 +310,6 @@ class ReportHDCaseSummary(Model):
data['department_id']=None data['department_id']=None
return data return data
def get_report_data2(self,context={}):
data={}
return data
def run_report(self,ids,context={}): def run_report(self,ids,context={}):
return { return {
'next': { 'next': {

View File

@ -44,8 +44,8 @@ class ReportLaborCost(Model):
defaults=self.default_get(context=context) defaults=self.default_get(context=context)
date_from=defaults['date_from'] date_from=defaults['date_from']
date_to=defaults['date_to'] date_to=defaults['date_to']
branch_id=None branch_id=defaults.get("branch_id")
department_id=None department_id=defaults.get("department_id")
dom=[] dom=[]
if ids: if ids:
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
@ -61,19 +61,44 @@ class ReportLaborCost(Model):
dom.append(['department_id','=',department_id]) dom.append(['department_id','=',department_id])
date=date_from date=date_from
hdcases={} hdcases={}
for hdcase in get_model("clinic.hd.case").search_browse(dom): hdcase_obj=get_model("clinic.hd.case")
dstates=dict(hdcase_obj._fields['state'].selection)
for hdcase in hdcase_obj.search_browse(dom):
dpt=hdcase.department_id dpt=hdcase.department_id
state=hdcase.state or ''
if dpt.id not in hdcases.keys(): if dpt.id not in hdcases.keys():
hdcases[dpt.id]={ hdcases[dpt.id]={
'name': dpt.name, 'name': dpt.name,
'department_id': dpt.id, 'department_id': dpt.id,
'branch_id': dpt.branch_id.id, 'branch_id': dpt.branch_id.id,
'qty':0, 'qty':0,
'state':{},
} }
hdcases[dpt.id]['qty']+=1 hdcases[dpt.id]['qty']+=1
if not hdcases[dpt.id]['state'].get(state):
hdcases[dpt.id]['state'][state]=0
hdcases[dpt.id]['state'][state]+=1
def replace_quote(dom=""):
dom=dom.replace("False","false")
dom=dom.replace("True","true")
return dom.replace("'","\"")
lines=[] lines=[]
dom=[]
dom.append(["date",">=",date_from])
dom.append(["date","<=",date_to])
total_hdcase=0 total_hdcase=0
for dpt_id, vals in hdcases.items(): for dpt_id, vals in hdcases.items():
sub_lines=[]
dom2=[['department_id','=',dpt_id]]
for state, sqty in vals['state'].items():
dom3=[['state','=',state]] # last domain
dom4=dom+dom2+dom3
state=dstates[state]
sub_lines.append({
'name': state,
'qty': sqty,
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%(dom4)),
})
qty=vals['qty'] or 0 qty=vals['qty'] or 0
total_hdcase+=qty total_hdcase+=qty
lines.append({ lines.append({
@ -81,6 +106,7 @@ class ReportLaborCost(Model):
'branch_id': vals['branch_id'], 'branch_id': vals['branch_id'],
'department_id': vals['department_id'], 'department_id': vals['department_id'],
'qty': qty, 'qty': qty,
'sub_lines': sub_lines,
}) })
sub_name='' sub_name=''
if department_id: if department_id:
@ -89,7 +115,6 @@ class ReportLaborCost(Model):
elif branch_id: elif branch_id:
branch=get_model("clinic.branch").browse(branch_id) branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or "" sub_name="(%s)" % branch.name or ""
print('>>>>>> :: ', date)
data={ data={
'company_name': '%s %s' % (company.name or "", sub_name), 'company_name': '%s %s' % (company.name or "", sub_name),
'date': date, 'date': date,

View File

@ -34,7 +34,6 @@ class ReportLaborCostSummary(Model):
def default_get(self,field_names=None,context={},**kw): def default_get(self,field_names=None,context={},**kw):
defaults=context.get("defaults",{}) defaults=context.get("defaults",{})
date=defaults.get("date", time.strftime("%Y-%m-%d")) date=defaults.get("date", time.strftime("%Y-%m-%d"))
print('date>>> ', date)
date_from=defaults.get("date_from", self._get_date_from()) date_from=defaults.get("date_from", self._get_date_from())
date_to=defaults.get("date_to", self._get_date_to()) date_to=defaults.get("date_to", self._get_date_to())
branch_id=defaults.get("branch_id") branch_id=defaults.get("branch_id")
@ -100,6 +99,7 @@ class ReportLaborCostSummary(Model):
citems={} citems={}
print('dom ', dom) print('dom ', dom)
total_hdcase=0 total_hdcase=0
states={}
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
citem=lcost.cycle_item_id citem=lcost.cycle_item_id
@ -145,8 +145,16 @@ class ReportLaborCostSummary(Model):
staffs[staff.name][dpt.name]['qty']+=qty staffs[staff.name][dpt.name]['qty']+=qty
if not citems.get(citem.id): if not citems.get(citem.id):
qty=len([hdcase for hdcase in citem.hd_cases if hdcase.state in ('completed', 'waiting_payment', 'paid')]) #qty=len([hdcase for hdcase in citem.hd_cases if hdcase.state in ('completed', 'waiting_payment', 'paid')])
qty=0
for hdcase in citem.hd_cases:
qty+=1
#if hdcase.state not in states.keys():
#states[hdcase.state]=0
#states[hdcase.state]+=1
citems[citem.id]=qty citems[citem.id]=qty
#for state,vals in states.items():
#print(state, vals)
lines=[] lines=[]
dom=[] dom=[]
if branch_id: if branch_id:

View File

@ -248,9 +248,6 @@ def date2thai(date, format='%(BY)s-%(m)s-%(d)s', lang='th_TH'):
, 'd': int(day) # XXX remove zero , 'd': int(day) # XXX remove zero
} }
def htmlcolor(r, g, b): def htmlcolor(r, g, b):
#ex: htmlcolor(250,0,0) => '#fa0000' #ex: htmlcolor(250,0,0) => '#fa0000'
def _chkarg(a): def _chkarg(a):

View File

@ -14,17 +14,31 @@
<tbody> <tbody>
{{#each lines }} {{#each lines }}
<tr> <tr>
<td> <th>
{{name}} {{name}}
</td> </th>
<th></th>
</tr>
{{#each sub_lines}}
<tr>
<td style="text-align:right">{{name}}</td>
<td style="text-align:right"> <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}}">{{currency qty}}</a> {{view "link" string=qty action="clinic_hd_case" action_options=action_options}}
</td> </td>
</tr> </tr>
{{/each}} {{/each}}
<tr>
<th style="text-align:right">
Subtotal
</th>
<th 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}}">{{currency qty}}</a>
</th>
</tr>
{{/each}}
</tbody> </tbody>
<tfoot> <tfoot>
<th>Total</th> <th>รวม</th>
<th style="text-align:right"> <th 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}}">{{currency total_hdcase}}</a> <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}}">{{currency total_hdcase}}</a>
</th> </th>