public function testLevelApplyingWithFreeRegistration()
 {
     $sylvheim = Member::getByNum(\SystemStats::ACCOUNT_SYLVHEIM);
     $sylvheim_total = new TransactionTotalsAssertions($sylvheim, $this);
     /* Setup - This member is set as paid but no money is spread.
         * Because this one is just for testing purpose
        ---------------------------------------------*/
     $marketingLeader = DbEntityHelper::createMember($sylvheim, ['Type' => Member::TYPE_MARKETINGLEADER]);
     $marketingLeader->reload(self::$propelCon);
     $marketingLeader_total = new TransactionTotalsAssertions($marketingLeader, $this);
     /* Create invitation
        ---------------------------------------------*/
     $invitation = Invitation::create($marketingLeader, ['type' => Member::TYPE_ORGLEADER, 'free_signup' => 1], self::$propelCon);
     /* Create member with created invitation code
        ---------------------------------------------*/
     list($valid, $data, $referralMember, $invitation) = \Member::validateSignupForm(array_merge(self::$singupFormData, ['referral_member_num' => $marketingLeader->getNum(), 'invitation_code' => $invitation->getHash()]));
     // Because the marketing leader is level 1 this org leader will be
     // transfered to be child of sylvheim
     $orgLeader = \Member::createFromSignup($data, $marketingLeader, $invitation, self::$propelCon);
     $orgLeader->reload(self::$propelCon);
     // Because orgleaders parent has to be sylvhelm, advertising someone first time
     // needs to bonus sylvheim
     DbEntityHelper::createSignupMember($orgLeader);
     // Spread money for creating this last member
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM, 1);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT, 1);
     // VL_BONUS - because, orgleader was VL first member and got transferred to
     // sylvheimm, therefore there is no VL between sylvheim and ol when ol
     // inviteds member
     $sylvheim_total->add(Transaction::REASON_VL_BONUS, 1);
     // marketing leader gets nothing from ol's advertising.
     $sylvheim_total->assertTotals();
     $marketingLeader_total->assertTotals();
 }
 public function testMemberGetBonusLevelPaymentsApplied()
 {
     $marketingLeader = DbEntityHelper::createMember(null, ['type' => Member::TYPE_MARKETINGLEADER, 'LastName' => 'vl']);
     $marketingLeader->reload(self::$propelCon);
     /* $m1 gets bonus level applied after recruiting several members
        ---------------------------------------------*/
     $m1 = DbEntityHelper::createSignupMember($marketingLeader, true, ['lastName' => 'm1']);
     $m1_total = new TransactionTotalsAssertions($m1, $this);
     $m1_1 = DbEntityHelper::createSignupMember($m1, true, ['lastName' => 'm1_1']);
     $m1_2 = DbEntityHelper::createSignupMember($m1, true, ['lastName' => 'm1_2']);
     $m1_2_1 = DbEntityHelper::createSignupMember($m1_2, true, ['lastName' => 'm1_2_1']);
     $m1_2_2 = DbEntityHelper::createSignupMember($m1_2, true, ['lastName' => 'm1_2_2']);
     $m1_3_1 = DbEntityHelper::createSignupMember($m1_2, true, ['lastName' => 'm1_3_1']);
     $m1_total->add(Transaction::REASON_ADVERTISED_LVL1, 2);
     /* $m1 gets bonus level 3 now
        ---------------------------------------------*/
     $m1->activity_setBonusLevel(3.29, self::$propelCon);
     /* further recruiting requires the bonus of the member applied
        ---------------------------------------------*/
     $m1_3 = DbEntityHelper::createSignupMember($m1, true, ['lastName' => 'm1_3']);
     $m1_2_3 = DbEntityHelper::createSignupMember($m1_2_1, true, ['lastName' => 'm1_2_3']);
     $m1_3_1_1 = DbEntityHelper::createSignupMember($m1_3_1, true, ['lastName' => 'm1_3_1_1']);
     $m1_3_1 = DbEntityHelper::createSignupMember($m1_3, true, ['lastName' => 'm1_3_1']);
     $m1_3_2 = DbEntityHelper::createSignupMember($m1_3, true, ['lastName' => 'm1_3_2']);
     $m1_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $m1_total->add(Transaction::REASON_ADVERTISED_INDIRECT, 2);
     $m1_total->addBonusLevelPayment(5);
     $m1_total->assertTotals();
     /* remove the bonus level afterwards
        ---------------------------------------------*/
     $m1->activity_setBonusLevel(0, self::$propelCon);
     $m1_4 = DbEntityHelper::createSignupMember($m1, true, ['lastName' => 'm1_4']);
     $m1_3_3 = DbEntityHelper::createSignupMember($m1_3, true, ['lastName' => 'm1_3_3']);
     $m1_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $m1_total->assertTotals();
 }
