/**
  * Check method del( )
  */
 public function testDel()
 {
     $ids = array();
     $params = array('name' => 'Test Product', 'sku' => 'TP-10', 'imageOption' => 'noImage', 'price' => 12, 'cost' => 5, 'min_contribution' => 5, 'is_active' => 1);
     $product = CRM_Contribute_BAO_ManagePremiums::add($params, $ids);
     CRM_Contribute_BAO_ManagePremiums::del($product->id);
     $params = array('id' => $product->id);
     $default = array();
     $result = CRM_Contribute_BAO_ManagePremiums::retrieve($params, $defaults);
     $this->assertEquals(empty($result), TRUE, 'Verify product record deletion.');
 }
 /**
  * create financial transaction for premium
  *
  * @access public
  * @static
  */
 static function createPremiumTrxn($params)
 {
     if ((empty($params['financial_type_id']) || empty($params['contributionId'])) && empty($params['oldPremium'])) {
         return;
     }
     if (!empty($params['cost'])) {
         $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         $financialAccountType = CRM_Contribute_PseudoConstant::financialAccountType($params['financial_type_id']);
         $accountRelationship = CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND label IN ('Premiums Inventory Account is', 'Cost of Sales Account is')");
         $toFinancialAccount = !empty($params['isDeleted']) ? 'Premiums Inventory Account is' : 'Cost of Sales Account is';
         $fromFinancialAccount = !empty($params['isDeleted']) ? 'Cost of Sales Account is' : 'Premiums Inventory Account is';
         $accountRelationship = array_flip($accountRelationship);
         $financialtrxn = array('to_financial_account_id' => $financialAccountType[$accountRelationship[$toFinancialAccount]], 'from_financial_account_id' => $financialAccountType[$accountRelationship[$fromFinancialAccount]], 'trxn_date' => date('YmdHis'), 'total_amount' => CRM_Utils_Array::value('cost', $params) ? $params['cost'] : 0, 'currency' => CRM_Utils_Array::value('currency', $params), 'status_id' => array_search('Completed', $contributionStatuses));
         $trxnEntityTable['entity_table'] = 'civicrm_contribution';
         $trxnEntityTable['entity_id'] = $params['contributionId'];
         CRM_Core_BAO_FinancialTrxn::create($financialtrxn, $trxnEntityTable);
     }
     if (!empty($params['oldPremium'])) {
         $premiumParams = array('id' => $params['oldPremium']['product_id']);
         $productDetails = array();
         CRM_Contribute_BAO_ManagePremiums::retrieve($premiumParams, $productDetails);
         $params = array('cost' => CRM_Utils_Array::value('cost', $productDetails), 'currency' => CRM_Utils_Array::value('currency', $productDetails), 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $productDetails), 'contributionId' => $params['oldPremium']['contribution_id'], 'isDeleted' => TRUE);
         CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($params);
     }
 }
 /**
  * Add premium during online Contribution.
  *
  * AddPremium();
  */
 public function testAddPremium()
 {
     $contactId = Contact::createIndividual();
     $ids = array('premium' => NULL);
     $params = array('name' => 'TEST Premium', 'sku' => 111, 'imageOption' => 'noImage', 'MAX_FILE_SIZE' => 2097152, 'price' => 100.0, 'cost' => 90.0, 'min_contribution' => 100, 'is_active' => 1);
     $premium = CRM_Contribute_BAO_ManagePremiums::add($params, $ids);
     $this->assertEquals('TEST Premium', $premium->name, 'Check for premium  name.');
     $ids = array('contribution' => NULL);
     $param = array('contact_id' => $contactId, 'currency' => 'USD', 'financial_type_id' => 1, 'contribution_status_id' => 1, 'payment_instrument_id' => 1, 'source' => 'STUDENT', 'receive_date' => '20080522000000', 'receipt_date' => '20080522000000', 'id' => NULL, 'non_deductible_amount' => 0.0, 'total_amount' => 300.0, 'fee_amount' => 5, 'net_amount' => 295, 'trxn_id' => '33erdfrwvw434', 'invoice_id' => '98ed34f7u9hh672ce0eafe8fb92', 'thankyou_date' => '20080522');
     $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids);
     $this->assertEquals($param['trxn_id'], $contribution->trxn_id, 'Check for transcation id creation.');
     $this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id  creation.');
     //parameter for adding premium to contribution
     $data = array('product_id' => $premium->id, 'contribution_id' => $contribution->id, 'product_option' => NULL, 'quantity' => 1);
     $contributionProduct = CRM_Contribute_BAO_Contribution::addPremium($data);
     $this->assertEquals($contributionProduct->product_id, $premium->id, 'Check for Product id .');
     //Delete Product
     CRM_Contribute_BAO_ManagePremiums::del($premium->id);
     $this->assertDBNull('CRM_Contribute_DAO_Product', $premium->name, 'id', 'name', 'Database check for deleted Product.');
     //Delete Contribution
     $this->contributionDelete($contribution->id);
     //Delete Contact
     Contact::delete($contactId);
 }
 /**
  * Process the Premium Information.
  *
  * @param array $params
  * @param int $contributionID
  * @param int $premiumID
  * @param array $options
  */
 public static function processPremium($params, $contributionID, $premiumID = NULL, $options = array())
 {
     $selectedProductID = $params['product_name'][0];
     $selectedProductOptionID = CRM_Utils_Array::value(1, $params['product_name']);
     $dao = new CRM_Contribute_DAO_ContributionProduct();
     $dao->contribution_id = $contributionID;
     $dao->product_id = $selectedProductID;
     $dao->fulfilled_date = CRM_Utils_Date::processDate($params['fulfilled_date'], NULL, TRUE);
     $isDeleted = FALSE;
     //CRM-11106
     $premiumParams = array('id' => $selectedProductID);
     $productDetails = array();
     CRM_Contribute_BAO_ManagePremiums::retrieve($premiumParams, $productDetails);
     $dao->financial_type_id = CRM_Utils_Array::value('financial_type_id', $productDetails);
     if (!empty($options[$selectedProductID])) {
         $dao->product_option = $options[$selectedProductID][$selectedProductOptionID];
     }
     if ($premiumID) {
         $ContributionProduct = new CRM_Contribute_DAO_ContributionProduct();
         $ContributionProduct->id = $premiumID;
         $ContributionProduct->find(TRUE);
         if ($ContributionProduct->product_id == $selectedProductID) {
             $dao->id = $premiumID;
         } else {
             $ContributionProduct->delete();
             $isDeleted = TRUE;
         }
     }
     $dao->save();
     //CRM-11106
     if ($premiumID == NULL || $isDeleted) {
         $premiumParams = array('cost' => CRM_Utils_Array::value('cost', $productDetails), 'currency' => CRM_Utils_Array::value('currency', $productDetails), 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $productDetails), 'contributionId' => $contributionID);
         if ($isDeleted) {
             $premiumParams['oldPremium']['product_id'] = $ContributionProduct->product_id;
             $premiumParams['oldPremium']['contribution_id'] = $ContributionProduct->contribution_id;
         }
         CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($premiumParams);
     }
 }
