report labor cost
							parent
							
								
									b4724e98b8
								
							
						
					
					
						commit
						b88bf1b337
					
				| 
						 | 
					@ -73,7 +73,6 @@ class ReportLaborCost(Model):
 | 
				
			||||||
        hdcases={}
 | 
					        hdcases={}
 | 
				
			||||||
        hdcase_obj=get_model("clinic.hd.case")
 | 
					        hdcase_obj=get_model("clinic.hd.case")
 | 
				
			||||||
        dstates=dict(hdcase_obj._fields['state'].selection)
 | 
					        dstates=dict(hdcase_obj._fields['state'].selection)
 | 
				
			||||||
        print('dom ', dom)
 | 
					 | 
				
			||||||
        for hdcase in hdcase_obj.search_browse(dom):
 | 
					        for hdcase in hdcase_obj.search_browse(dom):
 | 
				
			||||||
            dpt=hdcase.department_id
 | 
					            dpt=hdcase.department_id
 | 
				
			||||||
            state=hdcase.state or ''
 | 
					            state=hdcase.state or ''
 | 
				
			||||||
| 
						 | 
					@ -95,6 +94,9 @@ class ReportLaborCost(Model):
 | 
				
			||||||
            dom=dom.replace("False","false")
 | 
					            dom=dom.replace("False","false")
 | 
				
			||||||
            dom=dom.replace("True","true")
 | 
					            dom=dom.replace("True","true")
 | 
				
			||||||
            return dom.replace("'","\"")
 | 
					            return dom.replace("'","\"")
 | 
				
			||||||
 | 
					        st=get_model('clinic.setting').browse(1)
 | 
				
			||||||
 | 
					        vark=st.var_k or 0
 | 
				
			||||||
 | 
					        cost_per_case=st.cost_per_case or 0
 | 
				
			||||||
        lines=[] 
 | 
					        lines=[] 
 | 
				
			||||||
        dom=[]
 | 
					        dom=[]
 | 
				
			||||||
        dom.append(["date",">=",date_from])
 | 
					        dom.append(["date",">=",date_from])
 | 
				
			||||||
