/**
  * Get action links.
  *
  * @return array
  */
 public function &links()
 {
     if (!self::$_links) {
         self::$_links = array('view' => array('name' => ts('View'), 'url' => 'civicrm/contact/view/contribution', 'qs' => 'reset=1&id=%%contid%%&cid=%%cid%%&action=view&context=contribution&selectedChild=contribute', 'title' => ts('View Contribution')), 'assign' => array('name' => ts('Assign'), 'ref' => 'disable-action', 'title' => ts('Assign Transaction'), 'extra' => 'onclick = "assignRemove( %%id%%,\'' . 'assign' . '\' );"'));
     }
     return self::$_links;
 }
示例#2
0
 /**
  * Get output of financial transactions.
  *
  * @param bool $return
  *   Return result. This parameter allows the output to be unit tested.
  *
  * @return string
  */
 public static function getFinancialTransactionsList($return = FALSE)
 {
     $sortMapper = array(0 => '', 1 => '', 2 => 'sort_name', 3 => 'amount', 4 => 'trxn_id', 5 => 'transaction_date', 6 => 'payment_method', 7 => 'status', 8 => 'name');
     $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
     $return = isset($_REQUEST['return']) ? CRM_Utils_Type::escape($_REQUEST['return'], 'Boolean') : FALSE;
     $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
     $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
     $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
     $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
     $context = isset($_REQUEST['context']) ? CRM_Utils_Type::escape($_REQUEST['context'], 'String') : NULL;
     $entityID = isset($_REQUEST['entityID']) ? CRM_Utils_Type::escape($_REQUEST['entityID'], 'String') : NULL;
     $notPresent = isset($_REQUEST['notPresent']) ? CRM_Utils_Type::escape($_REQUEST['notPresent'], 'String') : NULL;
     $statusID = isset($_REQUEST['statusID']) ? CRM_Utils_Type::escape($_REQUEST['statusID'], 'String') : NULL;
     $search = isset($_REQUEST['search']) ? TRUE : FALSE;
     $params = $_POST;
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $returnvalues = array('civicrm_financial_trxn.payment_instrument_id as payment_method', 'civicrm_contribution.contact_id as contact_id', 'civicrm_contribution.id as contributionID', 'contact_a.sort_name', 'civicrm_financial_trxn.total_amount as amount', 'civicrm_financial_trxn.trxn_id as trxn_id', 'contact_a.contact_type', 'contact_a.contact_sub_type', 'civicrm_financial_trxn.trxn_date as transaction_date', 'name', 'civicrm_contribution.currency as currency', 'civicrm_financial_trxn.status_id as status', 'civicrm_financial_trxn.check_number as check_number');
     $columnHeader = array('contact_type' => '', 'sort_name' => ts('Contact Name'), 'amount' => ts('Amount'), 'trxn_id' => ts('Trxn ID'), 'transaction_date' => ts('Received'), 'payment_method' => ts('Payment Method'), 'status' => ts('Status'), 'name' => ts('Type'));
     if ($sort && $sortOrder) {
         $params['sortBy'] = $sort . ' ' . $sortOrder;
     }
     $params['page'] = $offset / $rowCount + 1;
     $params['rp'] = $rowCount;
     $params['context'] = $context;
     $params['offset'] = ($params['page'] - 1) * $params['rp'];
     $params['rowCount'] = $params['rp'];
     $params['sort'] = CRM_Utils_Array::value('sortBy', $params);
     $params['total'] = 0;
     // get batch list
     if (isset($notPresent)) {
         $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params);
         if ($search) {
             $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, $params, TRUE);
         } else {
             $unassignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, $notPresent, NULL, TRUE);
         }
         while ($unassignedTransactions->fetch()) {
             $unassignedTransactionsCount[] = $unassignedTransactions->id;
         }
         if (!empty($unassignedTransactionsCount)) {
             $params['total'] = count($unassignedTransactionsCount);
         }
     } else {
         $financialItem = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues, NULL, $params);
         $assignedTransactions = CRM_Batch_BAO_Batch::getBatchFinancialItems($entityID, $returnvalues);
         while ($assignedTransactions->fetch()) {
             $assignedTransactionsCount[] = $assignedTransactions->id;
         }
         if (!empty($assignedTransactionsCount)) {
             $params['total'] = count($assignedTransactionsCount);
         }
     }
     $financialitems = array();
     while ($financialItem->fetch()) {
         $row[$financialItem->id] = array();
         foreach ($columnHeader as $columnKey => $columnValue) {
             if ($financialItem->contact_sub_type && $columnKey == 'contact_type') {
                 $row[$financialItem->id][$columnKey] = $financialItem->contact_sub_type;
                 continue;
             }
             $row[$financialItem->id][$columnKey] = $financialItem->{$columnKey};
             if ($columnKey == 'sort_name' && $financialItem->{$columnKey}) {
                 $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=" . $financialItem->contact_id);
                 $row[$financialItem->id][$columnKey] = '<a href=' . $url . '>' . $financialItem->{$columnKey} . '</a>';
             } elseif ($columnKey == 'payment_method' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Batch_BAO_Batch', 'payment_instrument_id', $financialItem->{$columnKey});
                 if ($row[$financialItem->id][$columnKey] == 'Check') {
                     $checkNumber = $financialItem->check_number ? ' (' . $financialItem->check_number . ')' : '';
                     $row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey] . $checkNumber;
                 }
             } elseif ($columnKey == 'amount' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Utils_Money::format($financialItem->{$columnKey}, $financialItem->currency);
             } elseif ($columnKey == 'transaction_date' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->{$columnKey});
             } elseif ($columnKey == 'status' && $financialItem->{$columnKey}) {
                 $row[$financialItem->id][$columnKey] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $financialItem->{$columnKey});
             }
         }
         if ($statusID == CRM_Core_OptionGroup::getValue('batch_status', 'Open')) {
             if (isset($notPresent)) {
                 $js = "enableActions('x')";
                 $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_x_" . $financialItem->id . "' name='mark_x_" . $financialItem->id . "' value='1' onclick={$js}></input>";
                 $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Form_BatchTransaction::links(), NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
             } else {
                 $js = "enableActions('y')";
                 $row[$financialItem->id]['check'] = "<input type='checkbox' id='mark_y_" . $financialItem->id . "' name='mark_y_" . $financialItem->id . "' value='1' onclick={$js}></input>";
                 $row[$financialItem->id]['action'] = CRM_Core_Action::formLink(CRM_Financial_Page_BatchTransaction::links(), NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
             }
         } else {
             $row[$financialItem->id]['check'] = NULL;
             $tempBAO = new CRM_Financial_Page_BatchTransaction();
             $links = $tempBAO->links();
             unset($links['remove']);
             $row[$financialItem->id]['action'] = CRM_Core_Action::formLink($links, NULL, array('id' => $financialItem->id, 'contid' => $financialItem->contributionID, 'cid' => $financialItem->contact_id), ts('more'), FALSE, 'financialItem.batch.row', 'FinancialItem', $financialItem->id);
         }
         $row[$financialItem->id]['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage(CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) ? CRM_Utils_Array::value('contact_sub_type', $row[$financialItem->id]) : CRM_Utils_Array::value('contact_type', $row[$financialItem->id]), FALSE, $financialItem->contact_id);
         $financialitems = $row;
     }
     $iFilteredTotal = $iTotal = $params['total'];
     $selectorElements = array('check', 'contact_type', 'sort_name', 'amount', 'trxn_id', 'transaction_date', 'payment_method', 'status', 'name', 'action');
     if ($return) {
         return CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     }
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo CRM_Utils_JSON::encodeDataTableSelector($financialitems, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
     CRM_Utils_System::civiExit();
 }