diff --git a/netforce_clinic/layouts/clinic_payment_matching.xml b/netforce_clinic/layouts/clinic_payment_matching.xml
index 1025d34..95746e3 100644
--- a/netforce_clinic/layouts/clinic_payment_matching.xml
+++ b/netforce_clinic/layouts/clinic_payment_matching.xml
@@ -10,9 +10,12 @@
-
-
-
-
+
+
+
+
+
+
+
diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py
index 49c8213..ca468b4 100644
--- a/netforce_clinic/models/account_invoice.py
+++ b/netforce_clinic/models/account_invoice.py
@@ -4,10 +4,22 @@ from netforce.model import Model, fields, get_model
class AccountInvoice(Model):
_inherit="account.invoice"
+
+ def _get_patient(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ pt_id=None
+ if obj.patient_partner_id:
+ for pt in get_model('clinic.patient').search_browse([['partner_id','=',obj.patient_partner_id.id]]):
+ pt_id=pt.id
+ res[obj.id]=pt_id
+ return res
+
_fields={
'clinic_expense_id': fields.Many2One("clinic.hd.case.expense","Expense"),
'department_id': fields.Many2One("clinic.department","Department",search=True),
- 'patient_partner_id': fields.Many2One("partner","Patient",search=True),
+ 'patient_partner_id': fields.Many2One("partner","Partner Patient",search=True),
+ 'patient_id': fields.Many2One("clinic.patient","Patient",function="_get_patient", store=True,search=True),
}
def _get_number(self,context={}):
@@ -280,4 +292,5 @@ class AccountInvoice(Model):
t1=time.time()
dt=(t1-t0)*1000
print("invoice.post <<< %d ms"%dt)
+
AccountInvoice.register()
diff --git a/netforce_clinic/models/payment_matching.py b/netforce_clinic/models/payment_matching.py
index 9da2c2f..2cef393 100644
--- a/netforce_clinic/models/payment_matching.py
+++ b/netforce_clinic/models/payment_matching.py
@@ -22,7 +22,7 @@ class PaymentMatching(Model):
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
"inv_state": fields.Selection([("draft","Draft"),("waiting_approval","Waiting Approval"),("waiting_payment","Waiting Payment"),("paid","Paid"),("voided","Voided")],"Status"),
- "view_type": fields.Selection([("invoice","Invoice"),("file","File")],"View Type"),
+ "view_type": fields.Selection([("invoice","Invoice"),("matching","Matching")],"View Type"),
'patient_type_id': fields.Many2One("clinic.patient.type","Patient Type",required=True),
'pcode': fields.Char("Code",required=True),
'hcode_id': fields.Many2One("clinic.hospital","HCode"),
@@ -129,27 +129,106 @@ class PaymentMatching(Model):
inv_state=obj.inv_state
view_type=obj.view_type
lines=[]
- dom=[
- ['date','>=',date_from],
- ['date','<=',date_to],
- ['state','=',inv_state],
- ]
- if branch_id and not department_id:
- dom.append(['department_id.branch_id','=',branch_id])
- elif department_id:
- dom.append(['department_id','=',department_id])
- if view_type=='invoice':
- field_names=['date','number','amount_due']
+ invoices=[]
+ total_match_invoice=0
+ total_epo=0
+ total_srv=0
+ total_fee=0
+ total_amount=0
+ def get_invoices():
+ invoices=[]
+ dom=[
+ ['date','>=',date_from],
+ ['date','<=',date_to],
+ ['state','=',inv_state],
+ ]
+ if branch_id and not department_id:
+ dom.append(['department_id.branch_id','=',branch_id])
+ elif department_id:
+ dom.append(['department_id','=',department_id])
+ field_names=['date','number','amount_due','patient_id']
for inv in get_model('account.invoice').search_read(dom,field_names):
- vals={}
+ vals={
+ 'id': inv['id'],
+ 'patient_id': None,
+ 'patient_name': '',
+ 'patient_hn': '',
+ }
for field_name in field_names:
- vals[field_name]=inv[field_name],
- lines.append(vals)
+ if field_name=='patient_id' and inv['patient_id']:
+ patient=get_model('clinic.patient').browse(inv['patient_id'][0])
+ vals['patient_id']=patient.id
+ vals['patient_name']=patient.name
+ vals['patient_nospace_name']=patient.name_check
+ vals['patient_cid']=patient.card_no
+ vals['patient_hn']=patient.hn
+ else:
+ vals[field_name]=inv[field_name]
+ vals[field_name]=inv[field_name]
+ invoices.append(vals)
+ return invoices
+ if view_type=='invoice':
+ lines=get_invoices()
+ else:
+ if obj:
+ invoices=get_invoices()
+ rlines=obj.get_line()
+ no=1
+ for rline in rlines:
+ date_treatment=rline.get("dttran")
+ date=date_treatment[0:10]
+ time=date_treatment[11:]
+ if not time:
+ continue
+ epo=rline.get('epoadm29') or 0
+ fee=rline.get('amount23') or 0
+ srv=rline.get('allow37') or 0
+ name=rline.get("name14")
+ name_nospace=name.replace(" ","")
+ pid=rline.get('pid')
+ hn=rline.get('hn')
+ hn=''.join([x for x in hn if x.isdigit()])
+ total_fee+=fee
+ total_epo+=epo
+ total_srv+=srv
+ amount=fee+epo+srv
+ total_amount+=amount
+ line_vals={
+ 'no': no,
+ 'date':date,
+ 'patient_name': name,
+ 'pid': pid,
+ 'hn': hn,
+ 'fee': fee,
+ 'srv': srv,
+ 'epo': epo,
+ 'amount': amount,
+ }
+ for item_amt in ['fee','srv','epo']:
+ for inv in invoices:
+ if inv['patient_id']:
+ # check card no first then HN finally patient name
+ if pid==inv['patient_cid'] or hn==inv['patient_hn'] or name_nospace==inv['patient_nospace_name']:
+ inv_amt=inv['amount_due']
+ inv_date=inv['date']
+ if inv_date==date and inv_amt==line_vals[item_amt]:
+ line_vals['inv_%s'%(item_amt)]=inv['number']
+ line_vals['inv_%s_id'%(item_amt)]=inv['id']
+ total_match_invoice+=1
+ break
+ lines.append(line_vals)
+ no+=1
data={
'lines': lines,
'date_from': date_from,
'date_to': date_to,
- 'total_inv': len(lines),
+ 'total_qty': len(lines),
+ 'total_fee': total_fee,
+ 'total_epo': total_epo,
+ 'total_srv': total_srv,
+ 'total_match_invoice': total_match_invoice,
+ 'total_invoice': len(invoices),
+ 'total_amount': total_amount,
'view_type': view_type,
}
return data
diff --git a/netforce_clinic/templates/payment_matching.hbs b/netforce_clinic/templates/payment_matching.hbs
index 83a2bfb..bb16f31 100644
--- a/netforce_clinic/templates/payment_matching.hbs
+++ b/netforce_clinic/templates/payment_matching.hbs
@@ -1,21 +1,20 @@
-
-
-
-
-
-
- TOTAL: {{currency total_inv}}
-
-
+
+
+
+ Total Invoice |
+ Match |
+
+
+
+ {{currency total_invoice}} |
+ {{currency total_match_invoice}} |
+
+
+