diff --git a/netforce_clinic/models/labor_cost.py b/netforce_clinic/models/labor_cost.py index 61a8f69..8606871 100644 --- a/netforce_clinic/models/labor_cost.py +++ b/netforce_clinic/models/labor_cost.py @@ -142,7 +142,7 @@ class LaborCost(Model): nurse=line.nurse_id level=line.level_id or nurse.level_id if not level: - raise Exception("Please specify level for %s"%nurse.name) + raise Exception("Please specify level %s for %s"%(nurse.name,item.name)) levels[level.id]['total']+=1 st_levels={} diff --git a/netforce_clinic/models/report_labor_cost.py b/netforce_clinic/models/report_labor_cost.py index 2cf78f4..40dccc6 100644 --- a/netforce_clinic/models/report_labor_cost.py +++ b/netforce_clinic/models/report_labor_cost.py @@ -216,8 +216,7 @@ class ReportLaborCost(Model): for categ_name,vals in ctdata.items(): amount=vals['amount'] or 0 categ_id=vals['categ_id'] - total_amount+=amount - ctlines.append({ + ct_vals={ 'name': categ_name, 'amount': round(amount,0), 'branch_id': branch_id, @@ -225,7 +224,9 @@ class ReportLaborCost(Model): 'department_id': department_id, 'staff_type': 'nurse', 'cycle_id': cycle_id, - }) + } + total_amount+=ct_vals['amount'] + ctlines.append(ct_vals) ctlines.append({ 'name': 'รวม', 'amount': round(total_amount,0), @@ -354,16 +355,28 @@ class ReportLaborCost(Model): nlines[-1]['cost']+=nline['cost'] or 0 nlines[-1]['total']+=nline['total'] or 0 - def conv2line(keys=[],lines=[]): + def con2float(r): + if type(r)==type(''): + return r + return "{0:,.2f}".format(r) + + def v2h(keys=[],lines=[]): lines2=[] for key in keys: no=0 - vals={} + vals={'desc': False} + if key=='name': + vals['desc']=True for line in lines: - vals[no]=line[key] + vals[no]=con2float(line[key]) no+=1 lines2.append(vals) return lines2 + + def reformat(lines=[]): + for line in lines: + line['amount']=con2float(line['amount']) + return lines data={ 'company_name': '%s %s' % (company.name or "", sub_name), @@ -372,25 +385,17 @@ class ReportLaborCost(Model): 'date_to': date_to, 'lines': lines, 'dlines': dlines, - 'dlines2': conv2line(['name','qty','qty2','total_qty','cost'],dlines), + 'dlines2': v2h(['name','qty','qty2','total_qty','cost'],dlines), 'nlines': nlines, - 'nlines2': [], + 'nlines2': v2h(['name','qty','cost'],nlines), 'ctlines': ctlines, + 'ctlines2': reformat(ctlines), 'total_hdcase': total_hdcase, 'branch_id': branch_id, 'department_id': department_id, 'show_detail': show_detail, 'report_type': report_type, } - - for key in ('name', 'qty', 'cost'): - no=0 - vals={} - for nline in data['nlines']: - vals[no]=nline[key] - no+=1 - data['nlines2'].append(vals) - return data def onchange_date(self,context={}): diff --git a/netforce_clinic/models/report_labor_cost_summary.py b/netforce_clinic/models/report_labor_cost_summary.py index 79343b5..c3d2cad 100644 --- a/netforce_clinic/models/report_labor_cost_summary.py +++ b/netforce_clinic/models/report_labor_cost_summary.py @@ -115,9 +115,14 @@ class ReportLaborCostSummary(Model): dom.append(['labor_cost_id.cycle_item_id.cycle_id','=',cycle_id]) staffs={} citems={} + + def int2ths(r): + if type(r)==type(''): + return r + return "{0:,.0f}".format(r) + print('--> dom: ', dom) total_hdcase=0 - for line in get_model("clinic.labor.cost.line").search_browse(dom): lcost=line.labor_cost_id citem=lcost.cycle_item_id @@ -263,6 +268,7 @@ class ReportLaborCostSummary(Model): line['no']=no nlines.append(line) no+=1 + data={ 'title': title, 'date_from': date_from, @@ -272,12 +278,41 @@ class ReportLaborCostSummary(Model): 'comp_span': len(dpts), 'lines': nlines, 'total_lines': total_lines, - 'total_hdcase': total_hdcase or 0, + 'total_hdcase': int2ths(total_hdcase) or 0, 'total_cost': round(total_cost,0) or 0, 'staff_type': staff_type, 'branch_id': branch_id, 'department_id': department_id, - } + 'dpts_txt': [{0: '#', 1: 'รหัส', 2: 'ชื่อ-สกุล',}], + } + items=[] + vals={} + no=0 + dpt_len=len(data['dpts_txt'][0]) + for dpt in dpts: + data['dpts_txt'][0][no+dpt_len]=dpt['name'] + vals[no]=0 + no+=1 + count=1 + for i in range(len(data['lines'])): + line=data['lines'][i] + item_vals=vals.copy() + item_vals['no']=count + item_vals['number']=line['number'] + item_vals['staff_name']=line['staff_name'] + no=0 + for sub_line in line['sub_lines']: + item_vals['item%s'%no]=sub_line['amt'] + no+=1 + item_vals['total']=line['total'] + items.append(item_vals) + count+=1 + data['items']=items + data['total_lines_txt']=[{}] + no=0 + for tline in data['total_lines']: + data['total_lines_txt'][0]['item%s'%no]=tline['amt'] + no+=1 return data def onchange_date(self,context={}): diff --git a/netforce_clinic/reports/report_labor_cost.xlsx b/netforce_clinic/reports/report_labor_cost.xlsx index 4f8f604..7afae3d 100644 Binary files a/netforce_clinic/reports/report_labor_cost.xlsx and b/netforce_clinic/reports/report_labor_cost.xlsx differ diff --git a/netforce_clinic/reports/report_labor_cost_summary.xlsx b/netforce_clinic/reports/report_labor_cost_summary.xlsx index 238b52a..1d4e986 100644 Binary files a/netforce_clinic/reports/report_labor_cost_summary.xlsx and b/netforce_clinic/reports/report_labor_cost_summary.xlsx differ diff --git a/netforce_clinic/templates/report_labor_cost.hbs b/netforce_clinic/templates/report_labor_cost.hbs index 00b5437..49d8c1a 100644 --- a/netforce_clinic/templates/report_labor_cost.hbs +++ b/netforce_clinic/templates/report_labor_cost.hbs @@ -157,7 +157,7 @@