matching payment

fix_acc
watcha.h 2015-08-26 16:13:27 +07:00
parent 7afa9d7840
commit 2e99a673eb
7 changed files with 76 additions and 23 deletions

View File

@ -5,7 +5,6 @@
<item string="Account Patient" action="clinic_setting_account_patient"/>
<item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>
<item string="RD Shop Expense" action="clinic_report_account_shop"/>
<item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
<item string="Payment Matching" action="clinic_matching_payment"/>
<item string="Payment Invoices" action="clinic_invoice_payment"/>
<divider/>
@ -20,6 +19,7 @@
</item>
<item string="Matching">
<item string="Payment Matching" action="clinic_payment_matching"/>
<item string="HD Cases Matching" action="clinic_matching_hdcase_acc"/>
</item>
</item>
<item string="Financial Settings" position="after">

View File

@ -40,6 +40,7 @@
<list>
<field name="hdcase_date"/>
<field name="use_time"/>
<field name="nurse_id"/>
</list>
<form>
<field name="hd_case_id"/>

View File

@ -29,7 +29,7 @@ class Dialyzer(Model):
"visit_id": fields.Many2One("clinic.visit","Visit",search=True),
"hd_case_id": fields.Many2One("clinic.hd.case","HD Case",search=True),
"hd_cases": fields.One2Many("clinic.hd.case","dlz_id","HD Case"), #TODO funtion to get hd case
"hd_cases_dlz": fields.One2Many("clinic.hd.case.dialyzer","dialyzer_id","Dialyzer History"),
"hd_cases_dlz": fields.One2Many("clinic.hd.case.dialyzer","dialyzer_id","Dialyzer History",domain=[['hd_case_id.state','in','waiting_payment','paid']]),
'department_id': fields.Many2One("clinic.department","Department",search=True),
"membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"),
}

View File

@ -895,8 +895,13 @@ class HDCase(Model):
# TODO pop to note
obj.write({"state":"cancelled"})
#FIXME should use history to get the last time time and it should drop automatical
def update_usetime(self,ids,context={}):
datenow=time.strftime("%Y-%m-%d")
for obj in self.browse(ids):
# in case to draft
if obj.date < datenow:
continue
is_decrease=context.get('is_decrease')
for dlz_line in obj.dialyzers:
dlz=dlz_line.dialyzer_id
@ -1050,6 +1055,7 @@ class HDCase(Model):
def undo(self,ids,context={}):
obj=self.browse(ids)[0]
context['is_decrease']=True
# in case to draft
obj.update_usetime(context=context)
for line in obj.lines:
line.write({

View File

@ -6,9 +6,11 @@ class HDCaseDialyzerLine(Model):
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
hdcase_date=obj.hd_case_id.date
hdcase=obj.hd_case_id
res[obj.id]={
'hdcase_date': hdcase_date,
'hdcase_date': hdcase.date,
'hdcase_state': hdcase.state,
'nurse_id': hdcase.nurse_id.id,
}
return res
@ -21,6 +23,8 @@ class HDCaseDialyzerLine(Model):
"max_use_time":fields.Integer("Max use time"),
"membrane_type": fields.Selection([("unsub","Unsub cellul"),("sub","Sub cellul"),("synthetic","Synthetic")],"Membrane Type"),
'hdcase_date': fields.Date('Date', function="_get_all",function_multi=True),
"hdcase_state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),("completed","Finish Treatment"),('paid','Paid'),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",required=True,function="_get_all",function_multi=True),
'nurse_id': fields.Many2One('clinic.staff', 'Nurse',function="_get_all",function_multi=True),
}
_order="hd_case_id.date desc"

View File