示例#5
0
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contribute_BAO_ManagePremiums::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Premium Product type has been deleted.'), ts('Deleted'), 'info');
     } else {
         $params = $this->controller->exportValues($this->_name);
         $imageFile = CRM_Utils_Array::value('uploadFile', $params);
         $imageFile = $imageFile['name'];
         $config = CRM_Core_Config::singleton();
         $ids = array();
         $error = FALSE;
         // store the submitted values in an array
         // FIX ME
         if (CRM_Utils_Array::value('imageOption', $params, FALSE)) {
             $value = CRM_Utils_Array::value('imageOption', $params, FALSE);
             if ($value == 'image') {
                 // to check wether GD is installed or not
                 $gdSupport = CRM_Utils_System::getModuleSetting('gd', 'GD Support');
                 if ($gdSupport) {
                     if ($imageFile) {
                         $error = FALSE;
                         $params['image'] = $this->_resizeImage($imageFile, "_full", 200, 200);
                         $params['thumbnail'] = $this->_resizeImage($imageFile, "_thumb", 50, 50);
                     }
                 } else {
                     $error = TRUE;
                     $params['image'] = $config->resourceBase . 'i/contribute/default_premium.jpg';
                     $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
                 }
             } elseif ($value == 'thumbnail') {
                 $params['image'] = $params['imageUrl'];
                 $params['thumbnail'] = $params['thumbnailUrl'];
             } elseif ($value == 'default_image') {
                 $url = parse_url($config->userFrameworkBaseURL);
                 $params['image'] = $config->resourceBase . 'i/contribute/default_premium.jpg';
                 $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
             } else {
                 $params['image'] = "";
                 $params['thumbnail'] = "";
             }
         }
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['premium'] = $this->_id;
         }
         // fix the money fields
         foreach (array('cost', 'price', 'min_contribution') as $f) {
             $params[$f] = CRM_Utils_Rule::cleanMoney($params[$f]);
         }
         $premium = CRM_Contribute_BAO_ManagePremiums::add($params, $ids);
         if ($error) {
             CRM_Core_Session::setStatus(ts('No thumbnail of your image was created because the GD image library is not currently compiled in your PHP installation. Product is currently configured to use default thumbnail image. If you have a local thumbnail image you can upload it separately and input the thumbnail URL by editing this premium.'), ts('Notice'), 'alert');
         } else {
             CRM_Core_Session::setStatus(ts("The Premium '%1' has been saved.", array(1 => $premium->name)), ts('Saved'), 'success');
         }
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     require_once 'CRM/Contribute/BAO/ManagePremiums.php';
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         CRM_Contribute_BAO_ManagePremiums::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Premium Product type has been deleted.'));
     } else {
         $params = $this->controller->exportValues($this->_name);
         $imageFile = CRM_Utils_Array::value('uploadFile', $params);
         $imageFile = $imageFile['name'];
         $config =& CRM_Core_Config::singleton();
         $ids = array();
         $error = false;
         // store the submitted values in an array
         // FIX ME
         if (CRM_Utils_Array::value('imageOption', $params, false)) {
             $value = CRM_Utils_Array::value('imageOption', $params, false);
             if ($value == 'image') {
                 if ($imageFile) {
                     $fileName = basename($imageFile);
                     $params['image'] = $config->imageUploadURL . $fileName;
                     // to check wether GD is installed or not
                     require_once 'CRM/Utils/System.php';
                     $gdSupport = CRM_Utils_System::getModuleSetting('gd', 'GD Support');
                     $jpgSupport = CRM_Utils_System::getModuleSetting('gd', 'JPG Support');
                     $gifSupport = CRM_Utils_System::getModuleSetting('gd', 'GIF Read Support');
                     $pngSupport = CRM_Utils_System::getModuleSetting('gd', 'PNG Support');
                     $error = false;
                     if ($gdSupport == 'enabled' && $jpgSupport == 'enabled' && $gifSupport == 'enabled' && $pngSupport == 'enabled') {
                         list($width_orig, $height_orig) = getimagesize($imageFile);
                         $imageInfo = getimagesize($imageFile);
                         $width_orig . "<br>";
                         $height_orig . "<br>";
                         $path = explode('/', $imageFile);
                         $thumbFileName = $path[count($path) - 1];
                         $info = pathinfo($thumbFileName);
                         $basename = substr($info['basename'], 0, -(strlen($info['extension']) + ($info['extension'] == '' ? 0 : 1)));
                         $thumbFileName = $basename . "_thumb." . $info['extension'];
                         $path[count($path) - 1] = $thumbFileName;
                         $path = implode('/', $path);
                         $width = $height = 100;
                         $thumb = imagecreate($width, $height);
                         if ($imageInfo['mime'] == 'image/gif') {
                             $source = imagecreatefromgif($imageFile);
                         } else {
                             if ($imageInfo['mime'] == 'image/png') {
                                 $source = imagecreatefrompng($imageFile);
                             } else {
                                 $source = imagecreatefromjpeg($imageFile);
                             }
                         }
                         imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
                         $fp = fopen($path, 'w+');
                         ob_start();
                         ImageJPEG($thumb);
                         $image_buffer = ob_get_contents();
                         ob_end_clean();
                         ImageDestroy($thumb);
                         fwrite($fp, $image_buffer);
                         rewind($fp);
                         fclose($fp);
                         $params['thumbnail'] = $config->imageUploadURL . $thumbFileName;
                     } else {
                         $error = true;
                         $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
                     }
                 }
             } else {
                 if ($value == 'thumbnail') {
                     $params['image'] = $params['imageUrl'];
                     $params['thumbnail'] = $params['thumbnailUrl'];
                 } else {
                     if ($value == 'default_image') {
                         $url = parse_url($config->userFrameworkBaseURL);
                         $params['image'] = $config->resourceBase . 'i/contribute/default_premium.jpg';
                         $params['thumbnail'] = $config->resourceBase . 'i/contribute/default_premium_thumb.jpg';
                     } else {
                         $params['image'] = "";
                         $params['thumbnail'] = "";
                     }
                 }
             }
         }
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['premium'] = $this->_id;
         }
         // fix the money fields
         foreach (array('cost', 'price', 'min_contribution') as $f) {
             $params[$f] = CRM_Utils_Rule::cleanMoney($params[$f]);
         }
         $premium = CRM_Contribute_BAO_ManagePremiums::add($params, $ids);
         if ($error) {
             CRM_Core_Session::setStatus(ts('NOTICE: No thumbnail of your image was created because the GD image library is not currently compiled in your PHP installation. Product is currently configured to use default thumbnail image. If you have a local thumbnail image you can upload it separately and input the thumbnail URL by editing this premium.'));
         } else {
             CRM_Core_Session::setStatus(ts('The Premium \'%1\' has been saved.', array(1 => $premium->name)));
         }
     }
 }
