1
|
|
|
<?php |
2
|
|
|
require __DIR__ . "/assets/config.php"; |
3
|
|
|
require __DIR__ . "/../vendor/autoload.php"; |
4
|
|
|
|
5
|
|
|
use RobsonVLeite\CafeApi\Invoices; |
|
|
|
|
6
|
|
|
|
7
|
|
|
$invoices = new Invoices( |
8
|
|
|
"localhost/fsphp/cafeapi/", |
9
|
|
|
"[email protected]", |
10
|
|
|
"12345678" |
11
|
|
|
); |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* index |
15
|
|
|
*/ |
16
|
|
|
echo "<h1>INDEX</h1>"; |
17
|
|
|
|
18
|
|
|
$index = $invoices->index(null); |
19
|
|
|
$index = $invoices->index([ |
20
|
|
|
"wallet_id" => 23, |
21
|
|
|
"type" => "fixed_income", |
22
|
|
|
"status" => "paid", |
23
|
|
|
"page" => 2 |
24
|
|
|
]); |
25
|
|
|
|
26
|
|
|
if ($index->error()) { |
27
|
|
|
echo "<p class='error'>{$index->error()->message}</p>"; |
28
|
|
|
} else { |
29
|
|
|
foreach ($index->response()->invoices as $invoice) { |
30
|
|
|
echo "<p>{$invoice->description} {$invoice->value}</p>"; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
var_dump( |
34
|
|
|
[ |
35
|
|
|
"results" => $index->response()->results, |
36
|
|
|
"page" => $index->response()->page, |
37
|
|
|
"pages" => $index->response()->pages, |
38
|
|
|
], |
39
|
|
|
$index->response()->invoices |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* create |
45
|
|
|
*/ |
46
|
|
|
echo "<h1>CREATE</h1>"; |
47
|
|
|
|
48
|
|
|
$create = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRIPPED); |
49
|
|
|
if ($create && !empty($create["create"])) { |
50
|
|
|
$invoiceCreate = $invoices->create($create); |
51
|
|
|
|
52
|
|
|
if ($invoiceCreate->error()) { |
53
|
|
|
echo "<p class='error'>{$invoiceCreate->error()->message}</p>"; |
54
|
|
|
} else { |
55
|
|
|
$create = null; |
56
|
|
|
var_dump($invoiceCreate->response()->invoice); |
57
|
|
|
} |
58
|
|
|
} else { |
59
|
|
|
$create = null; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$value = function ($value) use ($create) { |
63
|
|
|
return (!empty($create[$value]) ? $create[$value] : null); |
64
|
|
|
}; |
65
|
|
|
|
66
|
|
|
?> |
67
|
|
|
<form action="" method="post"> |
68
|
|
|
<input type="hidden" name="create" value="true"/> |
69
|
|
|
<input type="text" name="wallet_id" value="<?= $value("wallet_id"); ?>" placeholder="wallet_id | Ex: 23"/> |
70
|
|
|
<input type="text" name="category_id" value="<?= $value("category_id"); ?>" placeholder="category_id | Ex: 3"/> |
71
|
|
|
<input type="text" name="description" value="<?= $value("description"); ?>" |
72
|
|
|
placeholder="description | Ex: By Component"/> |
73
|
|
|
<input type="text" name="type" value="<?= $value("type"); ?>" placeholder="type | Ex: income"/> |
74
|
|
|
<input type="text" name="value" value="<?= $value("value"); ?>" placeholder="value | Ex: 2500.10"/> |
75
|
|
|
<input type="text" name="due_at" value="<?= $value("due_at"); ?>" placeholder="due_at | Ex: 2019-02-20"/> |
76
|
|
|
<input type="text" name="repeat_when" value="<?= $value("repeat_when"); ?>" |
77
|
|
|
placeholder="repeat_when | Ex: single"/> |
78
|
|
|
<input type="text" name="period" value="<?= $value("period"); ?>" placeholder="period | Ex: month"/> |
79
|
|
|
<input type="text" name="enrollments" value="<?= $value("enrollments"); ?>" placeholder="enrollments | Ex: 1"/> |
80
|
|
|
<button>Cadastrar</button> |
81
|
|
|
</form> |
82
|
|
|
<?php |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* READ |
86
|
|
|
*/ |
87
|
|
|
echo "<h1>READ</h1>"; |
88
|
|
|
|
89
|
|
|
$invoice = $invoices->read(855); |
90
|
|
|
$invoice = $invoices->read(91); |
91
|
|
|
|
92
|
|
|
if ($invoice->error()) { |
93
|
|
|
echo "<p class='error'>{$invoice->error()->message}</p>"; |
94
|
|
|
} else { |
95
|
|
|
$invoiceData = $invoice->response()->invoice; |
96
|
|
|
var_dump( |
97
|
|
|
$invoiceData, |
98
|
|
|
$invoiceData->wallet |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* UPDATE |
104
|
|
|
*/ |
105
|
|
|
echo "<h1>UPDATE</h1>"; |
106
|
|
|
|
107
|
|
|
$invoiceId = 91; |
108
|
|
|
$invoiceUpdate = $invoices->read($invoiceId); |
109
|
|
|
|
110
|
|
|
if ($invoiceUpdate->error()) { |
111
|
|
|
echo "<p class='error'>{$invoiceUpdate->error()->message}</p>"; |
112
|
|
|
} else { |
113
|
|
|
$update = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRIPPED); |
114
|
|
|
|
115
|
|
|
if ($update && !empty($update["update"])) { |
116
|
|
|
$invoiceUpdate->update($invoiceId, $update); |
117
|
|
|
|
118
|
|
|
if ($invoiceUpdate->error()) { |
119
|
|
|
echo "<p class='error'>{$invoiceUpdate->error()->message}</p>"; |
120
|
|
|
} else { |
121
|
|
|
var_dump($invoiceUpdate->response()->invoice); |
122
|
|
|
} |
123
|
|
|
} else { |
124
|
|
|
$update = null; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$data = $invoiceUpdate->read($invoiceId)->response()->invoice; |
128
|
|
|
$value = function ($value) use ($data) { |
129
|
|
|
return (!empty($data->$value) ? $data->$value : null); |
130
|
|
|
}; |
131
|
|
|
?> |
132
|
|
|
|
133
|
|
|
<form action="" method="post"> |
134
|
|
|
<input type="hidden" name="update" value="true"/> |
135
|
|
|
<input type="text" name="wallet_id" value="<?= $value("wallet_id"); ?>"/> |
136
|
|
|
<input type="text" name="category_id" value="<?= $value("category_id"); ?>"/> |
137
|
|
|
<input type="text" name="description" value="<?= $value("description"); ?>"/> |
138
|
|
|
<input type="text" name="value" value="<?= $value("value"); ?>"/> |
139
|
|
|
<input type="text" name="due_day" value="<?= date("d", strtotime($value("due_at"))); ?>"/> |
140
|
|
|
<input type="text" name="status" value="<?= $value("status"); ?>"/> |
141
|
|
|
<button>Atualizar</button> |
142
|
|
|
</form> |
143
|
|
|
<?php |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* DELETE |
148
|
|
|
*/ |
149
|
|
|
echo "<h1>DELETE</h1>"; |
150
|
|
|
|
151
|
|
|
$delete = $invoices->delete(91); |
152
|
|
|
if ($delete->error()) { |
153
|
|
|
echo "<p class='error'>{$delete->error()->message}</p>"; |
154
|
|
|
} else { |
155
|
|
|
echo "<p>Lançamento foi excluído com sucesso!</p>"; |
156
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths