1
|
|
|
<?php |
2
|
|
|
require __DIR__ . "/assets/config.php"; |
3
|
|
|
require __DIR__ . "/../vendor/autoload.php"; |
4
|
|
|
|
5
|
|
|
use WorkCode\SyncWiseApi\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_FULL_SPECIAL_CHARS); |
|
|
|
|
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"); ?>" placeholder="description | Ex: By Component"/> |
72
|
|
|
<input type="text" name="type" value="<?= $value("type"); ?>" placeholder="type | Ex: income"/> |
73
|
|
|
<input type="text" name="value" value="<?= $value("value"); ?>" placeholder="value | Ex: 2500.10"/> |
74
|
|
|
<input type="text" name="due_at" value="<?= $value("due_at"); ?>" placeholder="due_at | Ex: 2019-02-20"/> |
75
|
|
|
<input type="text" name="repeat_when" value="<?= $value("repeat_when"); ?>" placeholder="repeat_when | Ex: single"/> |
76
|
|
|
<input type="text" name="period" value="<?= $value("period"); ?>" placeholder="period | Ex: month"/> |
77
|
|
|
<input type="text" name="enrollments" value="<?= $value("enrollments"); ?>" placeholder="enrollments | Ex: 1"/> |
78
|
|
|
<button>Cadastrar</button> |
79
|
|
|
</form> |
80
|
|
|
<?php |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* READ |
84
|
|
|
*/ |
85
|
|
|
echo "<h1>READ</h1>"; |
86
|
|
|
|
87
|
|
|
$invoice = $invoices->read(855); |
88
|
|
|
$invoice = $invoices->read(91); |
89
|
|
|
|
90
|
|
|
if ($invoice->error()) { |
91
|
|
|
echo "<p class='error'>{$invoice->error()->message}</p>"; |
92
|
|
|
} else { |
93
|
|
|
$invoiceData = $invoice->response()->invoice; |
94
|
|
|
var_dump( |
95
|
|
|
$invoiceData, |
96
|
|
|
$invoiceData->wallet |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* UPDATE |
102
|
|
|
*/ |
103
|
|
|
echo "<h1>UPDATE</h1>"; |
104
|
|
|
|
105
|
|
|
$invoiceId = 91; |
106
|
|
|
$invoiceUpdate = $invoices->read($invoiceId); |
107
|
|
|
|
108
|
|
|
if ($invoiceUpdate->error()) { |
109
|
|
|
echo "<p class='error'>{$invoiceUpdate->error()->message}</p>"; |
110
|
|
|
} else { |
111
|
|
|
$update = filter_input_array(INPUT_POST, FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
112
|
|
|
|
113
|
|
|
if ($update && !empty($update["update"])) { |
114
|
|
|
$invoiceUpdate->update($invoiceId, $update); |
115
|
|
|
|
116
|
|
|
if ($invoiceUpdate->error()) { |
117
|
|
|
echo "<p class='error'>{$invoiceUpdate->error()->message}</p>"; |
118
|
|
|
} else { |
119
|
|
|
var_dump($invoiceUpdate->response()->invoice); |
120
|
|
|
} |
121
|
|
|
} else { |
122
|
|
|
$update = null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$data = $invoiceUpdate->read($invoiceId)->response()->invoice; |
126
|
|
|
$value = function($value) use ($data) { |
127
|
|
|
return (!empty($data->$value) ? $data->$value : null); |
128
|
|
|
}; |
129
|
|
|
?> |
130
|
|
|
|
131
|
|
|
<form action="" method="post"> |
132
|
|
|
<input type="hidden" name="update" value="true"/> |
133
|
|
|
<input type="text" name="wallet_id" value="<?= $value("wallet_id"); ?>"/> |
134
|
|
|
<input type="text" name="category_id" value="<?= $value("category_id"); ?>"/> |
135
|
|
|
<input type="text" name="description" value="<?= $value("description"); ?>"/> |
136
|
|
|
<input type="text" name="value" value="<?= $value("value"); ?>"/> |
137
|
|
|
<input type="text" name="due_day" value="<?= date("d", strtotime($value("due_at"))); ?>"/> |
138
|
|
|
<input type="text" name="status" value="<?= $value("status"); ?>"/> |
139
|
|
|
<button>Atualizar</button> |
140
|
|
|
</form> |
141
|
|
|
<?php |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* DELETE |
146
|
|
|
*/ |
147
|
|
|
echo "<h1>DELETE</h1>"; |
148
|
|
|
|
149
|
|
|
$delete = $invoices->delete(91); |
150
|
|
|
if ($delete->error()) { |
151
|
|
|
echo "<p class='error'>{$delete->error()->message}</p>"; |
152
|
|
|
} else { |
153
|
|
|
echo "<p>Lançamento foi excluído com sucesso!</p>"; |
154
|
|
|
} |