Ejemplo n.º 1
0
 /**
  * Browse all price set fields.
  *
  * @param null
  *
  * @return void
  * @access public
  */
 function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999);
     }
     $priceField = array();
     $priceFieldBAO = new CRM_Price_BAO_PriceField();
     // fkey is sid
     $priceFieldBAO->price_set_id = $this->_sid;
     $priceFieldBAO->orderBy('weight, label');
     $priceFieldBAO->find();
     while ($priceFieldBAO->fetch()) {
         $priceField[$priceFieldBAO->id] = array();
         CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]);
         // get price if it's a text field
         if ($priceFieldBAO->html_type == 'Text') {
             $optionValues = array();
             $params = array('price_field_id' => $priceFieldBAO->id);
             CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues);
             $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
         }
         $action = array_sum(array_keys($this->actionLinks()));
         if ($this->_isSetReserved) {
             $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE;
         } else {
             if ($priceFieldBAO->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['active_on'] = '';
         }
         if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['expire_on'] = '';
         }
         // need to translate html types from the db
         $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
         $priceField[$priceFieldBAO->id]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']];
         $priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight'];
         $priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('fid' => $priceFieldBAO->id, 'sid' => $this->_sid), ts('more'), FALSE, 'priceField.row.actions', 'PriceField', $priceFieldBAO->id);
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
     $filter = "price_set_id = {$this->_sid}";
     CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_PriceField', 'id', $returnURL, $filter);
     $this->assign('priceField', $priceField);
 }
Ejemplo n.º 2
0
 /**
  * Browse all price set fields.
  *
  * @return void
  */
 public function browse()
 {
     $resourceManager = CRM_Core_Resources::singleton();
     if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
         $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
     }
     $priceField = array();
     $priceFieldBAO = new CRM_Price_BAO_PriceField();
     // fkey is sid
     $priceFieldBAO->price_set_id = $this->_sid;
     $priceFieldBAO->orderBy('weight, label');
     $priceFieldBAO->find();
     // display taxTerm for priceFields
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $getTaxDetails = FALSE;
     $taxRate = CRM_Core_PseudoConstant::getTaxRates();
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     while ($priceFieldBAO->fetch()) {
         $priceField[$priceFieldBAO->id] = array();
         CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]);
         // get price if it's a text field
         if ($priceFieldBAO->html_type == 'Text') {
             $optionValues = array();
             $params = array('price_field_id' => $priceFieldBAO->id);
             CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues);
             $financialTypeId = $optionValues['financial_type_id'];
             if (!array_key_exists($financialTypeId, $financialTypes)) {
                 unset($priceField[$priceFieldBAO->id]);
                 continue;
             }
             $priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
             if ($invoicing && isset($taxRate[$financialTypeId])) {
                 $priceField[$priceFieldBAO->id]['tax_rate'] = $taxRate[$financialTypeId];
                 $getTaxDetails = TRUE;
             }
             if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) {
                 $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate']);
                 $priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount'];
             }
         }
         $action = array_sum(array_keys(self::actionLinks()));
         if ($this->_isSetReserved) {
             $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE;
         } else {
             if ($priceFieldBAO->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['active_on'] = '';
         }
         if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') {
             $priceField[$priceFieldBAO->id]['expire_on'] = '';
         }
         // need to translate html types from the db
         $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
         $priceField[$priceFieldBAO->id]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']];
         $priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight'];
         $priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('fid' => $priceFieldBAO->id, 'sid' => $this->_sid), ts('more'), FALSE, 'priceField.row.actions', 'PriceField', $priceFieldBAO->id);
         $this->assign('taxTerm', $taxTerm);
         $this->assign('getTaxDetails', $getTaxDetails);
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
     $filter = "price_set_id = {$this->_sid}";
     CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_PriceField', 'id', $returnURL, $filter);
     $this->assign('priceField', $priceField);
 }