Dodaj nowe akcje API do zarządzania kategoriami finansów i operacjami finansowymi

This commit is contained in:
2026-01-21 01:07:02 +01:00
parent ac04805906
commit dc8c428f5a
2 changed files with 46 additions and 544 deletions

40
api.php
View File

@@ -82,5 +82,45 @@ if ( \S::get( 'action' ) == 'domain_opr_save' )
] );
echo json_encode( ['result' => 'ok'] );
exit;
}
if ( \S::get( 'action' ) == 'get_finances_categories' )
{
$rows = $mdb -> select( 'finance_categories', '*', [ 'parent_id' => null, 'ORDER' => [ 'name' => 'ASC' ] ] );
foreach ( $rows as $row )
{
$categories[] = [
'id' => $row['id'],
'name' => $row['name'],
'subcategories' => $mdb -> select( 'finance_categories', '*', [ 'parent_id' => $row['id'], 'ORDER' => [ 'name' => 'ASC' ] ] )
];
}
echo json_encode( $categories );
exit;
}
echo 'a';
if ( \S::get( 'action' ) == 'add_finance_operation' )
{
if ( !\S::get( 'operation_date' ) || !\S::get( 'net_value' ) || !\S::get( 'product_name' ) || !\S::get( 'category_id' ) )
{
echo json_encode( [ 'result' => 'error' ] );
exit;
}
$data = [
'date' => \S::get( 'operation_date' ),
'amount' => str_replace( ',', '.', \S::get( 'net_value' ) ),
'description' => \S::get( 'product_name' ),
'category_id' => \S::get( 'category_id' ),
];
if ( $mdb -> insert( 'finance_operations', $data ) ) {
$operation_id = $mdb -> id();
echo json_encode( [ 'result' => 'ok', 'operation_id' => $operation_id ] );
} else {
echo json_encode( [ 'result' => 'error' ] );
}
exit;
}