.id
3522
.gutitle
account
.title
account
.file
.extension
.name
|/routinetype-utility|
.user_id
7
.notes
.body
<ensure variable="att.function" value="get">
<var _function_list = "ensure,count,get,get_user_balance,credit,debit,create,paypal_reconcile"> <if listFindNoCase(_function_list,att.function) EQ 0><p>/routine-account : invalid function '<b>#att.function#</b>'</p><BREAK></if>


<var o = "account">


<var _account_select = reReplace('
#o#.id,
#o#.so_dateinserted,
#o#.so_lastupdated,
#o#.userid_unsignedint,
#o#.title, ("My Account")
#o#.total_double (value of account)
',"([[:space:]]|\([^\)]*\))","","all")>


<var _account_where = "#o#.user_id = 7">



<if att.function EQ "count">
<ensure variable="att.whereclause" value="#o#.id > 1">
<var _ret = 0>
<set orb="#o#" select="count(#o#.id) AS idcount" where="#_account_where# AND (#att.whereclause#)" maxrows="1"
is_proxy="1">
<setcrawl><var _ret = set.idcount></setcrawl>
</set>
<return _ret>
</if>



<if att.function EQ "get">
<ensure variable="att.select" value="#_account_select#">
<ensure variable="att.whereclause" value="#o#.id > 1">
<ensure variable="att.orderby" value="">
<ensure variable="att.groupby" value="">
<ensure variable="att.maxrows" value="100">
<var _ret = QueryNew('id')>
<set orb="#o#" select="#att.select#" where="#_account_where# AND (#att.whereclause#)"
is_proxy="1"
orderby="#att.orderby#"
groupby="#att.groupby#"
maxrows="#att.maxrows#">
<var _ret = set>
</set>
<return _ret>
</if>
<if att.function EQ "get_user_balance">
<return 0>
<var _ret = 0>
<ensure variable="att.userid_unsignedint" value="0">
<tag.account function="get" whereclause="account.userid_unsignedint = #att.userid_unsignedint#"
maxrows="1">
<var Q = return>
<loop query="Q">
<var _ret = _ret + Q.total_double>
</loop>
<return _ret>
</if>



<if att.function EQ "credit" OR att.function EQ "debit">
<ensure variable="att.sum_double" value="0">
<if att.function EQ "credit" AND att.sum_double LT 0>
<p>/routine-account : you may only credit accounts with zero or positive sums.</p>
<BREAK>
<elseif att.function EQ "debit" AND att.sum_double GTE 0>
<p>/routine-account : you may only debit accounts with negative sums.</p>
<BREAK>
</if>
<var _sum_double = att.sum_double * 100>
<var _sum_double = round(_sum_double)>
<var _sum_double = _sum_double / 100>
<ensure variable="att.account_id" value="0">
<ensure variable="att.userid_unsignedint" value="0">
<if att.account_id GT 0>
<var _w = "account.id = #att.account_id#">
<elseif att.userid_unsignedint GT 0>
<var _w = "account.userid_unsignedint = #att.userid_unsignedint#">
<else>
<p>/routine-account : invalid userid_unsignedint '<b>#att.userid_unsignedint#</b>'</p>
<BREAK>
</if>
<var _account_id = 0>
<var _account_total = 0>
<set orb="#o#" select="#o#.id,#o#.total_double" where="#_account_where# AND (#_w#)" maxrows="1"
orderby="#o#.so_dateinserted ASC"
is_proxy="1">
<setcrawl><var _account_id = set.id><var _account_total = set.total_double></setcrawl>
</set>
<if _account_id EQ 0>
<p>/routine-account : account not found</p>
<BREAK>
</if>
<update orb="#o#" where="#o#.id = #_account_id#"
total_double="#_account_total+_sum_double#" is_proxy="1">
<return return>
</if>



<if att.function EQ "create">

<ensure variable="att.userid_unsignedint" value="#client_id#">
<insert orb="#o#"
title="#att.title#"
total_double="0"
userid_unsignedint="#att.userid_unsignedint#"
is_proxy="1"
user_key_id="0">
<return return>

</if>



<if att.function EQ "ensure">
<return 0>
<ensure variable="att.userid_unsignedint" value="#client_id#">
<ensure variable="att.user_name" value="#client_name#">
<tag.account function="count" whereclause="account.userid_unsignedint = #att.userid_unsignedint#">
<var _num_accts = return>
<if _num_accts EQ 0>
<!--- user should have one account --->
<tag.account function="create"
title="#att.user_name# - #dateFormat(now(),'mm/dd/yyyy')#">
<elseif _num_accts GT 1>
<!--- but not more than one --->
<tag.account function="get" whereclause="account.userid_unsignedint = #att.userid_unsignedint#" orderby="account.so_dateinserted ASC">
<var Q = return>
<var _first_id = 0>
<var _first_total = 0>
<var _delete_ids = "0">
<var _makeup_amt = 0>
<loop query="Q">
<if Q.currentrow EQ 1>
<var _first_id = Q.id>
<var _first_total = Q.total_double>
<else>
<var _delete_ids = _delete_ids & "," & Q.id>
<var _makeup_amt = _makeup_amt + Q.total_double>
</if>
</loop>
<!--- magically (that is, without recording a transaction) adjust remaining account for money found/lost in other accounts --->
<if _makeup_amt NEQ 0>
<update orb="#o#" where="#o#.id = #_first_id#"
total_double="#_first_total+_makeup_amt#" is_proxy="1">
</if>
<!--- delete the ones that need to be deleted --->
<delete orb="#o#" where="#o#.id IN (#_delete_ids#)" is_proxy="1">
</if>
<return 1>
</if>



<if att.function EQ "paypal_reconcile">
<return 1>
<ensure variable="att.account_id" value="0">
<ensure variable="att.userid_unsignedint" value="0">
<if att.account_id GT 0>
<var _whereclause = "#o#.id = #att.account_id#">
<elseif att.userid_unsignedint GT 0>
<var _whereclause = "#o#.userid_unsignedint = #att.userid_unsignedint#">
<else>
<p>/routine-account : att.account_id was not passed to paypal_reconcile function</p>
<return 0>
<BREAK>
</if>
<tag.account function="get" whereclause="#_whereclause#" maxrows="1">
<var Ac = return>
<if NOT isQuery(Ac) AND Ac.recordcount EQ 1>
<p>/routine-account : no account found for paypal_reconcile function</p>
<return 0>
<BREAK>
</if>
<var _o = "otransaction">
<var dt = dateAdd("y",-1,now())>
<set orb="#_o#"
select="#_o#.id,#_o#.clientid_unsignedint,#_o#.so_dateinserted,#_o#.payer_email,#_o#.item_name,#_o#.item_number,#_o#.business,#_o#.invoice,#_o#.sum_double"
where="( #_o#.invoice LIKE('|iqtpi_cash_in|#Ac.id#|%') OR #_o#.invoice LIKE('|cash_in|#Ac.id#|%') ) AND #_o#.clientid_unsignedint = #Ac.userid_unsignedint# AND #_o#.business IN ('steve@fentriss.com','info@sevenorbs.com') AND #_o#.user_id = 7"
is_proxy="1"
show_error="1">
<var Pp = set>
</set>
<if NOT isQuery(Pp)>
<p>/routine-account : no set returned during otransaction query</p>
<return 0>
<BREAK>
</if>
<tag.txn whereclause="txn.userid_unsignedint = #client_id# AND txn.type IN('cash_in','iqtpi_cash_in')">
<var Txn = return>
<var _account_invoice_list = "">
<loop query="Txn">
<var _account_invoice_list = _account_invoice_list & "," & Txn.invoice>
</loop>
<loop query="Pp">
<if listFind(_account_invoice_list,Pp.invoice) EQ 0>
<!--- an otransaction record of a paypal cash_in exists where an
account cash_in does not. Record the account cash_in. --->
<tag.txn function="record"
type="cash_in"
title="Cash In"
notes="Cash in via PayPal (#Pp.payer_email#)"
invoice="#Pp.invoice#"
userid_unsignedint="#Pp.clientid_unsignedint#"
party_unsignedint="0"
sum_double="#Pp.sum_double#">
</if>
</loop>
</if>
 
.sum_double
0.00
.producttype
.productincludes
.physical_unsignedint
0
.isprotected_unsignedint
0
.overridesiteheader_unsignedint
0