Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last payment date in accounts #530

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crm/modules/payment/payment.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,32 @@ function payment_accounts_table ($opts) {
array('title' => 'Name')
, array('title' => 'Email')
, array('title' => 'Balance Owed')
, array('title' => 'Last payment')
)
, 'rows' => array()
);
$contacts = crm_get_data('contact', array('cid'=>$cids));
$cidToContact = crm_map($contacts, 'cid');
$total_amount_owed=0;
foreach ($balances as $cid => $balance) {
$last_payment = get_last_payment($cid);
$total_amount_owed += $balance['value']/100;
$row = array();
$row[] = theme('contact_name', $cid, !$export);
$row[] = $cidToContact[$cid]['email'];
$row[] = payment_format_currency($balance);
$row[] = "${last_payment['date']} (${last_payment['months']} months ago)";
$table['rows'][] = $row;
}
$table['rows'][] = array(
'Total',
'',
payment_format_currency(array(
'value' => $total_amount_owed,
'code' => variable_get('currency_code'),
)),
''
);
return $table;
}

Expand Down Expand Up @@ -1309,3 +1323,17 @@ function command_payment_filter () {
}
return crm_url('payments') . $query;
}

function get_last_payment($cid) {
global $db_connect;
$sql = "
SELECT `date`, `value`/100 AS amount, TIMESTAMPDIFF(MONTH, `date`, now()) AS months
FROM payment
WHERE `credit` = $cid AND `value` > 0
ORDER BY `date` DESC LIMIT 1
";
$res = mysqli_query($db_connect, $sql);
if (!$res) crm_error(mysqli_error($db_connect));
$db_row = mysqli_fetch_assoc($res);
return $db_row;
}