Ejemplo n.º 1
0
 /**
  * Store created pay
  *
  * @param Request $request
  *
  * @return array
  *
  * @throws \Exception
  */
 public function store(Request $request)
 {
     $op = new PayOperation();
     $op->amount = $request->input('amount');
     $op->type = $request->input('type');
     $op->requestor_id = Auth::id();
     if ($op->save()) {
         return redirect('/pays');
     } else {
         return redirect('/pays/create')->withErrors($op->getValidator());
     }
 }
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());
     $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);
 }