Пример #1
0
 public static function GenerateStewardship()
 {
     $dttDate = new QDateTime('2004-01-05');
     print 'Generating Stewardship... ';
     $objFundArray = StewardshipFund::QueryArray(QQ::NotEqual(QQN::StewardshipFund()->Id, 1));
     while ($dttDate->IsEarlierThan(QDateTime::Now())) {
         print $strDate = '[' . $dttDate->ToString('YYYY-MMM-DD') . ']';
         $intCheckCount = rand(10, 55);
         $arrStack = array();
         for ($i = 0; $i < floor(($intCheckCount - 1) / 25) + 1; $i++) {
             $arrStack[] = null;
         }
         $objBatch = StewardshipBatch::Create(self::GenerateFromArray(self::$StewardshipUserArray), $arrStack, self::GenerateFromArray(array('Weekend T/O', 'Weekend Giving', 'Tithes and Offerings', 'Tithes & Offerings', null)), $dttDate, $dttDate);
         $intStackCount = $objBatch->CountStewardshipStacks();
         $dttStart = new QDateTime($dttDate);
         $dttStart->SetTime(8, 0, 0);
         $dttEnd = new QDateTime($dttDate);
         $dttEnd->SetTime(16, 0, 0);
         for ($i = 0; $i < $intStackCount; $i++) {
             if ($i == $intStackCount - 1) {
                 if ($intCheckCount % 25 == 0) {
                     $intChecksInStackCount = 25;
                 } else {
                     $intChecksInStackCount = $intCheckCount % 25;
                 }
             } else {
                 $intChecksInStackCount = 25;
             }
             $objStack = StewardshipStack::LoadByStewardshipBatchIdStackNumber($objBatch->Id, $i + 1);
             for ($j = 0; $j < $intChecksInStackCount; $j++) {
                 $objHousehold = self::GenerateFromArray(self::$HouseholdArray);
                 $objHouseholdParticipant = self::GenerateFromArray($objHousehold->GetHouseholdParticipationArray());
                 $mixAmountArray = array();
                 if (rand(0, 50)) {
                     $mixAmountArray[] = array(1, rand(1000, 150000) / 100);
                 } else {
                     $mixAmountArray[] = array(self::GenerateFromArray($objFundArray)->Id, rand(1000, 150000) / 100);
                 }
                 if (!rand(0, 20)) {
                     $mixAmountArray[] = array(self::GenerateFromArray($objFundArray)->Id, rand(1000, 150000) / 100);
                 }
                 $objContribution = StewardshipContribution::Create($objBatch->CreatedByLogin, $objHouseholdParticipant->Person, $objStack, StewardshipContributionType::Check, rand(1000, 9999), $mixAmountArray, self::GenerateDateTime($dttStart, $dttEnd), null, null, null, false);
                 if (rand(0, 5)) {
                     $objContribution->SaveImageFile(__DEVTOOLS_CLI__ . '/datagen_file_assets/check.tif');
                 }
             }
             $objStack->RefreshActualTotalAmount();
         }
         if ($intCheckCount != $objBatch->CountStewardshipContributions()) {
             print "\r\n" . 'MISCOUNT: ' . $objBatch->Id . "\r\n";
         }
         $objBatch->RefreshActualTotalAmount();
         $dttDate->Day += 7;
         print str_repeat(chr(8) . ' ' . chr(8), strlen($strDate));
     }
     print "Done.\r\n";
 }
Пример #2
0
Файл: new.php Проект: alcf/chms
 public function btnSave_Click()
 {
     $fltArray = array();
     foreach ($this->txtReportedTotals as $txtReportedTotal) {
         if ($txtReportedTotal->Visible) {
             if ($fltAmount = trim($txtReportedTotal->Text)) {
                 $fltArray[] = $fltAmount;
             } else {
                 $fltArray[] = null;
             }
         }
     }
     $objBatch = StewardshipBatch::Create(QApplication::$Login, $fltArray, trim($this->txtDescription->Text), null, $this->calDateCredited->DateTime);
     QApplication::Redirect('/stewardship/batch.php/' . $objBatch->Id . '#1');
 }
