diff --git a/netforce_clinic/actions/clinic_report_receipt_summary.xml b/netforce_clinic/actions/clinic_report_receipt_summary.xml new file mode 100644 index 0000000..f86b8b0 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_receipt_summary.xml @@ -0,0 +1,9 @@ + + Receipt Summary + report + clinic.report.receipt.summary + report_receipt_summary + report_receipt_summary + 1 + clinic_menu + diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index f2c9765..875bc87 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -47,6 +47,8 @@ + + diff --git a/netforce_clinic/layouts/clinic_report_receipt_summary.xml b/netforce_clinic/layouts/clinic_report_receipt_summary.xml new file mode 100644 index 0000000..75af748 --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_receipt_summary.xml @@ -0,0 +1,7 @@ +
+ + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index 59538bf..49b3d66 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -146,3 +146,4 @@ from . import document from . import payment_matching from . import create_invoice_payment from . import report_stock_card +from . import report_receipt_summary diff --git a/netforce_clinic/models/report_account_hd_case_summary.py b/netforce_clinic/models/report_account_hd_case_summary.py index 58203bd..2878059 100644 --- a/netforce_clinic/models/report_account_hd_case_summary.py +++ b/netforce_clinic/models/report_account_hd_case_summary.py @@ -36,14 +36,12 @@ class ReportAccountHDCaseSummary(Model): reimbursable=defaults.get('reimbursable',"yes") branch_id=defaults.get('branch_id',None) - print('defaults ', defaults) if branch_id: branch_id=int(branch_id) department_id=defaults.get('department_id',None) if department_id: department_id=int(department_id) select_dpt=get_model('select.company').get_select() - print('select_dpt ', select_dpt) if select_dpt: if not branch_id: branch_id=select_dpt['branch_id'] diff --git a/netforce_clinic/models/report_receipt_summary.py b/netforce_clinic/models/report_receipt_summary.py new file mode 100644 index 0000000..f17198e --- /dev/null +++ b/netforce_clinic/models/report_receipt_summary.py @@ -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 ReportReceiptSummary(Model): + _name='clinic.report.receipt.summary' + _transient=True + + _fields={ + "date": fields.Date("Month", required=True), + "date_from": fields.Date("From", required=True), + "date_to": fields.Date("To", required=True), + 'branch_id': fields.Many2One("clinic.branch","Branch"), + 'department_id': fields.Many2One("clinic.department","Departments"), + } + + def default_get(self,field_names=None,context={},**kw): + defaults=context.get("defaults",{}) + date=defaults.get('date',time.strftime("%Y-%m-%d")) + year,month=time.strftime("%Y-%m").split("-") + weekday, total_day=monthrange(int(year), int(month)) + date_from=defaults.get('date_from','%s-%s-01'%(year,month)) + date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day)) + #date_from=defaults.get('date',date) + #date_to=defaults.get('date',date) + + ########### find branch + branch_id=defaults.get('branch_id',None) + if branch_id: + branch_id=int(branch_id) + department_id=defaults.get('department_id',None) + if department_id: + department_id=int(department_id) + select_dpt=get_model('select.company').get_select() + if select_dpt: + if not branch_id: + branch_id=select_dpt['branch_id'] + if not department_id: + if select_dpt.get('department_ids'): + department_id=select_dpt['department_ids'][0] + else: + department_id=select_dpt['department_id'] + res={ + 'date': date, + 'date_from': date_from, + 'date_to': date_to, + 'branch_id': branch_id, + 'department_id': department_id, + } + return res + + def get_report_data(self,ids,context={}): + company_id=get_active_company() + company=get_model("company").browse(company_id) + + ################ default values ############### + defaults=self.default_get(context=context) + date=defaults.get('date',time.strftime("%Y-%m-%d")) + year=int(date[0:4]) + crr_month=int(date[5:7]) + weekday, crr_total_day=monthrange(year, crr_month) + date_from=defaults.get('date_from',date) + date_to=defaults.get('date_to',date) + branch_id=defaults.get("branch_id",None) + department_id=defaults.get("department_id",None) + + ################# when click run report ############# + 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 + + #################### condition to get shop rd ######## + dom=[ + ['date', '>=', date_from], + ['date', '<=', date_to], + ] + if branch_id: + dom.append(['branch_id','=',branch_id]) + branch=get_model("clinic.branch").browse(branch_id) + if department_id: + dom.append(['department_id','=',department_id]) + department=get_model("clinic.department").browse(department_id) + + lines=[] + total_amount=0 + ############### from HD Case ################### + for hdcase in get_model('clinic.hd.case').search_browse(dom): + patient=hdcase.patient_id + line_vals={ + 'patient_name': patient.name, + 'patient_id': patient.id, + 'is_rd_shop': False, + 'id': hdcase.id, + } + for payment in hdcase.payments: + items=[] + for line in payment.lines: + items.append(line.description) + list_item='\n'.join([item for item in items if item]) + line_vals.update({ + 'payment_id': payment.id, + 'date': payment.date, + 'number': payment.number, + 'ref': payment.ref, + 'list_item': list_item, + 'amount_total': payment.amount_total, + 'date_send': '', # ?? + }) + total_amount+=payment.amount_total + lines.append(line_vals) + + ############### from RD Shop ################### + for shop in get_model('clinic.shop').search_browse(dom): + patient=shop.patient_id + items=[] + for line in shop.lines: + prod=line.product_id + if prod: + items.append(prod.name) + else: + items.append(line.description) + list_item='\n'.join([item for item in items if item]) + line_vals={ + 'is_rd_shop': True, + 'patient_name': patient.name, + 'patient_id': patient.id, + 'date': shop.date, + 'number': shop.number, + 'id': shop.id, + 'ref': shop.ref, + 'list_item': list_item, + 'amount_total': shop.sub_total, + 'date_send': '', # ?? + } + total_amount+=shop.sub_total + lines.append(line_vals) + + data={ + 'title': 'Receipt Summary', + 'date_from': date_from, + 'date_to': date_to, + 'parent_company_name': company.parent_id and company.parent_id.name or "", + 'company_name': company.name, + 'branch_name': branch.name, + 'department_name': department.name, + 'lines': sorted(lines, key=lambda line: line['date']), + 'total_amount': total_amount, + } + return data + + def onchange_branch(self,context={}): + data=context['data'] + data['department_id']=None + 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_datefrom(self,context={}): + data=context['data'] + data['date_to']=data['date_from'] + return data + +ReportReceiptSummary.register() diff --git a/netforce_clinic/reports/report_receipt_summary.xlsx b/netforce_clinic/reports/report_receipt_summary.xlsx new file mode 100644 index 0000000..d0f2ef1 Binary files /dev/null and b/netforce_clinic/reports/report_receipt_summary.xlsx differ diff --git a/netforce_clinic/templates/report_receipt_summary.hbs b/netforce_clinic/templates/report_receipt_summary.hbs new file mode 100644 index 0000000..d6365f3 --- /dev/null +++ b/netforce_clinic/templates/report_receipt_summary.hbs @@ -0,0 +1,60 @@ +
+

+ {{title}} +

+

+ {{parent_company_name}} {{company_name}}
+

+

+ From {{date_from}} To {{date_to}} +

+
+ + + + + + + + + + + + + + {{#each lines}} + + + + + + + + + + + {{/each}} + + + + + + + +
วันที่ใบเสร็จผู้ป่วยเลขที่ใบเสร็จอ้างอิง #รายการจำนวนเงินวันที่นำฝาก
{{date}}{{patient_name}} + {{#if is_rd_shop}} + {{view "link" string=number action="clinic_shop" action_options="mode=form" active_id=id}} + {{else}} + {{view "link" string=number action="clinic_hd_case" action_options="mode=form" active_id=id}} + {{/if}} + + {{#if is_rd_shop}} + + {{else}} + + {{/if}} + {{ref}}{{list_item}}{{currency amount_total}}{{date_send}}
ทั้งหมด{{currency total_amount}}