protected function buildExtraDataDefaultQuickForm(CRM_Core_Form $form)
 {
     require_once 'CRM/Finance/BAO/BatchType.php';
     require_once 'CRM/Finance/BAO/BankAccount.php';
     require_once 'CRM/Contribute/PseudoConstant.php';
     $form->add('text', 'batch_title', ts('Batch Title'), null, true);
     $form->add('textarea', 'description', ts('Description'), null, false);
     $emptySelect1[''] = '- select -';
     $bankAccounts = CRM_Finance_BAO_BankAccount::getBankAccountsList($emptySelect1);
     $form->add('select', 'banking_account', ts('Bank Account'), $bankAccounts, true);
     //TODO: how to get this in civicrm default format?
     $current = CRM_Utils_Date::getToday(null, 'm/d/Y');
     $form->addDate('banking_date', ts('Banking Date'), true, array('formatType' => 'activityDate', 'value' => $current));
     $form->addElement('checkbox', 'exclude_from_posting', ts('Exclude from posting'), null, null);
     $emptySelect[''] = '- select -';
     $contributionTypes = CRM_Finance_BAO_BatchType::getContributionTypesList($emptySelect);
     $form->add('select', 'contribution_type_id', ts('Contribution Type'), $contributionTypes, true);
     $el = $form->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), true);
     $el->setValue($this->getDefaultPaymentMethodId());
     if (!in_array('campaign_id', $this->hideDefaultFields)) {
         $form->add('text', 'campaign_name', ts('Default Campaign Code'), array('class' => 'form text huge'), true);
         $form->add('hidden', 'campaign_id');
     }
     if (!in_array('received_date', $this->hideDefaultFields)) {
         $form->addDate('received_date', ts('Received date'), true, array('formatType' => 'activityDate', 'value' => $current));
     }
     //$form->add('select', 'contribution_type_id', ts('Contribution Type ID'), array(''=>ts( '- select -' )) + CRM_Contribute_PseudoConstant::contributionType( ), true );
     //matusz: http://support.vedaconsulting.co.uk/issues/81
     //$form->addDate( 'expected_posting_date', ts('Expected posting date'), true, array('formatType' => 'activityDate') );
     $form->addFormRule(array($this, 'extraDataQuickFormRule'));
 }
 static function createBatch(array $batchDetails)
 {
     //check mandatory $params
     foreach (array('banking_date', 'banking_account', 'batch_status', 'exclude_from_posting', 'payment_instrument_id') as $param) {
         if (!isset($batchDetails[$param])) {
             throw new InvalidArgumentException("No param[{$param}]");
         }
     }
     // PS Commented out this way of creating the batch
     // Replaced with using the batch description and tidying
     //$batch_sql = "SELECT max(id) as max_id FROM civicrm_batch";
     //$batch_dao = CRM_Core_DAO::executeQuery($batch_sql);
     //$batch_dao->fetch();
     //$nextId = $batch_dao->max_id + 1;
     $session =& CRM_Core_Session::singleton();
     //$nextId = CRM_Utils_String::titleToVar($batchDetails['description']);
     if (!isset($batchDetails['batch_title'])) {
         $batchDetails['batch_title'] = 'Contrib Batch ' . CRM_Utils_Date::currentDBDate();
     }
     $batchParams = array('title' => $batchDetails['batch_title'], 'description' => $batchDetails['description'], 'created_id' => $session->get('userID'), 'created_date' => CRM_Utils_Date::currentDBDate(), 'type_id' => 1, 'status_id' => 2);
     // Create the batch
     require_once 'CRM/Batch/BAO/Batch.php';
     $createdBatch =& CRM_Batch_BAO_Batch::create($batchParams);
     $batchDetails['batch_id'] = $createdBatch->id;
     require_once 'CRM/Utils/Date.php';
     $batchDetails['banking_date'] = CRM_Utils_Date::processDate($batchDetails['banking_date']);
     //        require_once 'CRM/Finance/BAO/BatchType.php';
     $expectedPostingDate = CRM_Finance_BAO_BatchType::getBatchTypeExpectedPostingDate();
     //matusz: copied from CRM_Batch_Page_AJAX::getContributionTypeForCampaign()
     //$batchDetails['contribution_type_id']
     $campaignId = null;
     if (!empty($batchDetails['campaign_id'])) {
         $campaignId = $batchDetails['campaign_id'];
     }
     /*       
            $contributionTypeId = null;
            if($campaignId !== null) {
                $select_dao = CRM_Core_DAO::executeQuery("SELECT * FROM ".CIVICRM_MTL_CAMPAIGN_FUND_CODE." WHERE campaign_id = %0", array(
                    array($campaignId, 'Int')
                ));
                if (!$select_dao->fetch()){
                    throw new Exception("No contribution_type_id found by using campaign id '$campaignId'");
                }
     
                $batchDetails['contribution_type_id'] = $select_dao->contribution_type_id;
            }
     */
     if (empty($batchDetails['contribution_type_id'])) {
         $batchDetails['contribution_type_id'] = 0;
     }
     $batchDetails['exclude_from_posting'] = empty($batchDetails['exclude_from_posting']) ? 0 : 1;
     $sqlParams = array(array($batchDetails['payment_instrument_id'], 'Int'), array($expectedPostingDate, 'Timestamp'), array($batchDetails['exclude_from_posting'], 'Boolean'), array($batchDetails['banking_date'], 'Timestamp'), array($batchDetails['banking_account'], 'Int'), array($batchDetails['contribution_type_id'], 'Int'), array((string) $batchDetails['batch_title'], 'String'));
     $batchDetailsSql = " UPDATE civicrm_batch SET ";
     $batchDetailsSql .= "    payment_instrument_id = %0 ";
     $batchDetailsSql .= " ,  expected_posting_date = %1 ";
     $batchDetailsSql .= " ,  exclude_from_posting = %2 ";
     $batchDetailsSql .= " ,  banking_date  = %3 ";
     $batchDetailsSql .= " ,  banking_account = %4 ";
     $batchDetailsSql .= " ,  contribution_type_id = %5 ";
     $batchDetailsSql .= " ,  title = %6 ";
     $parameterIndex = 6;
     if ($campaignId !== null) {
         $parameterIndex = $parameterIndex + 1;
         $batchDetailsSql .= ", campaign_id = %{$parameterIndex} ";
         $sqlParams[] = array($campaignId, 'Int');
     }
     /*        
             if(isset($batchDetails['expected_entries'])) {
                 $parameterIndex = $parameterIndex + 1;            
                 $batchDetailsSql .= ", expected_entries = %$parameterIndex ";
                 $sqlParams[] = array($batchDetails['expected_entries'], 'Int');
             }
             
             if(isset($batchDetails['expected_value'])) {
                 $parameterIndex = $parameterIndex + 1;            
                 $batchDetailsSql .= ", expected_value = %$parameterIndex ";
                 $sqlParams[] = array($batchDetails['expected_value'], 'Money');
             }
     */
     if (isset($batchDetails['entity_type'])) {
         $parameterIndex = $parameterIndex + 1;
         $batchDetailsSql .= ", entity_type = %{$parameterIndex} ";
         $sqlParams[] = array($batchDetails['entity_type'], 'String');
     }
     $parameterIndex = $parameterIndex + 1;
     $batchDetailsSql .= " WHERE id = %{$parameterIndex} ";
     $sqlParams[] = array($batchDetails['batch_id'], 'Int');
     CRM_Core_DAO::executeQuery($batchDetailsSql, $sqlParams);
     return $batchDetails;
 }