Commit c2364888 authored by Monish Deb's avatar Monish Deb

CSV export fatal error fix

parent 306ef748
...@@ -82,14 +82,13 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat ...@@ -82,14 +82,13 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat
ft.trxn_id AS trxn_id, ft.trxn_id AS trxn_id,
cov.label AS payment_instrument, cov.label AS payment_instrument,
ft.check_number, ft.check_number,
CASE c.source AS source,
WHEN eftc.entity_table = 'civicrm_contribution' c.id AS contribution_id,
THEN c.source c.contact_id AS contact_id,
ELSE cgp.label eb.batch_id AS batch_id,
END AS source,
ft.currency AS currency, ft.currency AS currency,
cov_status.label AS status, cov_status.label AS status,
CASE CASE
WHEN efti.entity_id IS NOT NULL WHEN efti.entity_id IS NOT NULL
THEN efti.amount THEN efti.amount
ELSE eftc.amount ELSE eftc.amount
...@@ -109,7 +108,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat ...@@ -109,7 +108,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat
LEFT JOIN civicrm_option_value cov ON (cov.value = ft.payment_instrument_id AND cov.option_group_id = cog.id) LEFT JOIN civicrm_option_value cov ON (cov.value = ft.payment_instrument_id AND cov.option_group_id = cog.id)
LEFT JOIN civicrm_entity_financial_trxn eftc ON (eftc.financial_trxn_id = ft.id AND (eftc.entity_table = 'civicrm_contribution' OR eftc.entity_table = 'civicrm_grant')) LEFT JOIN civicrm_entity_financial_trxn eftc ON (eftc.financial_trxn_id = ft.id AND (eftc.entity_table = 'civicrm_contribution' OR eftc.entity_table = 'civicrm_grant'))
LEFT JOIN civicrm_contribution c ON c.id = eftc.entity_id AND eftc.entity_table = 'civicrm_contribution' LEFT JOIN civicrm_contribution c ON c.id = eftc.entity_id AND eftc.entity_table = 'civicrm_contribution'
LEFT JOIN civicrm_grant ccg ON ccg.id = eftc.entity_id AND eftc.entity_table = 'civicrm_grant' LEFT JOIN civicrm_grant ccg ON ccg.id = eftc.entity_id AND eftc.entity_table = 'civicrm_grant'
LEFT JOIN civicrm_grant_program cgp ON cgp.id = ccg.grant_program_id LEFT JOIN civicrm_grant_program cgp ON cgp.id = ccg.grant_program_id
LEFT JOIN civicrm_option_group cog_status ON cog_status.name = 'contribution_status' LEFT JOIN civicrm_option_group cog_status ON cog_status.name = 'contribution_status'
...@@ -150,7 +149,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat ...@@ -150,7 +149,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat
*/ */
function formatHeaders($values) { function formatHeaders($values) {
$arrayKeys = array_keys($values); $arrayKeys = array_keys($values);
$headers = ''; $headers = [];
if (!empty($arrayKeys)) { if (!empty($arrayKeys)) {
foreach ($values[$arrayKeys[0]] as $title => $value) { foreach ($values[$arrayKeys[0]] as $title => $value) {
$headers[] = $title; $headers[] = $title;
...@@ -170,7 +169,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat ...@@ -170,7 +169,7 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat
$financialItems = array(); $financialItems = array();
$this->_batchIds = $batchId; $this->_batchIds = $batchId;
while ($dao->fetch()) { while ($dao->fetch()) {
$creditAccountName = $creditAccountType = $creditAccountName = $creditAccountType =
$creditAccount = NULL; $creditAccount = NULL;
if ($dao->credit_account) { if ($dao->credit_account) {
$creditAccountName = $dao->credit_account_name; $creditAccountName = $dao->credit_account_name;
...@@ -180,9 +179,9 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat ...@@ -180,9 +179,9 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat
else { else {
$creditAccountName = $dao->from_credit_account_name; $creditAccountName = $dao->from_credit_account_name;
$creditAccountType = $dao->from_credit_account_type_code; $creditAccountType = $dao->from_credit_account_type_code;
$creditAccount = $dao->from_credit_account; $creditAccount = $dao->from_credit_account;
} }
$financialItems[] = array( $financialItems[] = array(
'Transaction Date' => $dao->trxn_date, 'Transaction Date' => $dao->trxn_date,
'Debit Account' => $dao->to_account_code, 'Debit Account' => $dao->to_account_code,
...@@ -220,4 +219,71 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat ...@@ -220,4 +219,71 @@ class CRM_Financial_BAO_ExportFormat_CSV extends CRM_Financial_BAO_ExportFormat
function exportTRANS() { function exportTRANS() {
} }
}
\ No newline at end of file /**
* Generate CSV array for export.
*
* @param array $export
*/
public function makeExport($export) {
// getting data from admin page
$prefixValue = Civi::settings()->get('contribution_invoice_settings');
foreach ($export as $batchId => $dao) {
$financialItems = array();
$this->_batchIds = $batchId;
$queryResults = array();
while ($dao->fetch()) {
$creditAccountName = $creditAccountType = $creditAccount = NULL;
if ($dao->credit_account) {
$creditAccountName = $dao->credit_account_name;
$creditAccountType = $dao->credit_account_type_code;
$creditAccount = $dao->credit_account;
}
else {
$creditAccountName = $dao->from_credit_account_name;
$creditAccountType = $dao->from_credit_account_type_code;
$creditAccount = $dao->from_credit_account;
}
$invoiceNo = CRM_Utils_Array::value('invoice_prefix', $prefixValue) . "" . $dao->contribution_id;
$financialItems[] = array(
'Batch ID' => $dao->batch_id,
'Invoice No' => $invoiceNo,
'Contact ID' => $dao->contact_id,
'Financial Trxn ID/Internal ID' => $dao->financial_trxn_id,
'Transaction Date' => $dao->trxn_date,
'Debit Account' => $dao->to_account_code,
'Debit Account Name' => $dao->to_account_name,
'Debit Account Type' => $dao->to_account_type_code,
'Debit Account Amount (Unsplit)' => $dao->debit_total_amount,
'Transaction ID (Unsplit)' => $dao->trxn_id,
'Debit amount (Split)' => $dao->amount,
'Payment Instrument' => $dao->payment_instrument,
'Check Number' => $dao->check_number,
'Source' => $dao->source,
'Currency' => $dao->currency,
'Transaction Status' => $dao->status,
'Amount' => $dao->amount,
'Credit Account' => $creditAccount,
'Credit Account Name' => $creditAccountName,
'Credit Account Type' => $creditAccountType,
'Item Description' => $dao->item_description,
);
end($financialItems);
$queryResults[] = get_object_vars($dao);
}
CRM_Utils_Hook::batchItems($queryResults, $financialItems);
$financialItems['headers'] = self::formatHeaders($financialItems);
self::export($financialItems);
}
parent::initiateDownload();
}
}
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title> <title></title>
</head> </head>
{foreach from=$grantPayment key=key item=data}
<body > <body >
{foreach from=$grantPayment key=key item=data}
<!-- Stub 1 --> <!-- Stub 1 -->
<div style="height:300px; font-size: 11px;"> <div style="font-size: 11px;">
<div style="float:right; text-align:right;">{$data.payment_id}</div> <div style="float:right; text-align:right;">{$data.payment_id}</div>
<table width="100%" cellpadding=0 cellspacing=0 style="font-size: 11px;"> <table width="100%" cellpadding=0 cellspacing=0 style="font-size: 11px;">
<tr><td width="100%" colspan="4">RE: {$data.payment_reason}</td></tr> <tr><td width="100%" colspan="4">RE: {$data.payment_reason}</td></tr>
...@@ -16,13 +15,13 @@ ...@@ -16,13 +15,13 @@
<td width="15%">Grant ID</td><td width="50%">Payee</td> <td width="15%">Grant ID</td><td width="50%">Payee</td>
<td width="20%">Amount</td> <td width="20%">Amount</td>
</tr> </tr>
<tr><td width="15%">{$data.payment_details}</td> </tr> <tr><td width="15%">{$data.payment_details}</td> </tr>
<tr> <tr>
<td width="15%"></td><td width="15%"></td><td width="50%" style="text-align:right;">Total Amount&nbsp;&nbsp;&nbsp;&nbsp;</td><td width="15%">{$data.amount|crmMoney:$data.currency}</td> <td width="15%"></td><td width="15%"></td><td width="50%" style="text-align:right;">Total Amount&nbsp;&nbsp;&nbsp;&nbsp;</td><td width="15%">{$data.amount|crmMoney:$data.currency}</td>
</tr> </tr>
</table> </table>
</div> </div>
<!-- Cheque portion --> <!-- Cheque portion -->
<div style="height:100px" > <div style="height:100px" >
<table width="100%" cellpadding=0 cellspacing=0> <table width="100%" cellpadding=0 cellspacing=0>
...@@ -41,13 +40,13 @@ ...@@ -41,13 +40,13 @@
<table width="100%" cellpadding=0 cellspacing=0> <table width="100%" cellpadding=0 cellspacing=0>
<tr> <tr>
<td width="100%">{$data.payable_to_name}</td> <td width="100%">{$data.payable_to_name}</td>
</tr> </tr>
<tr> <tr>
<td width="100%">{$data.payable_to_address}</td> <td width="100%">{$data.payable_to_address}</td>
</tr> </tr>
</table> </table>
</div> </div>
<!-- Stub 2 --> <!-- Stub 2 -->
<div style="page-break-after: always; font-size: 10px;" > <div style="page-break-after: always; font-size: 10px;" >
<div style="float:right; text-align:right;"> {$data.payment_id} </div> <div style="float:right; text-align:right;"> {$data.payment_id} </div>
...@@ -56,14 +55,14 @@ ...@@ -56,14 +55,14 @@
<tr><td width="15%">Payment Date</td><td width="15%">Grant ID</td><td width="50%">Payee</td> <tr><td width="15%">Payment Date</td><td width="15%">Grant ID</td><td width="50%">Payee</td>
<td width="20%">Amount</td></tr> <td width="20%">Amount</td></tr>
<tr><td width="15%">{$data.payment_details}</td> <tr><td width="15%">{$data.payment_details}</td>
</tr> </tr>
<tr> <tr>
<td width="15%"></td><td width="15%"></td> <td width="15%"></td><td width="15%"></td>
<td width="50%" style="text-align:right; ">Total Amount&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="50%" style="text-align:right; ">Total Amount&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td width="20%">{$data.amount|crmMoney:$data.currency}</td> <td width="20%">{$data.amount|crmMoney:$data.currency}</td>
</tr> </tr>
</table> </table>
</div> </div>
{/foreach}
</body> </body>
{/foreach} </html>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment