Ejemplo n.º 1
0
 /**
  * Testing 1 2 3...
  *
  * @return void
  */
 public function testAll()
 {
     $user = factory(User::class)->create();
     $up = new UserProperty();
     $up->user_id = $user->id;
     $up->key = UserProperty::KEY_TITHE_PERCENTAGE;
     $up->value = '10';
     $this->assertTrue($up->save());
     $op = new PayOperation();
     $op->amount = 5000;
     $op->type = Pay::TYPE_GATHERED;
     $op->requestor_id = $user->id;
     $this->assertTrue($op->save());
     $op->amount = 5000;
     $op->type = Pay::TYPE_GATHERED;
     $op->requestor_id = $user->id;
     $this->assertTrue($op->save());
     $uProps = $user->userProperties()->where('key', UserProperty::KEY_TITHE_PERCENTAGE)->first();
     // Check tithe percentage
     $this->assertNotNull($uProps);
     $this->assertEquals('10.1', $uProps->value);
     // Check tithe
     $tithe = $user->tithe;
     $this->assertNotNull($tithe);
     $this->assertEquals(1010, $tithe->amount);
     $this->assertEquals(10000, $tithe->pool_amount);
     // Check pays
     $pays = $user->pays;
     $this->assertNotNull($pays);
     $this->assertEquals(2, sizeof($pays));
     $this->assertEquals(5000, $pays[0]->amount);
     $this->assertEquals(5000, $pays[1]->amount);
     $this->assertEquals(Pay::TYPE_GATHERED, $pays[0]->type);
     $this->assertEquals(Pay::TYPE_GATHERED, $pays[1]->type);
     //Check credit
     $credit = $user->credit;
     $this->assertNotNull($credit);
     $this->assertEquals(10000, $credit->amount);
 }
Ejemplo n.º 2
0
 /**
  * Testing 1 2 3...
  *
  * @return void
  */
 public function testAll()
 {
     $user = factory(User::class)->create();
     $up = new UserProperty();
     $up->user_id = $user->id;
     $up->key = UserProperty::KEY_TITHE_PERCENTAGE;
     $up->value = '10';
     $this->assertTrue($up->save());
     $pay = new Pay();
     $pay->user_id = $user->id;
     $pay->amount = 5000;
     $this->assertTrue($pay->save());
     $tithe = new Tithe();
     $tithe->user_id = $user->id;
     $tithe->setPoolAmount($pay->amount);
     $tithe->setAmount();
     $tithe->status = Tithe::STATUS_STORED;
     $this->assertTrue($tithe->save());
     $tithe = Tithe::find($tithe->id);
     $this->assertNotNull($tithe);
     $this->assertEquals(5000, $tithe->pool_amount);
     $this->assertEquals(500, $tithe->amount);
 }
Ejemplo n.º 3
0
 public function setProperty($property, $value)
 {
     /** @var UserProperty $model */
     $model = UserProperty::findOne(['user_id' => $this->id, 'property' => $property]);
     if (is_null($model)) {
         $model = new UserProperty();
         $model->user_id = $this->id;
         $model->property = $property;
     }
     $model->value = $value;
     $model->save();
 }