Esempio n. 1
0
 /**
  * Creates a new StewardshipBatch with a given description and Batch Date.  Will use Now() if no date is specified.
  * @param Login $objLogin the login responsible for creating this
  * @param float $fltReportedTotalAmountArray[] optional
  * @param string $strDescription optional
  * @param QDateTime $dttBatchDate optional, or will use Now() if null
  * @param QDateTime $dttDateCredited optional, or will use $dttBatchDate if null
  * @return StewardshipBatch
  */
 public static function Create(Login $objLogin, $fltReportedTotalAmountArray = null, $strDescription = null, QDateTime $dttBatchDate = null, QDateTime $dttDateCredited = null)
 {
     if (!$dttBatchDate) {
         $dttBatchDate = QDateTime::Now();
     } else {
         $dttBatchDate = new QDateTime($dttBatchDate);
     }
     $dttBatchDate->SetTime(null, null, null);
     if (!$dttDateCredited) {
         $dttDateCredited = new QDateTime($dttBatchDate);
     } else {
         $dttDateCredited = new QDateTime($dttDateCredited);
     }
     $dttDateCredited->SetTime(null, null, null);
     $objBatch = new StewardshipBatch();
     $objBatch->CreatedByLogin = $objLogin;
     $objBatch->StewardshipBatchStatusTypeId = StewardshipBatchStatusType::NewBatch;
     $objBatch->DateEntered = $dttBatchDate;
     $objBatch->DateCredited = $dttDateCredited;
     $objCurrentLastLetter = StewardshipBatch::QuerySingle(QQ::Equal(QQN::StewardshipBatch()->DateEntered, $dttBatchDate), QQ::OrderBy(QQN::StewardshipBatch()->BatchLabel, false));
     if ($objCurrentLastLetter) {
         $objBatch->BatchLabel = chr(ord($objCurrentLastLetter->BatchLabel) + 1);
     } else {
         $objBatch->BatchLabel = 'A';
     }
     if ($fltReportedTotalAmountArray) {
         $objBatch->ReportedTotalAmount = null;
         foreach ($fltReportedTotalAmountArray as $fltReportedTotalAmount) {
             $objBatch->ReportedTotalAmount += $fltReportedTotalAmount;
         }
     }
     $objBatch->ActualTotalAmount = 0;
     $objBatch->PostedTotalAmount = 0;
     $objBatch->Description = $strDescription;
     $objBatch->Save();
     // Create Stacks
     if ($fltReportedTotalAmountArray) {
         foreach ($fltReportedTotalAmountArray as $fltReportedTotalAmount) {
             $objBatch->CreateStack($fltReportedTotalAmount);
         }
     }
     return $objBatch;
 }