public function RenderCount(StewardshipPost $objPost)
 {
     if ($objPost->Id) {
         return $objPost->CountStewardshipPostLineItems();
     } else {
         return StewardshipContribution::CountByStewardshipBatchIdUnpostedFlag($this->objBatch->Id, true);
     }
 }
示例#2
0
 /**
  * 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;
 }