/** * Returns an array of 2-item arrays, where each item has the following index: * 0: stewardship_fund_id * 1; total amount YTD * for a given month * @param QDateTime $dttMonth * @return string[][] */ public static function GetReportYtdByFundForMonth(QDateTime $dttMonth) { $dttMonth->Day = 1; $dttMonth->SetTime(null, null, null); $dttNextMonth = new QDateTime($dttMonth); $dttNextMonth->Month++; $dttNextMonth->SetTime(null, null, null); $dttMonth->Month = 1; $objResult = StewardshipPostAmount::GetDatabase()->Query(sprintf("SELECT stewardship_fund_id, SUM(amount) AS sum_amount FROM stewardship_post_amount, stewardship_post, stewardship_batch WHERE\n\t\t\t\tstewardship_batch_id=stewardship_batch.id AND\n\t\t\t\tstewardship_post_id=stewardship_post.id AND date_credited >= '%s' AND date_credited < '%s' GROUP BY stewardship_fund_id ORDER BY SUM(amount) DESC;", $dttMonth->ToString('YYYY-MM-DD'), $dttNextMonth->ToString('YYYY-MM-DD'))); $strToReturn = array(); while ($objRow = $objResult->GetNextRow()) { $strToReturn[] = array($objRow->GetColumn('stewardship_fund_id'), $objRow->GetColumn('sum_amount')); } return $strToReturn; }
/** * Deletes all associated StewardshipPostAmounts * @return void */ public function DeleteAllStewardshipPostAmounts() { if (is_null($this->intId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateStewardshipPostAmount on this unsaved StewardshipPost.'); } // Get the Database Object for this Class $objDatabase = StewardshipPost::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (StewardshipPostAmount::LoadArrayByStewardshipPostId($this->intId) as $objStewardshipPostAmount) { $objStewardshipPostAmount->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `stewardship_post_amount` WHERE `stewardship_post_id` = ' . $objDatabase->SqlVariable($this->intId) . ' '); }
/** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this StewardshipPostAmountMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing StewardshipPostAmount object creation - defaults to CreateOrEdit * @return StewardshipPostAmountMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objStewardshipPostAmount = StewardshipPostAmount::Load($intId); // StewardshipPostAmount was found -- return it! if ($objStewardshipPostAmount) { return new StewardshipPostAmountMetaControl($objParentObject, $objStewardshipPostAmount); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a StewardshipPostAmount object with PK arguments: ' . $intId); } } // If EditOnly is specified, throw an exception } else { if ($intCreateType == QMetaControlCreateType::EditOnly) { throw new QCallerException('No PK arguments specified'); } } // If we are here, then we need to create a new record return new StewardshipPostAmountMetaControl($objParentObject, new StewardshipPostAmount()); }
/** * Performs a Post of any balance on the batch. * @param Login $objLogin * @return StewardshipPost $objPost the actual post object if posted, or null if nothing was needed to be posted */ public function PostBalance(Login $objLogin) { $objPost = null; $fltBalanceArray = $this->GetUnpostedBalanceByStewardshipFundId(); if (count($fltBalanceArray) || StewardshipContribution::CountByStewardshipBatchIdUnpostedFlag($this->intId, true)) { $objLastPost = StewardshipPost::QuerySingle(QQ::Equal(QQN::StewardshipPost()->StewardshipBatchId, $this->intId), QQ::OrderBy(QQN::StewardshipPost()->PostNumber, false)); if ($objLastPost) { $intPostNumber = $objLastPost->PostNumber + 1; } else { $intPostNumber = 1; } $objPost = new StewardshipPost(); $objPost->StewardshipBatch = $this; $objPost->PostNumber = $intPostNumber; $objPost->DatePosted = QDateTime::Now(); $objPost->CreatedByLoginId = $objLogin->Id; $objPost->Save(); // It is possible (Due to status caching) that this can be called when there is actually nothing to post // If this happens, we'll want to delete the Post" $blnPosted = false; $fltTotalAmount = 0; foreach ($fltBalanceArray as $intFundId => $fltAmount) { $blnPosted = true; $objPostAmount = new StewardshipPostAmount(); $objPostAmount->StewardshipPostId = $objPost->Id; $objPostAmount->StewardshipFundId = $intFundId; $objPostAmount->Amount = $fltAmount; $objPostAmount->Save(); $fltTotalAmount += $fltAmount; } $objPost->TotalAmount = $fltTotalAmount; $objPost->Save(); // Add the Line Items foreach (StewardshipContribution::LoadArrayByStewardshipBatchIdUnpostedFlag($this->intId, true) as $objContribution) { if ($objContribution->PostLineItems($objPost)) { $blnPosted = true; } } // if NOTHING was physically posted, then delete the Post object. if (!$blnPosted) { $objPost->Delete(); $objPost = null; } } $this->RefreshStatus(); // Let's refresh the descriptions foreach ($this->GetStewardshipPostArray() as $objPostToRefresh) { foreach ($objPostToRefresh->GetStewardshipPostLineItemArray() as $objPostLineItem) { $objPostLineItem->RefreshDescription(); } } return $objPost; }
/** * Main utility method to aid with data binding. It is used by the default BindAllRows() databinder but * could and should be used by any custom databind methods that would be used for instances of this * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). * * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query * @return void */ public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null) { // Setup input parameters to default values if none passed in if (!$objCondition) { $objCondition = QQ::All(); } $objClauses = $objOptionalClauses ? $objOptionalClauses : array(); // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = StewardshipPostAmount::QueryCount($objCondition, $objClauses); } // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add // the OrderByClause to the $objClauses array if ($objClause = $this->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from StewardshipPostAmount, given the clauses above $this->DataSource = StewardshipPostAmount::QueryArray($objCondition, $objClauses); }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, StewardshipPostAmount::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }