-
Notifications
You must be signed in to change notification settings - Fork 7
/
LastPayments.php
70 lines (56 loc) · 1.76 KB
/
LastPayments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Crm\PaymentsModule\Components;
use Crm\ApplicationModule\Widget\BaseWidget;
use Crm\ApplicationModule\Widget\WidgetManager;
use Crm\PaymentsModule\Repository\PaymentsRepository;
class LastPayments extends BaseWidget
{
private $view = 'last_payments';
private $where = [];
private $limit;
/** @var PaymentsRepository */
private $paymentsRepository;
public function __construct(WidgetManager $widgetManager, PaymentsRepository $paymentsRepository)
{
parent::__construct($widgetManager);
$this->paymentsRepository = $paymentsRepository;
}
public function setUserId($userId)
{
$this->where['user_id'] = $userId;
return $this;
}
public function setPaymentGatewayId($paymentGatewayId)
{
$this->where['payment_gateway_id'] = $paymentGatewayId;
return $this;
}
public function setSubscriptionTypeId($subscriptionTypeId)
{
$this->where['subscription_type_id'] = $subscriptionTypeId;
return $this;
}
public function setSalesFunnelId($salesFunnelId)
{
$this->where['sales_funnel_id'] = $salesFunnelId;
return $this;
}
public function setLimit($limit)
{
$this->limit = $limit;
return $this;
}
public function render()
{
$payments = $this->paymentsRepository->all()->order('created_at DESC');
if (empty($this->where)) {
throw new \Exception('You cannot list all payments withou where');
}
$payments->where($this->where);
if ($this->limit) {
$payments->limit($this->limit);
}
$this->template->payments = $payments;
$this->template->setFile(__DIR__ . '/' . $this->view . '.latte')->render();
}
}