Пример #3
0
 public function PostBatch(Login $objLogin, QDateTime $dttDateCredited)
 {
     if ($this->blnReconciledFlag) {
         throw new QCallerException('Cannot post a PayPal Batch that has already been reconciled!');
     }
     // First, create the stewardship stacks into arrays of 100
     $objToBecomeStacksArray = array();
     $fltStackTotalsArray = array();
     $fltRunningTotal = 0;
     $objCurrentStack = array();
     foreach ($this->GetCreditCardPaymentArray(QQ::OrderBy(QQN::CreditCardPayment()->DateCaptured)) as $objCreditCardPayment) {
         if ($objCreditCardPayment->OnlineDonation || $objCreditCardPayment->SignupPayment && $objCreditCardPayment->SignupPayment->AmountDonation) {
             if (count($objCurrentStack) >= 100) {
                 $objToBecomeStacksArray[] = $objCurrentStack;
                 $fltStackTotalsArray[] = $fltRunningTotal;
                 $objCurrentStack = array();
                 $fltRunningTotal = 0;
             }
             $objCurrentStack[] = $objCreditCardPayment;
             if ($objCreditCardPayment->OnlineDonation) {
                 foreach ($objCreditCardPayment->OnlineDonation->GetOnlineDonationLineItemArray() as $objOnlineDonationLineItem) {
                     if ($objOnlineDonationLineItem->DonationFlag) {
                         $fltRunningTotal += $objOnlineDonationLineItem->Amount;
                     }
                 }
             } else {
                 $fltRunningTotal += $objCreditCardPayment->SignupPayment->AmountDonation;
             }
         }
     }
     if (count($objCurrentStack)) {
         $objToBecomeStacksArray[] = $objCurrentStack;
         $fltStackTotalsArray[] = $fltRunningTotal;
     }
     // Start a Transaction
     PaypalBatch::GetDatabase()->TransactionBegin();
     try {
         // Create the Batch
         $objBatch = StewardshipBatch::Create($objLogin, $fltStackTotalsArray, 'Stewardship Entries for PayPal Batch #' . $this->Number, QDateTime::Now(), $dttDateCredited);
         $objStackArray = $objBatch->GetStewardshipStackArray(QQ::OrderBy(QQN::StewardshipStack()->StackNumber));
         if (count($objStackArray) != count($objToBecomeStacksArray)) {
             throw new Exception('Mismatch of Created Stacks vs. Calculated Stacks');
         }
         // Create Each Stack
         for ($intStackIndex = 0; $intStackIndex < count($objStackArray); $intStackIndex++) {
             $objStack = $objStackArray[$intStackIndex];
             $objPaymentArray = $objToBecomeStacksArray[$intStackIndex];
             foreach ($objPaymentArray as $objPayment) {
                 // Create a StewardshipContribution for each OnlineDonation entry
                 if ($objPayment->OnlineDonation) {
                     // First ensure we have a Donation AmountArray
                     $objAmountArray = $objPayment->OnlineDonation->GetAmountArray();
                     if ($objAmountArray) {
                         $objContribution = StewardshipContribution::Create($objLogin, $objPayment->OnlineDonation->Person, $objStack, StewardshipContributionType::CreditCard, $objPayment->TransactionCode, $objAmountArray, null, null, null, null, true);
                     } else {
                         $objContribution = null;
                     }
                     // Create a StewardshipContribution for the donation in a SignupPayment
                 } else {
                     $objContribution = StewardshipContribution::Create($objLogin, $objPayment->SignupPayment->SignupEntry->SignupByPerson, $objStack, StewardshipContributionType::CreditCard, $objPayment->TransactionCode, array(array($objPayment->SignupPayment->DonationStewardshipFundId, $objPayment->SignupPayment->AmountDonation)), null, null, null, null, true);
                 }
                 // Proceed if a Contribution was successfully created
                 if ($objContribution) {
                     // Fixup on the Contribution Object
                     $objContribution->AlternateSource = $objPayment->CreditCardDescription;
                     $objContribution->DateCredited = $dttDateCredited;
                     $objContribution->Save();
                     // Fixup on the CCPayment Object to link back to the contribution object
                     $objPayment->StewardshipContribution = $objContribution;
                     $objPayment->Save();
                 }
             }
         }
         // Cleanup each Payment object
         foreach ($this->GetCreditCardPaymentArray() as $objCreditCardPayment) {
             $objCreditCardPayment->CreditCardStatusTypeId = CreditCardStatusType::Reconciled;
             $objCreditCardPayment->Save();
         }
         // Cleanup this object
         $this->blnReconciledFlag = true;
         $this->dttDateReconciled = QDateTime::Now();
         $this->StewardshipBatch = $objBatch;
         $this->Save();
         // Finally, Post the StewardshipBatch
         $objBatch->PostBalance($objLogin);
         // If we are here, then it was a success!  Commit the Transaction!
         PaypalBatch::GetDatabase()->TransactionCommit();
     } catch (Exception $objExc) {
         PaypalBatch::GetDatabase()->TransactionRollBack();
         throw $objExc;
     }
 }