示例#7
0
 /**
  * Function to process the Premium Information
  *
  * @access public
  *
  * @return None
  */
 static function processPremium(&$params, $contributionID, $premiumID = NULL, &$options = NULL)
 {
     $dao = new CRM_Contribute_DAO_ContributionProduct();
     $dao->contribution_id = $contributionID;
     $dao->product_id = $params['product_name'][0];
     $dao->fulfilled_date = CRM_Utils_Date::processDate($params['fulfilled_date'], NULL, TRUE);
     $isDeleted = False;
     //CRM-11106
     $premiumParams = array('id' => $params['product_name'][0]);
     $productDetails = array();
     CRM_Contribute_BAO_ManagePremiums::retrieve($premiumParams, $productDetails);
     $dao->financial_type_id = CRM_Utils_Array::value('financial_type_id', $productDetails);
     if (CRM_Utils_Array::value($params['product_name'][0], $options)) {
         $dao->product_option = $options[$params['product_name'][0]][$params['product_name'][1]];
     }
     if ($premiumID) {
         $premoumDAO = new CRM_Contribute_DAO_ContributionProduct();
         $premoumDAO->id = $premiumID;
         $premoumDAO->find(TRUE);
         if ($premoumDAO->product_id == $params['product_name'][0]) {
             $dao->id = $premiumID;
             $premium = $dao->save();
         } else {
             $premoumDAO->delete();
             $isDeleted = TRUE;
             $premium = $dao->save();
         }
     } else {
         $premium = $dao->save();
     }
     //CRM-11106
     if ($premiumID == NULL || $isDeleted) {
         $params = array('cost' => CRM_Utils_Array::value('cost', $productDetails), 'currency' => CRM_Utils_Array::value('currency', $productDetails), 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $productDetails), 'contributionId' => $contributionID);
         if ($isDeleted) {
             $params['oldPremium']['product_id'] = $premoumDAO->product_id;
             $params['oldPremium']['contribution_id'] = $premoumDAO->contribution_id;
         }
         CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($params);
     }
 }