| 
						 | 
					@ -136,6 +138,7 @@ class ReportLaborCost(Model):
 | 
				
			||||||
            total_hdcase+=qty
 | 
					            total_hdcase+=qty
 | 
				
			||||||
        dlines=[]
 | 
					        dlines=[]
 | 
				
			||||||
        nlines=[]
 | 
					        nlines=[]
 | 
				
			||||||
 | 
					        ctlines=[]
 | 
				
			||||||
        if report_type=='cross':
 | 
					        if report_type=='cross':
 | 
				
			||||||
            dom=[
 | 
					            dom=[
 | 
				
			||||||
                ['date','>=',date_from],
 | 
					                ['date','>=',date_from],
 | 
				
			||||||
| 
						 | 
					@ -144,8 +147,10 @@ class ReportLaborCost(Model):
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
            ddata={}
 | 
					            ddata={}
 | 
				
			||||||
            ndata={}
 | 
					            ndata={}
 | 
				
			||||||
            for line in get_model('clinic.labor.cost.line').search_browse(dom):
 | 
					            ctdata={}
 | 
				
			||||||
 | 
					            for line in get_model('clinic.labor.cost.line').search_browse(dom,order="department_id.name"):
 | 
				
			||||||
                cost_id=line.labor_cost_id
 | 
					                cost_id=line.labor_cost_id
 | 
				
			||||||
 | 
					                categ_name=line.categ_id.name or ""
 | 
				
			||||||
                citem=cost_id.cycle_item_id
 | 
					                citem=cost_id.cycle_item_id
 | 
				
			||||||
                department=citem.department_id
 | 
					                department=citem.department_id
 | 
				
			||||||
                dpt_name=department.name or ''
 | 
					                dpt_name=department.name or ''
 | 
				
			||||||
| 
						 | 
					@ -155,28 +160,81 @@ class ReportLaborCost(Model):
 | 
				
			||||||
                        ddata[dpt_name]=0
 | 
					                        ddata[dpt_name]=0
 | 
				
			||||||
                    ddata[dpt_name]+=qty
 | 
					                    ddata[dpt_name]+=qty
 | 
				
			||||||
                elif line.type=='nurse':
 | 
					                elif line.type=='nurse':
 | 
				
			||||||
 | 
					                    if categ_name not in ctdata.keys():
 | 
				
			||||||
 | 
					                        ctdata[categ_name]=0
 | 
				
			||||||
 | 
					                    ctdata[categ_name]+=line.pay_amount or 0
 | 
				
			||||||
                    if dpt_name not in ndata.keys():
 | 
					                    if dpt_name not in ndata.keys():
 | 
				
			||||||
                        ndata[dpt_name]=set()
 | 
					                        ndata[dpt_name]=set()
 | 
				
			||||||
                    for hdcase in citem.hd_cases:
 | 
					                    for hdcase in citem.hd_cases:
 | 
				
			||||||
                        ndata[dpt_name].update({hdcase.id})
 | 
					                        ndata[dpt_name].update({hdcase.id})
 | 
				
			||||||
 | 
					            total_amount=0
 | 
				
			||||||
 | 
					            for categ_name,amount in ctdata.items():
 | 
				
			||||||
 | 
					                total_amount+=amount
 | 
				
			||||||
 | 
					                ctlines.append({
 | 
				
			||||||
 | 
					                    'name': categ_name,
 | 
				
			||||||
 | 
					                    'amount': amount,
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					            ctlines.append({
 | 
				
			||||||
 | 
					                'name': 'รวม',
 | 
				
			||||||
 | 
					                'amount': total_amount,
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
            dlines.append({
 | 
					            dlines.append({
 | 
				
			||||||
                'name': 'แพทย์',
 | 
					                'name': 'แพทย์',
 | 
				
			||||||
                'qty': 'จำนวนครั้ง',
 | 
					                'qty': 'จำนวนครั้ง',
 | 
				
			||||||
 | 
					                'qty2': 'ไม่จ่ายแพทย์',
 | 
				
			||||||
 | 
					                'total_qty': 'รวมจำนวนครั้ง',
 | 
				
			||||||
 | 
					                'cost': 'เป็นยอดเงินรวม',
 | 
				
			||||||
 | 
					                'desc': True,
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            for dt_name,qty in ddata.items():
 | 
					            for dt_name,qty in ddata.items():
 | 
				
			||||||
 | 
					                walkin=0
 | 
				
			||||||
 | 
					                cost=(walkin+qty)*cost_per_case
 | 
				
			||||||
                dlines.append({
 | 
					                dlines.append({
 | 
				
			||||||
                    'name': dt_name,
 | 
					                    'name': dt_name,
 | 
				
			||||||
                    'qty': qty,
 | 
					                    'qty': qty,
 | 
				
			||||||
 | 
					                    'qty2': walkin,
 | 
				
			||||||
 | 
					                    'total_qty': walkin+qty,
 | 
				
			||||||
 | 
					                    'cost': cost,
 | 
				
			||||||
 | 
					                    'total': 0,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
 | 
					            dlines.append({
 | 
				
			||||||
 | 
					                'name': 'รวม',
 | 
				
			||||||
 | 
					                'qty': 0,
 | 
				
			||||||
 | 
					                'qty2': 0,
 | 
				
			||||||
 | 
					                'total_qty':0,
 | 
				
			||||||
 | 
					                'cost': 0,
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            for dline in dlines[1:-1]:
 | 
				
			||||||
 | 
					                dlines[-1]['qty']+=dline['qty'] or 0
 | 
				
			||||||
 | 
					                dlines[-1]['qty2']+=dline['qty2'] or 0
 | 
				
			||||||
 | 
					                dlines[-1]['total_qty']+=dline['total_qty'] or 0
 | 
				
			||||||
 | 
					                dlines[-1]['cost']+=dline['cost'] or 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            nlines.append({
 | 
					            nlines.append({
 | 
				
			||||||
                'name': 'พยาบาล',
 | 
					                'name': 'พยาบาล',
 | 
				
			||||||
                'qty': 'จำนวนครั้ง',
 | 
					                'qty': 'จำนวนครั้ง',
 | 
				
			||||||
 | 
					                'cost': 'เป็นยอดเงินรวม',
 | 
				
			||||||
 | 
					                'total': 'รวม',
 | 
				
			||||||
 | 
					                'desc': True,
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
            for dt_name, hdcases in ndata.items():
 | 
					            for dt_name, hdcases in ndata.items():
 | 
				
			||||||
 | 
					                total_hdcase=len(hdcases)
 | 
				
			||||||
                nlines.append({
 | 
					                nlines.append({
 | 
				
			||||||
                    'name': dt_name,
 | 
					                    'name': dt_name,
 | 
				
			||||||
                    'qty': len(hdcases)
 | 
					                    'qty': total_hdcase,
 | 
				
			||||||
 | 
					                    'cost': total_hdcase*vark,
 | 
				
			||||||
 | 
					                    'total': 0,
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
 | 
					            nlines.append({
 | 
				
			||||||
 | 
					                'name': 'รวม',
 | 
				
			||||||
 | 
					                'qty': 0,
 | 
				
			||||||
 | 
					                'cost': 0,
 | 
				
			||||||
 | 
					                'total': 0,
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					            for nline in nlines[1:-1]:
 | 
				
			||||||
 | 
					                nlines[-1]['qty']+=nline['qty'] or 0
 | 
				
			||||||
 | 
					                nlines[-1]['cost']+=nline['cost'] or 0
 | 
				
			||||||
 | 
					                nlines[-1]['total']+=nline['total'] or 0
 | 
				
			||||||
        data={
 | 
					        data={
 | 
				
			||||||
            'company_name': '%s %s' % (company.name or "", sub_name),
 | 
					            'company_name': '%s %s' % (company.name or "", sub_name),
 | 
				
			||||||
            'date': date,
 | 
					            'date': date,
 | 
				
			||||||
| 
						 | 
					@ -185,13 +243,12 @@ class ReportLaborCost(Model):
 | 
				
			||||||
            'lines': lines,
 | 
					            'lines': lines,
 | 
				
			||||||
            'dlines': dlines,
 | 
					            'dlines': dlines,
 | 
				
			||||||
            'nlines': nlines,
 | 
					            'nlines': nlines,
 | 
				
			||||||
 | 
					            'ctlines': ctlines,
 | 
				
			||||||
            'total_hdcase': total_hdcase,
 | 
					            'total_hdcase': total_hdcase,
 | 
				
			||||||
            'branch_id': branch_id,
 | 
					            'branch_id': branch_id,
 | 
				
			||||||
            'department_id': department_id,
 | 
					            'department_id': department_id,
 | 
				
			||||||
            'show_detail': show_detail,
 | 
					            'show_detail': show_detail,
 | 
				
			||||||
            'report_type': report_type,
 | 
					            'report_type': report_type,
 | 
				
			||||||
            #'ddata': ddata,
 | 
					 | 
				
			||||||
            #'ndata': ndata,
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return data
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,6 @@
 | 
				
			||||||
<center>
 | 
					<center>
 | 
				
			||||||
    <h3>
 | 
					 | 
				
			||||||
        {{company_name}}
 | 
					 | 
				
			||||||
    </h3>
 | 
					 | 
				
			||||||
    <h4>
 | 
					    <h4>
 | 
				
			||||||
        From {{date_from}} To {{date_to}}
 | 
					        จาก {{date_from}} ถึง {{date_to}}
 | 
				
			||||||
    </h4>
 | 
					    </h4>
 | 
				
			||||||
</center>
 | 
					</center>
 | 
				
			||||||
{{#ifeq report_type "detail"}}
 | 
					{{#ifeq report_type "detail"}}
 | 
				
			||||||
| 
						 | 
					@ -64,12 +61,47 @@
 | 
				
			||||||
        <tbody style="text-align:center">
 | 
					        <tbody style="text-align:center">
 | 
				
			||||||
            <tr>
 | 
					            <tr>
 | 
				
			||||||
                {{#each dlines }}
 | 
					                {{#each dlines }}
 | 
				
			||||||
                    <th style="text-align:center;width:10%">{{name}}</th>
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th style="text-align:left;width:10%">{{name}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <th style="text-align:center;width:10%">{{name}}</th>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
                {{/each}}
 | 
					                {{/each}}
 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
            <tr>
 | 
					            <tr>
 | 
				
			||||||
                {{#each dlines }}
 | 
					                {{#each dlines }}
 | 
				
			||||||
                    <td>{{qty}}</td>
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th style="text-align:left;width:10%">{{qty}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="text-align:right">{{currency qty}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
 | 
					                {{/each}}
 | 
				
			||||||
 | 
					            </tr>
 | 
				
			||||||
 | 
					            <tr>
 | 
				
			||||||
 | 
					                {{#each dlines }}
 | 
				
			||||||
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th style="text-align:left;width:10%">{{qty2}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="text-align:right">{{currency qty2}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
 | 
					                {{/each}}
 | 
				
			||||||
 | 
					            </tr>
 | 
				
			||||||
 | 
					            <tr>
 | 
				
			||||||
 | 
					                {{#each dlines }}
 | 
				
			||||||
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th style="text-align:left;width:10%">{{total_qty}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="text-align:right">{{currency total_qty}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
 | 
					                {{/each}}
 | 
				
			||||||
 | 
					            </tr>
 | 
				
			||||||
 | 
					            <tr>
 | 
				
			||||||
 | 
					                {{#each dlines }}
 | 
				
			||||||
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th style="text-align:left;width:10%">{{cost}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="text-align:right">{{currency cost}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
                {{/each}}
 | 
					                {{/each}}
 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
        </tbody>
 | 
					        </tbody>
 | 
				
			||||||
| 
						 | 
					@ -78,14 +110,41 @@
 | 
				
			||||||
        <tbody style="text-align:center">
 | 
					        <tbody style="text-align:center">
 | 
				
			||||||
            <tr>
 | 
					            <tr>
 | 
				
			||||||
                {{#each nlines }}
 | 
					                {{#each nlines }}
 | 
				
			||||||
                    <th style="text-align:center;width:10%">{{name}}</th>
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th style="text-align:left;width:10%">{{name}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <th style="text-align:center;width:10%">{{name}}</th>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
                {{/each}}
 | 
					                {{/each}}
 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
            <tr>
 | 
					            <tr>
 | 
				
			||||||
                {{#each nlines }}
 | 
					                {{#each nlines }}
 | 
				
			||||||
                    <td>{{qty}}</td>
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th>{{qty}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="text-align:right">{{currency qty}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
 | 
					                {{/each}}
 | 
				
			||||||
 | 
					            </tr>
 | 
				
			||||||
 | 
					            <tr>
 | 
				
			||||||
 | 
					                {{#each nlines }}
 | 
				
			||||||
 | 
					                    {{#if desc}}
 | 
				
			||||||
 | 
					                        <th>{{cost}}</th>
 | 
				
			||||||
 | 
					                    {{else}}
 | 
				
			||||||
 | 
					                        <td style="text-align:right">{{currency cost}}</td>
 | 
				
			||||||
 | 
					                    {{/if}}
 | 
				
			||||||
                {{/each}}
 | 
					                {{/each}}
 | 
				
			||||||
            </tr>
 | 
					            </tr>
 | 
				
			||||||
        </tbody>
 | 
					        </tbody>
 | 
				
			||||||
    </table>
 | 
					    </table>
 | 
				
			||||||
 | 
					    <table class="table table-bordered">
 | 
				
			||||||
 | 
					        <tbody style="text-align:center">
 | 
				
			||||||
 | 
					            {{#each ctlines }}
 | 
				
			||||||
 | 
					                <tr>
 | 
				
			||||||
 | 
					                    <th style="text-align:left;width:14%">{{name}}</th>
 | 
				
			||||||
 | 
					                    <td style="text-align:right">{{currency amount}}</td>
 | 
				
			||||||
 | 
					                </tr>
 | 
				
			||||||
 | 
					            {{/each}}
 | 
				
			||||||
 | 
					        </tbody>
 | 
				
			||||||
 | 
					    </table>
 | 
				
			||||||
{{/ifeq}}
 | 
					{{/ifeq}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue