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(); }
/** * Delete this member and adopt his children to his referer. * Calling onReceivedMemberFee. * * @param PropelPDO $con * @return */ public function deleteAndUpdateTree(PropelPDO $con) { $children = MemberQuery::create()->filterByRefererId($this->getId())->find($con); $thisReferer = $this->getMemberRelatedByRefererId(); $thisRefererHadPaid = $thisReferer->hadPaid(); $updateCount = ReservedPaidEventQuery::create()->filterByUnpaidId($this->getId())->update(['UnpaidId' => $thisReferer->getId()], $con); foreach ($children as $child) { $child->setRefererMember($thisReferer, $con); $child->save($con); } if ($updateCount > 0) { $thisReferer->fireReservedReceivedMemberFeeEvents($con); $thisReferer->save($con); } $this->setDeletionDate(time()); $this->save($con); }