Exemple #3
0
 public function testReceivingChildrenOfDeletedFirstMemberWithDeepTree()
 {
     // NOTE: This tests what happen if my first advertising gets
     // deleted due to not paying fee.
     /* Setup
        ---------------------------------------------*/
     DbEntityHelper::setCon(self::$propelCon);
     $promoter1 = DbEntityHelper::createMember();
     $MYSELF = DbEntityHelper::createSignupMember($promoter1);
     $MYSELF_total = new TransactionTotalsAssertions($MYSELF, $this);
     $this->assertEquals($MYSELF->getFundsLevel(), Member::FUNDS_LEVEL1);
     /* Advertise 2 users
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $franz = DbEntityHelper::createSignupMember($MYSELF);
     $WILL_NOT_PAY = DbEntityHelper::createSignupMember($MYSELF, false);
     /* WILL_NOT_PAY advertises 3 and these does either advertise a view
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL2, 4);
     DbEntityHelper::createSignupMember($WILL_NOT_PAY);
     DbEntityHelper::createSignupMember($WILL_NOT_PAY);
     DbEntityHelper::createSignupMember($WILL_NOT_PAY);
     $deep1 = DbEntityHelper::createSignupMember($WILL_NOT_PAY);
     $deep1_lazy = DbEntityHelper::createSignupMember($WILL_NOT_PAY, false);
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_INDIRECT, 2);
     $deep2 = DbEntityHelper::createSignupMember($deep1);
     DbEntityHelper::createSignupMember($deep1);
     DbEntityHelper::createSignupMember($deep1);
     DbEntityHelper::createSignupMember($deep1);
     $deep2_lazy = DbEntityHelper::createSignupMember($deep1, false);
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_INDIRECT, 2);
     $deep3 = DbEntityHelper::createSignupMember($deep2, false);
     DbEntityHelper::createSignupMember($deep2);
     $WILL_NOT_PAY->deleteAndUpdateTree(self::$propelCon);
     DbEntityHelper::fireReceivedMemberFee($deep1_lazy, time());
     DbEntityHelper::fireReceivedMemberFee($deep2_lazy, time());
     DbEntityHelper::fireReceivedMemberFee($deep3, time());
     // ---- assert - ME
     $MYSELF_total->assertTotals();
 }
Exemple #4
0
 public function testSnowballModelLazyIncommingFeeExtensiv()
 {
     // NOTE: this is basically the exact same scenario as @see $this->testSnowballModel
     // with the only difference that the incomming of the member fee
     // happens lazy and in different order. Later advertised members does
     // pay earlier so that ReservedPaidEvents get created and triggered.
     /* Setup
        ---------------------------------------------*/
     $now = time();
     $promoter1 = DbEntityHelper::createMember();
     $MYSELF = DbEntityHelper::createSignupMember($promoter1);
     $MYSELF_total = new TransactionTotalsAssertions($MYSELF, $this);
     $this->assertEquals($MYSELF->getFundsLevel(), Member::FUNDS_LEVEL1);
     /* Advertise 2 users
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL1, 2);
     $far_l1_1 = DbEntityHelper::createSignupMember($MYSELF, false);
     $bea_l1_2 = DbEntityHelper::createSignupMember($MYSELF, false);
     /* Advertise 1 more user - chris
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $CHRIS_l1_3 = DbEntityHelper::createSignupMember($MYSELF, false);
     $CHRIS_total = new TransactionTotalsAssertions($CHRIS_l1_3, $this);
     /* chris advertise 1 user - dean
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $DEAN_l2_1 = DbEntityHelper::createSignupMember($CHRIS_l1_3, false);
     /* chris advertise 1 user - emi
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $EMI_l2_2 = DbEntityHelper::createSignupMember($CHRIS_l1_3, false);
     /* dean advertise 1 user - franz
        ---------------------------------------------*/
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $FRANZ_l3_1 = DbEntityHelper::createSignupMember($DEAN_l2_1, false);
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_INDIRECT, 3);
     $anonym1 = DbEntityHelper::createSignupMember($DEAN_l2_1, false);
     $anonym2 = DbEntityHelper::createSignupMember($EMI_l2_2, false);
     $anonym3 = DbEntityHelper::createSignupMember($EMI_l2_2, false);
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_INDIRECT, 4);
     $ALF_l2_3 = DbEntityHelper::createSignupMember($CHRIS_l1_3, false);
     $GUST_l3_1 = DbEntityHelper::createSignupMember($ALF_l2_3, false);
     $anonym4 = DbEntityHelper::createSignupMember($ALF_l2_3, false);
     $anonym5 = DbEntityHelper::createSignupMember($GUST_l3_1, false);
     $anonym6 = DbEntityHelper::createSignupMember($GUST_l3_1, false);
     /* fee incomming in different order for all users
        ---------------------------------------------*/
     DbEntityHelper::fireReceivedMemberFee($anonym6, $now);
     DbEntityHelper::fireReceivedMemberFee($anonym5, $now);
     DbEntityHelper::fireReceivedMemberFee($anonym4, $now);
     DbEntityHelper::fireReceivedMemberFee($GUST_l3_1, $now);
     DbEntityHelper::fireReceivedMemberFee($anonym3, $now);
     DbEntityHelper::fireReceivedMemberFee($anonym2, $now);
     DbEntityHelper::fireReceivedMemberFee($anonym1, $now);
     DbEntityHelper::fireReceivedMemberFee($FRANZ_l3_1, $now);
     // the following order does matter. ALF has to be the third so that
     // MYSELF does not receive anynthing from his advertisings
     DbEntityHelper::fireReceivedMemberFee($DEAN_l2_1, $now);
     DbEntityHelper::fireReceivedMemberFee($EMI_l2_2, $now);
     DbEntityHelper::fireReceivedMemberFee($ALF_l2_3, $now);
     DbEntityHelper::fireReceivedMemberFee($bea_l1_2, $now);
     DbEntityHelper::fireReceivedMemberFee($far_l1_1, $now);
     // ---- assert - correct reserved paid events count
     $this->assertEquals(ReservedPaidEventQuery::create()->count(), 11);
     // ---- assert - ME got 10 since chris has not paid yet
     $MYSELF_total_before = new TransactionTotalsAssertions($MYSELF, $this);
     $MYSELF_total_before->add(Transaction::REASON_ADVERTISED_LVL1, 2);
     $MYSELF_total_before->assertTotals();
     // ---- assert - chris pais now as least. this trigger all remaining
     // reserved paid events
     DbEntityHelper::fireReceivedMemberFee($CHRIS_l1_3, $now);
     $this->assertEquals($MYSELF->getFundsLevel(), Member::FUNDS_LEVEL2);
     $this->assertEquals(ReservedPaidEventQuery::create()->count(), 0);
     // ---- assert - CHRIS - should be 90 euro
     $CHRIS_total->assertTotals();
     // ---- assert - ME
     $MYSELF_total->assertTotals();
 }
 public function testFixRecursiveIndirectBonusSpreading()
 {
     $promoter1 = DbEntityHelper::createMember(null, ['LastName' => 'promoter1', 'FundsLevel' => \Member::FUNDS_LEVEL2]);
     $S1 = DbEntityHelper::createSignupMember($promoter1, true, ['lastName' => 'S1']);
     $S2 = DbEntityHelper::createSignupMember($S1, true, ['lastName' => 'S2']);
     $S3 = DbEntityHelper::createSignupMember($S2, true, ['lastName' => 'S3']);
     $S4 = DbEntityHelper::createSignupMember($S3, true, ['lastName' => 'S4']);
     // DbEntityHelper::createSignupMember($egal);
     $promoter1_total = new TransactionTotalsAssertions($promoter1, $this);
     $S1_total = new TransactionTotalsAssertions($S1, $this);
     $S2_total = new TransactionTotalsAssertions($S2, $this);
     $S3_total = new TransactionTotalsAssertions($S3, $this);
     $S4_total = new TransactionTotalsAssertions($S4, $this);
     // Zahlung s1
     $promoter1_total->add(Transaction::REASON_ADVERTISED_LVL2);
     // zahlung s2
     $promoter1_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $S1_total->add(Transaction::REASON_ADVERTISED_LVL1);
     // zahlung s3
     $promoter1_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $S2_total->add(Transaction::REASON_ADVERTISED_LVL1);
     // zahlung s4
     $promoter1_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $S3_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $promoter1_total->assertTotals();
     $S1_total->assertTotals();
     $S2_total->assertTotals();
     $S3_total->assertTotals();
 }
 public function testBuildCurrentCompleteUseCase()
 {
     // @see resources/docs/Test 13.04.2016.docx
     //
     $CEO = Member::getByNum(\SystemStats::ACCOUNT_NUM_CEO1);
     $CEO_total = new TransactionTotalsAssertions($CEO, $this);
     $this->totals['CEO1'] = $CEO_total;
     $sylvheim = Member::getByNum(\SystemStats::ACCOUNT_SYLVHEIM);
     $sylvheim_total = new TransactionTotalsAssertions($sylvheim, $this);
     $this->totals['sylvheim'] = $sylvheim_total;
     /**
      * director 01
      *
      */
     $director1 = DbEntityHelper::createMemberWithInvitation($sylvheim, ['type' => \Member::TYPE_MARKETINGLEADER, 'free_signup' => 1], ['firstName' => 'Director', 'lastName' => '01']);
     $director1_total = new TransactionTotalsAssertions($director1, $this);
     $this->totals['director1'] = $director1_total;
     $this->assertTotals();
     /**
      * Spender 01
      */
     $spender01 = DbEntityHelper::createSignupMember($director1, true, ['firstName' => 'spender', 'lastName' => '01']);
     $spender01_total = new TransactionTotalsAssertions($spender01, $this);
     $this->totals['spender01'] = $spender01_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director1_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $director1_total->add(Transaction::REASON_PM_BONUS);
     $director1_total->add(Transaction::REASON_VL_BONUS);
     $director1_total->add(Transaction::REASON_OL_BONUS);
     $this->assertTotals();
     /**
      * Spender 02
      *
      * director 1 gets level 2
      */
     $spender02 = DbEntityHelper::createSignupMember($director1, true, ['firstName' => 'spender', 'lastName' => '02']);
     $spender02_total = new TransactionTotalsAssertions($spender02, $this);
     $this->totals['spender02'] = $spender02_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director1_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $director1_total->add(Transaction::REASON_PM_BONUS);
     $director1_total->add(Transaction::REASON_VL_BONUS);
     $director1_total->add(Transaction::REASON_OL_BONUS);
     $this->assertTotals();
     /**
      * Spender 03
      */
     $spender03 = DbEntityHelper::createSignupMember($spender02, true, ['firstName' => 'spender', 'lastName' => '03']);
     $spender03_total = new TransactionTotalsAssertions($spender03, $this);
     $this->totals['spender03'] = $spender03_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender02_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 04
      */
     $spender04 = DbEntityHelper::createSignupMember($spender03, true, ['firstName' => 'spender', 'lastName' => '04']);
     $spender04_total = new TransactionTotalsAssertions($spender04, $this);
     $this->totals['spender04'] = $spender04_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender03_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 05
      */
     $spender05 = DbEntityHelper::createSignupMember($spender04, true, ['firstName' => 'spender', 'lastName' => '05']);
     $spender05_total = new TransactionTotalsAssertions($spender05, $this);
     $this->totals['spender05'] = $spender05_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender04_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 06
      */
     $spender06 = DbEntityHelper::createSignupMember($spender05, true, ['firstName' => 'spender', 'lastName' => '06']);
     $spender06_total = new TransactionTotalsAssertions($spender06, $this);
     $this->totals['spender06'] = $spender06_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender05_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 07
      */
     $spender07 = DbEntityHelper::createSignupMember($spender01, true, ['firstName' => 'spender', 'lastName' => '07']);
     $spender07_total = new TransactionTotalsAssertions($spender07, $this);
     $this->totals['spender07'] = $spender07_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender01_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 08
      */
     $spender08 = DbEntityHelper::createSignupMember($spender07, true, ['firstName' => 'spender', 'lastName' => '08']);
     $spender08_total = new TransactionTotalsAssertions($spender08, $this);
     $this->totals['spender08'] = $spender08_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender07_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 09
      */
     $spender09 = DbEntityHelper::createSignupMember($spender08, true, ['firstName' => 'spender', 'lastName' => '09']);
     $spender09_total = new TransactionTotalsAssertions($spender09, $this);
     $this->totals['spender09'] = $spender09_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender08_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 10
      */
     $spender10 = DbEntityHelper::createSignupMember($spender09, true, ['firstName' => 'spender', 'lastName' => '10']);
     $spender10_total = new TransactionTotalsAssertions($spender10, $this);
     $this->totals['spender10'] = $spender10_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $spender09_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender 11
      */
     $spender11 = DbEntityHelper::createSignupMember($director1, true, ['firstName' => 'spender', 'lastName' => '11']);
     $spender11_total = new TransactionTotalsAssertions($spender11, $this);
     $this->totals['spender11'] = $spender11_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director1_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $director1_total->add(Transaction::REASON_PM_BONUS);
     $director1_total->add(Transaction::REASON_VL_BONUS);
     $director1_total->add(Transaction::REASON_OL_BONUS);
     $this->assertTotals();
     /**
      * promoter 01
      * free invitation, no bonuses
      */
     $promoter01 = DbEntityHelper::createMemberWithInvitation($director1, ['type' => \Member::TYPE_PROMOTER, 'free_signup' => 1], ['firstName' => 'promoter', 'lastName' => '01']);
     $promoter01_total = new TransactionTotalsAssertions($promoter01, $this);
     $this->totals['promoter01'] = $promoter01_total;
     $this->assertTotals();
     /**
      * Spender 12
      */
     $spender12 = DbEntityHelper::createSignupMember($promoter01, true, ['firstName' => 'spender', 'lastName' => '12']);
     $spender12_total = new TransactionTotalsAssertions($spender12, $this);
     $this->totals['spender12'] = $spender12_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director1_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $director1_total->add(Transaction::REASON_VL_BONUS);
     $director1_total->add(Transaction::REASON_OL_BONUS);
     $promoter01_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $promoter01_total->add(Transaction::REASON_PM_BONUS);
     $this->assertTotals();
     /**
      * promoter 02
      */
     $promoter02 = DbEntityHelper::createMemberWithInvitation($director1, ['type' => \Member::TYPE_PROMOTER], ['firstName' => 'promoter', 'lastName' => '02']);
     $promoter02_total = new TransactionTotalsAssertions($promoter02, $this);
     $this->totals['promoter02'] = $promoter02_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director1_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $director1_total->add(Transaction::REASON_VL_BONUS);
     $director1_total->add(Transaction::REASON_OL_BONUS);
     $director1_total->add(Transaction::REASON_PM_BONUS);
     $this->assertTotals();
     /**
      * Spender 13
      */
     $spender13 = DbEntityHelper::createSignupMember($promoter02, true, ['firstName' => 'spender', 'lastName' => '13']);
     $spender13_total = new TransactionTotalsAssertions($spender13, $this);
     $this->totals['spender13'] = $spender13_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director1_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $director1_total->add(Transaction::REASON_VL_BONUS);
     $director1_total->add(Transaction::REASON_OL_BONUS);
     $promoter02_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $promoter02_total->add(Transaction::REASON_PM_BONUS);
     $this->assertTotals();
     /**
      * ol 01
      * free invitation, no bonuses
      */
     $ol01 = DbEntityHelper::createMemberWithInvitation($director1, ['type' => \Member::TYPE_ORGLEADER, 'free_signup' => 1], ['firstName' => 'ol', 'lastName' => '02']);
     $ol01_total = new TransactionTotalsAssertions($ol01, $this);
     $this->totals['ol01'] = $ol01_total;
     $this->assertTotals();
     // We need to stop here because the ol is not allowed to invitate before
     // becomming level 2
     // return;
     // /**
     //  * promoter 03
     //  */
     // $promoter03 = DbEntityHelper::createMemberWithInvitation($ol01, [
     //     'type' => \Member::TYPE_PROMOTER,
     //     'free_signup' => 1
     // ], [
     //     'firstName' => 'promoter',
     //     'lastName' => '03'
     // ]);
     // $promoter03_total = new TransactionTotalsAssertions($promoter03, $this);
     // $this->totals['promoter03'] = $promoter03_total;
     // $this->assertTotals();
     // /**
     //  * Spender 14
     //  */
     // $spender14 = DbEntityHelper::createSignupMember($promoter03, true, [
     //     'firstName' => 'spender',
     //     'lastName' => '14'
     // ]);
     // $spender14_total = new TransactionTotalsAssertions($spender14, $this);
     // $this->totals['spender14'] = $spender14_total;
     // $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     // $director1_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     // $director1_total->add(Transaction::REASON_VL_BONUS);
     // $director1_total->add(Transaction::REASON_OL_BONUS);
     // $promoter03_total->add(Transaction::REASON_ADVERTISED_LVL1);
     // $promoter03_total->add(Transaction::REASON_PM_BONUS);
     // $this->assertTotals();
     /**
      * CEO Tree beginns here
      */
     /**
      * Spender I.
      */
     $spenderI = DbEntityHelper::createSignupMember($CEO, true, ['firstName' => 'spender', 'lastName' => 'I.']);
     $spenderI_total = new TransactionTotalsAssertions($spenderI, $this);
     $this->totals['spenderI'] = $spenderI_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $CEO_total->add(Transaction::REASON_SYLVHEIM);
     $CEO_total->add(Transaction::REASON_VL_BONUS);
     $CEO_total->add(Transaction::REASON_OL_BONUS);
     $CEO_total->add(Transaction::REASON_PM_BONUS);
     $CEO_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $this->assertTotals();
     /**
      * director I.
      *
      */
     $directorI = DbEntityHelper::createMemberWithInvitation($CEO, ['type' => \Member::TYPE_MARKETINGLEADER, 'free_signup' => 1], ['firstName' => 'Director', 'lastName' => 'I']);
     $directorI_total = new TransactionTotalsAssertions($directorI, $this);
     $this->totals['directorI'] = $directorI_total;
     $this->assertTotals();
     /**
      * Spender II
      */
     $spenderII = DbEntityHelper::createSignupMember($directorI, true, ['firstName' => 'spender', 'lastName' => 'II']);
     $spenderII_total = new TransactionTotalsAssertions($spenderII, $this);
     $this->totals['spenderII'] = $spenderII_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $CEO_total->add(Transaction::REASON_SYLVHEIM);
     $CEO_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $directorI_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $directorI_total->add(Transaction::REASON_VL_BONUS);
     $directorI_total->add(Transaction::REASON_OL_BONUS);
     $directorI_total->add(Transaction::REASON_PM_BONUS);
     $this->assertTotals();
     /**
      * Spender III
      */
     $spenderIII = DbEntityHelper::createSignupMember($spenderII, true, ['firstName' => 'spender', 'lastName' => 'III']);
     $spenderIII_total = new TransactionTotalsAssertions($spenderIII, $this);
     $this->totals['spenderIII'] = $spenderIII_total;
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $CEO_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $CEO_total->add(Transaction::REASON_SYLVHEIM);
     $CEO_total->add(Transaction::REASON_VL_BONUS);
     $CEO_total->add(Transaction::REASON_OL_BONUS);
     $CEO_total->add(Transaction::REASON_PM_BONUS);
     $spenderII_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $this->assertTotals();
     /**
      * Spender IV.
      */
     $spenderIV = DbEntityHelper::createSignupMember($CEO, true, ['firstName' => 'spender', 'lastName' => 'IV']);
     $spenderIV_total = new TransactionTotalsAssertions($spenderIV, $this);
     $this->totals['spenderIV'] = $spenderIV_total;
     $CEO_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $CEO_total->add(Transaction::REASON_CEO1_BONUS);
     $CEO_total->add(Transaction::REASON_SYLVHEIM);
     $CEO_total->add(Transaction::REASON_VL_BONUS);
     $CEO_total->add(Transaction::REASON_OL_BONUS);
     $CEO_total->add(Transaction::REASON_PM_BONUS);
     $this->assertTotals();
 }
 public function test_105_director_marketingleader_promoter()
 {
     $sylvheim = Member::getByNum(\SystemStats::ACCOUNT_SYLVHEIM);
     $sylvheim_total = new TransactionTotalsAssertions($sylvheim, $this);
     $this->assertEquals(Member::FUNDS_LEVEL2, $sylvheim->getFundsLevel());
     /* advertise director
        ---------------------------------------------*/
     $director = DbEntityHelper::createMemberWithInvitation($sylvheim, Member::TYPE_MARKETINGLEADER);
     $director_total = new TransactionTotalsAssertions($director, $this);
     $this->assertEquals(0, $director->getAdvertisedCount());
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_LVL2);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $sylvheim_total->add(Transaction::REASON_PM_BONUS);
     $sylvheim_total->assertTotals();
     /* director advertise orgleader
        ---------------------------------------------*/
     $orgleader = DbEntityHelper::createMemberWithInvitation($director, Member::TYPE_ORGLEADER);
     $orgleader_total = new TransactionTotalsAssertions($orgleader, $this);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $director_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $director_total->add(Transaction::REASON_VL_BONUS);
     $director_total->add(Transaction::REASON_OL_BONUS);
     $director_total->add(Transaction::REASON_PM_BONUS);
     // $orgleader wird sylvheim nachgestellt
     $this->assertEquals($orgleader->getParentId(), $sylvheim->getId());
     $sylvheim_total->assertTotals();
     $director_total->assertTotals();
     $this->assertEquals(1, $director->getAdvertisedCount());
     $this->assertEquals(Member::FUNDS_LEVEL1, $director->getFundsLevel());
     /* orgleader advertise promoter
        ---------------------------------------------*/
     $promoter = DbEntityHelper::createMemberWithInvitation($orgleader, Member::TYPE_PROMOTER);
     $promoter_total = new TransactionTotalsAssertions($promoter, $this);
     $this->assertEquals(1, $director->getAdvertisedCount());
     $this->assertEquals(Member::FUNDS_LEVEL1, $director->getFundsLevel());
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $orgleader_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $orgleader_total->add(Transaction::REASON_OL_BONUS);
     $orgleader_total->add(Transaction::REASON_PM_BONUS);
     // $promoter wird sylvheim nachgestellt
     $this->assertEquals($promoter->getParentId(), $sylvheim->getId());
     $sylvheim_total->assertTotals();
     $director_total->assertTotals();
     $orgleader_total->assertTotals();
     /* promoter advertise member
        ---------------------------------------------*/
     $donator = DbEntityHelper::createSignupMember($promoter);
     $sylvheim_total->add(Transaction::REASON_ADVERTISED_INDIRECT);
     $sylvheim_total->add(Transaction::REASON_SYLVHEIM);
     $sylvheim_total->add(Transaction::REASON_VL_BONUS);
     $sylvheim_total->add(Transaction::REASON_OL_BONUS);
     $promoter_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $promoter_total->add(Transaction::REASON_PM_BONUS);
     $this->assertEquals($donator->getParentId(), $sylvheim->getId());
     $sylvheim_total->assertTotals();
     $director_total->assertTotals();
     $orgleader_total->assertTotals();
     $promoter_total->assertTotals();
 }
 public function testSingleDistributionModel()
 {
     /* Setup
        ---------------------------------------------*/
     $systemAccount = SystemStats::getSystemAccount();
     $systemTransfer = new TransactionTotalsAssertions($systemAccount, $this);
     $promoter1 = DbEntityHelper::createMember();
     $MYSELF = DbEntityHelper::createSignupMember($promoter1);
     $this->assertEquals($MYSELF->getFundsLevel(), Member::FUNDS_LEVEL1);
     /* Advertise 2 users
        ---------------------------------------------*/
     $far_l1_1 = DbEntityHelper::createSignupMember($MYSELF);
     $bea_l1_2 = DbEntityHelper::createSignupMember($MYSELF);
     // Funds level never changes
     $this->assertEquals($MYSELF->getFundsLevel(), Member::FUNDS_LEVEL1);
     $MYSELF_total = new TransactionTotalsAssertions($MYSELF, $this);
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL1, 2);
     $MYSELF_total->assertTotals();
     /* Advertise 1 more user - chris
        ---------------------------------------------*/
     $CHRIS_l1_3 = DbEntityHelper::createSignupMember($MYSELF);
     // ---- assert - ME
     $MYSELF_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $MYSELF_total->assertTotals();
     /* chris advertise 1 user - dean
        ---------------------------------------------*/
     $DEAN_l2_1 = DbEntityHelper::createSignupMember($CHRIS_l1_3);
     // ---- assert - CHRIS
     $CHRIS_transfer = DbEntityHelper::getCurrentTransferBundle($CHRIS_l1_3);
     $CHRIS_total = new TransactionTotalsAssertions($CHRIS_l1_3, $this);
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $CHRIS_total->assertTotals();
     // ---- assert - ME
     // unchanged
     $MYSELF_total->assertTotals();
     /* chris advertise 1 user - emi
        ---------------------------------------------*/
     $EMI_l2_2 = DbEntityHelper::createSignupMember($CHRIS_l1_3);
     // ---- assert - CHRIS
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $CHRIS_total->assertTotals();
     $this->assertEquals($CHRIS_l1_3->getFundsLevel(), Member::FUNDS_LEVEL1);
     // ---- assert - ME
     // unchanged
     $MYSELF_total->assertTotals();
     /* dean advertise 1 user - franz
        ---------------------------------------------*/
     $FRANZ_l3_1 = DbEntityHelper::createSignupMember($DEAN_l2_1);
     // ---- assert - CHRIS - remain at 10 euro
     $CHRIS_total->assertTotals();
     // ---- assert - ME
     // unchanged
     $MYSELF_total->assertTotals();
     DbEntityHelper::createSignupMember($DEAN_l2_1);
     DbEntityHelper::createSignupMember($EMI_l2_2);
     DbEntityHelper::createSignupMember($EMI_l2_2);
     $CHRIS_total->add(Transaction::REASON_ADVERTISED_LVL1);
     $ALF_l2_3 = DbEntityHelper::createSignupMember($CHRIS_l1_3);
     $GUST_l3_1 = DbEntityHelper::createSignupMember($ALF_l2_3);
     DbEntityHelper::createSignupMember($ALF_l2_3);
     // ---- assert - CHRIS - at 60 euro
     $CHRIS_total->assertTotals();
     // ---- assert - ME
     // unchanged
     $MYSELF_total->assertTotals();
     DbEntityHelper::createSignupMember($GUST_l3_1);
     DbEntityHelper::createSignupMember($GUST_l3_1);
     // ---- assert - CHRIS - at 90 euro
     // unchanged
     $CHRIS_total->assertTotals();
     /* if anyone advertised more than 2 user i dont get anything from the third on
        ---------------------------------------------*/
     DbEntityHelper::createSignupMember($CHRIS_l1_3);
     DbEntityHelper::createSignupMember($CHRIS_l1_3);
     DbEntityHelper::createSignupMember($CHRIS_l1_3);
     DbEntityHelper::createSignupMember($GUST_l3_1);
     DbEntityHelper::createSignupMember($GUST_l3_1);
     DbEntityHelper::createSignupMember($GUST_l3_1);
     DbEntityHelper::createSignupMember($ALF_l2_3);
     DbEntityHelper::createSignupMember($ALF_l2_3);
     DbEntityHelper::createSignupMember($ALF_l2_3);
     DbEntityHelper::createSignupMember($EMI_l2_2);
     DbEntityHelper::createSignupMember($EMI_l2_2);
     /* as well, i dont get anything but 5euro from my first advertisings
        ---------------------------------------------*/
     DbEntityHelper::createSignupMember($bea_l1_2);
     DbEntityHelper::createSignupMember($bea_l1_2);
     DbEntityHelper::createSignupMember($bea_l1_2);
     // ---- assert - MYSELF
     $MYSELF_total->assertTotals();
 }
 public function testTopLevelBonusSpreading()
 {
     $ceo = Member::getByNum(\SystemStats::ACCOUNT_NUM_CEO1);
     $it = Member::getByNum(\SystemStats::ACCOUNT_NUM_IT);
     $sylvheim = Member::getByNum(\SystemStats::ACCOUNT_SYLVHEIM);
     $executive = Member::getByNum(\SystemStats::ACCOUNT_EXECUTIVE);
     $ceo_total = new TransactionTotalsAssertions($ceo, $this);
     $it_total = new TransactionTotalsAssertions($it, $this);
     $sylvheim_total = new TransactionTotalsAssertions($sylvheim, $this);
     $executive_total = new TransactionTotalsAssertions($executive, $this);
     // Any advertise any
     $any = DbEntityHelper::createSignupMember($executive);
     $ceo_total->add(Transaction::REASON_CEO1_BONUS, 1);
     $ceo_total->add(Transaction::REASON_VL_BONUS, 1);
     $ceo_total->add(Transaction::REASON_OL_BONUS, 1);
     $ceo_total->add(Transaction::REASON_PM_BONUS, 1);
     $ceo_total->add(Transaction::REASON_SYLVHEIM, 1);
     $it_total->add(Transaction::REASON_IT_BONUS, 1);
     // Sylvhelm gets nothing here!
     $ceo_total->assertTotals();
     $it_total->assertTotals();
     $sylvheim_total->assertTotals();
 }