@ -11,7 +11,6 @@ class PaymentMatching(Model):
_string="Payment Matching"
_transient=True
_fields={
'name': fields.Char("Name"),
"date": fields.Date("Month"),
@ -26,6 +25,7 @@ class PaymentMatching(Model):
'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"),
'inv_ids': fields.Text("Invoice ids"),
}
def _get_date_from(self,context={}):
@ -49,18 +49,25 @@ class PaymentMatching(Model):
date_from=line.date_start
date_to=line.date_stop
break
tids=get_model('clinic.patient.type').search([['default','=',True]])
patient_type_id=None
if tids:
patient_type_id=tids[0]
pcode='SSO'
for ptype in get_model('clinic.patient.type').search_read([['default','=',True]],['code']):
pcode=ptype['code']
patient_type_id=ptype['id']
hdcode_id=None
for hid in get_model("clinic.hospital").search([]):
hdcode_id=hid
break
res={
'period_id': period_id,
'date': time.strftime("%Y-%m-%d"),
'date_from': date_from,
'date_to': date_to,
'inv_state': 'waiting_payment',
#'inv_state': 'waiting_payment',
'view_type': 'invoice',
'patient_type_id': patient_type_id,
'pcode': pcode,
'hcode_id': hdcode_id,
}
return res
@ -121,6 +128,7 @@ class PaymentMatching(Model):
inv_state=defaults.get('inv_state')
view_type=defaults.get('view_type')
pcode=''
obj=None
if ids:
obj=self.browse(ids)[0]
date_from=obj.date_from
@ -143,13 +151,15 @@ class PaymentMatching(Model):
dom=[
['date','>=',date_from],
['date','<=',date_to],
['state','=',inv_state],
]
if inv_state:
dom.append(['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']
print('dom ', dom)
field_names=['date','number','amount_total','amount_due','patient_id','state']
for inv in get_model('account.invoice').search_read(dom,field_names):
vals={
'id': inv['id'],
@ -170,6 +180,7 @@ class PaymentMatching(Model):
vals[field_name]=inv[field_name]
invoices.append(vals)
return invoices
inv_match_ids=[]
if view_type=='invoice':
lines=get_invoices()
total_invoice=len(lines)
@ -214,12 +225,16 @@ class PaymentMatching(Model):
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_amt=inv['amount_due']
inv_amt=inv['amount_total']
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
line_vals['inv_%s_state'%(item_amt)]=inv['state']
if inv['state']=='waiting_payment':
inv_match_ids.append(inv['id'])
total_match_invoice+=1
break
lines.append(line_vals)
no+=1
@ -267,6 +282,7 @@ class PaymentMatching(Model):
'epo': 0,
'inv_id': None,
'inv_number': '',
'inv_state': '',
'no': no,
}
for inv in invoices:
@ -275,13 +291,20 @@ class PaymentMatching(Model):
if date==inv['date'] and fee==inv['amount_due']:
vals['inv_id']=inv['id']
vals['inv_number']=inv['number']
total_match_invoice+=1
vals['inv_state']=inv['state']
if inv['state']=='waiting_payment':
inv_match_ids.append(inv['id'])
total_match_invoice+=1
break
lines.append(vals)
no+=1
pc=0
if total_invoice:
pc=(total_match_invoice/total_invoice)*100
if inv_match_ids and obj:
obj.write({
'inv_ids': str(inv_match_ids),
})
data={
'lines': lines,
'date_from': date_from,
@ -292,7 +315,8 @@ class PaymentMatching(Model):
'total_srv': total_srv,
'total_invoice': total_invoice,
'total_match_invoice': total_match_invoice,
'total_match_invoice_in_pc': pc,
'pc_match': pc,
'pc_unmatch': 100-pc,
'total_unmatch_invoice': total_invoice-total_match_invoice,
'total_amount': total_amount,
'view_type': view_type,

View File

@ -1,17 +1,31 @@
<div class="row" style="margin-top:10px;">
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" style="width:{{currency pc_match}}%">
{{currency pc_match}}% Match (success)
</div>
<div class="progress-bar progress-bar-danger" role="progressbar" style="width:{{currency pc_unmatch}}%">
{{currency pc_unmatch}}% Un Match (fail)
</div>
</div>
</div>
<div class="row">
<table class="table table-bordered">
<thead>
<th style="text-align:center">Total Item</th>
<th style="text-align:center">Total Invoice</th>
<th style="text-align:center">Match</th>
<th style="text-align:center">Un Match</th>
<th style="text-align:center;width:25%">Total Item Waiting To Matching</th>
<th style="text-align:center;width:25%">Total Invoice</th>
<th style="text-align:center;width:25%">Match</th>
<th style="text-align:center;width:25%">Un Match</th>
</thead>
<tbody>
<tr>
<td style="text-align:center">{{currency total_item}}</td>
<td style="text-align:center">{{currency total_invoice}}</td>
<td style="text-align:center">{{currency total_match_invoice}}</td>
<td style="text-align:center">{{currency total_unmatch_invoice}}</td>
<td style="text-align:center">
{{currency total_match_invoice}}
</td>
<td style="text-align:center">
{{currency total_unmatch_invoice}}
</td>
</tr>
</tbody>
</table>
@ -65,7 +79,11 @@
<td>
<a style="text-decoration:None" href="ui#form_view_xml=cust_invoice_form&active_id={{inv_fee_id}}&name=cust_invoice&mode=form" target="_blank">
{{#if inv_fee_id}}
<span class="label label-info">
{{#ifeq inv_fee_state "paid"}}
<span class="label label-success">
{{else}}
<span class="label label-info">
{{/ifeq}}
{{inv_fee}}
</span>
{{/if}}