/** Datei: plugins/products/library/ARUNOX/Plugins/Products/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\Services\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ // Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => "/products/services", "label" => "Leistungen", "icon" => "bi bi-gear-wide-connected", "menu" => "products", ]; return $routes; }); } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Services/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\Services\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Products; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Kontakt nicht gefunden", "saved" => "Kontakt wurde erfolgreich gespeichert", "deleted" => "Kontakt wurde erfolgreich gelöscht", "created" => "Kontakt wurde erfolgreich erstellt", "statuschanged.0" => "Kontakt wurde erfolgreich deaktiviert", "statuschanged.1" => "Kontakt wurde erfolgreich aktiviert", "notcreated" => "Kontakt konnte nicht erstellt werden", "notsaved" => "Kontakt konnte nicht gespeichert werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /contacts * @route.description Listet alle Kontakte */ public static function getAll() : array { return Products\Services\Model::getAll(); } /** * @api * @method GET * * @route.path /contacts/{hashid} * @route.description Gibt einen einzelnen Kontakts anhand der ID zurück */ public static function get( string $hashid ) : BaseEntity | HTTP\Response { if( $result = Products\Services\Model::get( $hashid ) ) return $result; return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /contacts/{hashid} * @route.description Speichert Änderungen an einem bestehenden Kontakts */ public static function save( string $hashid, array $data ) : HTTP\Response { if( $result = Products\Services\Model::get( $hashid ) ) { if( $result->save( $data ) ) { return REST\Response::autoResponse( 200, static::getNotify("saved") ); } return REST\Response::autoResponse( 500, static::getNotify("notsaved") ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method POST * * @route.path /contacts * @route.description Erstellt einen neuen Kontakt */ public static function create( array $data ) : HTTP\Response { if( $hashid = Products\Services\Model::save( $data ) ) { $result = Products\Services\Model::get( $hashid ); return REST\Response::autoResponse( 200, static::getNotify("created"), [ "data" => $result ] ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method DELETE * * @route.path /contacts/{hashid} * @route.description Löscht einen Kontakt anhand der ID */ public static function delete( string $hashid ) : HTTP\Response { if( Products\Services\Model::delete( $hashid ) ) { return REST\Response::autoResponse( 200, static::getNotify("deleted") ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /contacts/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Kontakts */ public static function toggleStatus( string $hashid ) : HTTP\Response { if( $result = Products\Services\Model::get( $hashid ) ) { $result->toggleStatus( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /contacts/{hashid}/invoice * @route.description Wechselt den Status (aktiv/inaktiv) eines Kontakts */ public static function toggleInvoice( string $hashid ) : HTTP\Response { if( $result = Products\Services\Model::get( $hashid ) ) { $result->toggleInvoice( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /contacts/{hashid} * @route.description REST-Antwort nach dem Speichern eines Kontakts */ public static function restResponseSave( string $hashid, array $data ) : HTTP\Response { $result = static::save( $hashid, $data ); if( $result->isStatus( 200 ) ) { $data = Products\Services\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /contacts * @route.description REST-Antwort nach dem Erstellen eines Kontakts (inkl. Notifikation, Redirect etc.) */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::create( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/contacts/{$result->getBody("data", "hashid")}" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /contacts/{hashid} * @route.description REST-Antwort nach dem Löschen eines Kontakts */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::delete( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/contacts" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /contacts/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Kontakts (z. B. für Notifications) */ public static function restResponseToggleStatus( string $hashid ) : HTTP\Response { $result = static::toggleStatus( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /contacts/{hashid}/invoice * @route.description REST-Antwort zur Status-Umschaltung eines Kontakts (z. B. für Notifications) */ public static function restResponseToggleInvoice( string $hashid ) : HTTP\Response { $result = static::toggleInvoice( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /contacts * @route.description REST-Konfiguration für Kontakt-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Kontakte" ) ->replaceContent( static::restConfigTable() ); } /** * @internal rest * @method GET * * @route.path /contacts/{hashid} * @route.alternative.0 /contacts/{hashid}#kontext * @route.alternative.1 /contacts/{hashid}#chat * @route.alternative.2 /contacts/{hashid}#telefon * @route.description REST-Konfiguration für Detailansicht eines Kontakts */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "details", "Kontakt bearbeiten" ) ->setBacklink( "/contacts" ) ->get() ->setApi( "/contacts/{$hashid}" ) ->setAction( "/contacts/{$hashid}", "PUT" ) ->addTab( "Kontakt" )->get() ->addHeadline( "Kontakt", 2 ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "company_name", FALSE, "contacts" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "firstname", FALSE, "contacts" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "lastname", FALSE, "contacts" )) ->parent() ->addTab( "Ansprechpartner" )->get() ->addContent( // Contacts\Contacts\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Adressen" )->get() ->addContent( // Contacts\Addresses\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /contacts/create * @route.description REST-Konfiguration für das Erstellen eines Kontakts (Formular) */ public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Kontakt erstellen" ) ->get() ->setAction( "/contacts", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "contacts" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "contacts" )); } /** * @internal rest * @method GET * * @route.path /contacts/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Kontakts */ public static function restConfigDelete( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Kontakt Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/contacts/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "contacts" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "contacts" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $table = REST\Generator\Data\Table::create() ->setApi( "/contacts" ) ->setAction( "/contacts/{hashid}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "contacts", "hashid" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ // "label" => Products\Services\Category::label(), // "icon" => Products\Services\Category::icon(), // "options" => Products\Services\Category::getAll(), // ], "category", [], "contacts", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "label" => Products\Services\Type::label(), "icon" => Products\Services\Type::icon(), "options" => Products\Services\Type::getAll(), ], "type", [], "contacts", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "company_name", TRUE, TRUE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "firstname", TRUE, TRUE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "lastname", TRUE, TRUE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "email", TRUE, TRUE, TRUE, "contacts" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ // "label" => Contacts\Reachability::label(), // "icon" => Contacts\Reachability::icon(), // "options" => Contacts\Reachability::getAll(), // ], "reachability", [], "contacts", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "contacts" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "contacts", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "contacts", "hashid" )) ; $buttons = $table->top()->getButtons(); foreach( Products\Services\Type::getAll() as $type ) { $type["name"] = "type"; $buttons->addDropdown( ...Hooks::filter( "rest.generator::button.name->create", $type, "contacts" ) ); } return $table; } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => "#", "path" => "/products", "label" => "Artikelstamm", "icon" => "bi bi-box-seam", "menu" => "content", // "name" => "products", ]; $routes[] = [ "path" => "/products", "label" => "Produkte", "icon" => "bi bi-list-ul", "menu" => "products", ]; return $routes; }); } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Products; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /products * @route.description Listet alle Produkte */ public static function getAllOwn( $args ) : array { if( isset( $args["type"] ) ) { return Products\Model::getAll([ "type" => $args["type"] ]); } return Products\Model::getAll(); } /** * @api * @method GET * * @route.path /products/{hashid} * @route.description Gibt einen einzelnen Produkts anhand der ID zurück */ public static function get( string $hashid ) : BaseEntity | HTTP\Response { if( $result = Products\Model::get( $hashid ) ) return $result; return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /products/{hashid} * @route.description Speichert Änderungen an einem bestehenden Produkts */ public static function save( string $hashid, array $data ) : HTTP\Response { if( $result = Products\Model::get( $hashid ) ) { if( $result->save( $data ) ) { return REST\Response::autoResponse( 200, static::getNotify("saved") ); } return REST\Response::autoResponse( 500, static::getNotify("notsaved") ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method POST * * @route.path /products * @route.description Erstellt einen neues Produkt */ public static function create( array $data ) : HTTP\Response { if( $hashid = Products\Model::save( $data ) ) { $result = Products\Model::get( $hashid ); return REST\Response::autoResponse( 200, static::getNotify("created" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method DELETE * * @route.path /products/{hashid} * @route.description Löscht ein Produkt anhand der ID */ public static function delete( string $hashid ) : HTTP\Response { if( Products\Model::delete( $hashid ) ) { return REST\Response::autoResponse( 200, static::getNotify("deleted") ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /products/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Produkts */ public static function toggleStatus( string $hashid ) : HTTP\Response { if( $result = Products\Model::get( $hashid ) ) { $result->toggleStatus( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /products/{hashid}/invoice * @route.description Wechselt den Status (aktiv/inaktiv) eines Produkts */ public static function toggleInvoice( string $hashid ) : HTTP\Response { if( $result = Products\Model::get( $hashid ) ) { $result->toggleInvoice( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /products/{hashid} * @route.description REST-Antwort nach dem Speichern eines Produkts */ public static function restResponseSave( string $hashid, array $data ) : HTTP\Response { $result = static::save( $hashid, $data ); if( $result->isStatus( 200 ) ) { $data = Products\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /products * @route.description REST-Antwort nach dem Erstellen eines Produkts (inkl. Notifikation, Redirect etc.) */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::create( $data ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); $type = Products\Type::get( $data->type ); REST\Response::closeModals(); REST\Response::redirect( "/products#{$type["plural"]}" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /products/{hashid} * @route.description REST-Antwort nach dem Löschen eines Produkts */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::delete( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/products" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /products/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Produkts (z. B. für Notifications) */ public static function restResponseToggleStatus( string $hashid ) : HTTP\Response { $result = static::toggleStatus( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /products/{hashid}/invoice * @route.description REST-Antwort zur Status-Umschaltung eines Produkts (z. B. für Notifications) */ public static function restResponseToggleInvoice( string $hashid ) : HTTP\Response { $result = static::toggleInvoice( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /products * @route.description REST-Konfiguration für Produkt-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { $tabs = REST\Response::addWrapper( "details", "Artikelstamm" )->get(); foreach( Products\Type::getAll() as $type ) { $tabs = $tabs->addTab( $type["plural"] )->get() ->setIcon( $type["icon"] ) ->addContent( static::restConfigTable( $type["value"] ) ) ->parent(); } $tabs->addTab( "Sales prices", "sales" )->get() ->setIcon( "bi-currency-euro" ) ->addContent( Products\Sales\Types\API\v1\Controller::restConfigTable() ) ->parent(); return $tabs; } /** * @internal rest * @method GET * * @route.path /products/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Produkts */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "details", "Produkt bearbeiten" ) ->setBacklink( "/products" ) ->get() ->setApi( "/products/{$hashid}" ) ->setAction( "/products/{$hashid}", "PUT" ) ->addTab( "Produkt" )->get() ->addHeadline( "Produkt", 2 ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "company_name", FALSE, "products" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "firstname", FALSE, "products" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "lastname", FALSE, "products" )) ->parent() ->addTab( "Ansprechpartner" )->get() ->addContent( // Contacts\Contacts\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Adressen" )->get() ->addContent( // Contacts\Addresses\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /products/create * @route.description REST-Konfiguration für das Erstellen eines Produkts (Formular) */ public static function restConfigCreate( $args ) : REST\Generator\Base\BaseGenerator { $option = Products\Type::get( $args["type"] ); return REST\Response::addModal( "details", "{$option["label"]} erstellen" ) ->get() ->setAction( "/products", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "products" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "products" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "custom_id", FALSe, "products" )) ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "description ", FALSE, "products" )) ->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "type", $args["type"], "products" )) ; } /** * @internal rest * @method GET * * @route.path /products/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Produkts */ public static function restConfigDelete( string $hashid ) : REST\Generator\Base\BaseGenerator { $type = Products\Model::getValue( $hashid, "type" ); return REST\Response::addModal( "details", "{$type->getLabel()} Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/products/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "products" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "products" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( int $type ) : REST\Generator\Base\BaseGenerator { $table = REST\Generator\Data\Table::create() ->setApi( "/products?type={$type}" ) ->setAction( "/products/{hashid}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [ "action" => "/products/create?type={$type}", ], "products" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "products", "hashid" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ // "label" => Products\Type::label(), // "icon" => Products\Type::icon(), // "options" => Products\Type::getAll(), // ], "type", [], "products", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "name", TRUE, TRUE, TRUE, "products" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "products" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "products" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "products", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "products", "hashid" )) ; return $table; } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Type.php **/ [ "color" => REST\Generator\Config\Color::Primary, "icon" => "bi-box", "label" => "Product", "plural" => "Products" ], self::Service => [ "color" => REST\Generator\Config\Color::Secondary, "icon" => "bi-gear-wide-connected", "label" => "Service", "plural" => "Services" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\Sales\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ // Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => "/products/sales", "label" => "Verkaufspreise", "icon" => "bi bi-currency-euro", "menu" => "products", ]; return $routes; }, 20 ); } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\Sales\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Products; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Kontakt nicht gefunden", "saved" => "Kontakt wurde erfolgreich gespeichert", "deleted" => "Kontakt wurde erfolgreich gelöscht", "created" => "Kontakt wurde erfolgreich erstellt", "statuschanged.0" => "Kontakt wurde erfolgreich deaktiviert", "statuschanged.1" => "Kontakt wurde erfolgreich aktiviert", "notcreated" => "Kontakt konnte nicht erstellt werden", "notsaved" => "Kontakt konnte nicht gespeichert werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /contacts * @route.description Listet alle Kontakte */ public static function getAll() : array { return Products\Sales\Model::getAll(); } /** * @api * @method GET * * @route.path /contacts/{hashid} * @route.description Gibt einen einzelnen Kontakts anhand der ID zurück */ public static function get( string $hashid ) : BaseEntity | HTTP\Response { if( $result = Products\Sales\Model::get( $hashid ) ) return $result; return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /contacts/{hashid} * @route.description Speichert Änderungen an einem bestehenden Kontakts */ public static function save( string $hashid, array $data ) : HTTP\Response { if( $result = Products\Sales\Model::get( $hashid ) ) { if( $result->save( $data ) ) { return REST\Response::autoResponse( 200, static::getNotify("saved") ); } return REST\Response::autoResponse( 500, static::getNotify("notsaved") ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method POST * * @route.path /contacts * @route.description Erstellt einen neuen Kontakt */ public static function create( array $data ) : HTTP\Response { if( $hashid = Products\Sales\Model::save( $data ) ) { $result = Products\Sales\Model::get( $hashid ); return REST\Response::autoResponse( 200, static::getNotify("created"), [ "data" => $result ] ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method DELETE * * @route.path /contacts/{hashid} * @route.description Löscht einen Kontakt anhand der ID */ public static function delete( string $hashid ) : HTTP\Response { if( Products\Sales\Model::delete( $hashid ) ) { return REST\Response::autoResponse( 200, static::getNotify("deleted") ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /contacts/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Kontakts */ public static function toggleStatus( string $hashid ) : HTTP\Response { if( $result = Products\Sales\Model::get( $hashid ) ) { $result->toggleStatus( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /contacts/{hashid}/invoice * @route.description Wechselt den Status (aktiv/inaktiv) eines Kontakts */ public static function toggleInvoice( string $hashid ) : HTTP\Response { if( $result = Products\Sales\Model::get( $hashid ) ) { $result->toggleInvoice( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /contacts/{hashid} * @route.description REST-Antwort nach dem Speichern eines Kontakts */ public static function restResponseSave( string $hashid, array $data ) : HTTP\Response { $result = static::save( $hashid, $data ); if( $result->isStatus( 200 ) ) { $data = Products\Sales\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /contacts * @route.description REST-Antwort nach dem Erstellen eines Kontakts (inkl. Notifikation, Redirect etc.) */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::create( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/contacts/{$result->getBody("data", "hashid")}" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /contacts/{hashid} * @route.description REST-Antwort nach dem Löschen eines Kontakts */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::delete( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/contacts" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /contacts/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Kontakts (z. B. für Notifications) */ public static function restResponseToggleStatus( string $hashid ) : HTTP\Response { $result = static::toggleStatus( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /contacts/{hashid}/invoice * @route.description REST-Antwort zur Status-Umschaltung eines Kontakts (z. B. für Notifications) */ public static function restResponseToggleInvoice( string $hashid ) : HTTP\Response { $result = static::toggleInvoice( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /contacts * @route.description REST-Konfiguration für Kontakt-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Kontakte" ) ->replaceContent( static::restConfigTable() ); } /** * @internal rest * @method GET * * @route.path /contacts/{hashid} * @route.alternative.0 /contacts/{hashid}#kontext * @route.alternative.1 /contacts/{hashid}#chat * @route.alternative.2 /contacts/{hashid}#telefon * @route.description REST-Konfiguration für Detailansicht eines Kontakts */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "details", "Kontakt bearbeiten" ) ->setBacklink( "/contacts" ) ->get() ->setApi( "/contacts/{$hashid}" ) ->setAction( "/contacts/{$hashid}", "PUT" ) ->addTab( "Kontakt" )->get() ->addHeadline( "Kontakt", 2 ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "company_name", FALSE, "contacts" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "firstname", FALSE, "contacts" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "lastname", FALSE, "contacts" )) ->parent() ->addTab( "Ansprechpartner" )->get() ->addContent( // Contacts\Contacts\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Adressen" )->get() ->addContent( // Contacts\Addresses\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /contacts/create * @route.description REST-Konfiguration für das Erstellen eines Kontakts (Formular) */ public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Kontakt erstellen" ) ->get() ->setAction( "/contacts", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "contacts" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "contacts" )); } /** * @internal rest * @method GET * * @route.path /contacts/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Kontakts */ public static function restConfigDelete( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Kontakt Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/contacts/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "contacts" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "contacts" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $table = REST\Generator\Data\Table::create() ->setApi( "/contacts" ) ->setAction( "/contacts/{hashid}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "contacts", "hashid" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ // "label" => Products\Sales\Category::label(), // "icon" => Products\Sales\Category::icon(), // "options" => Products\Sales\Category::getAll(), // ], "category", [], "contacts", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "label" => Products\Sales\Type::label(), "icon" => Products\Sales\Type::icon(), "options" => Products\Sales\Type::getAll(), ], "type", [], "contacts", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "company_name", TRUE, TRUE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "firstname", TRUE, TRUE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "lastname", TRUE, TRUE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "email", TRUE, TRUE, TRUE, "contacts" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ // "label" => Contacts\Reachability::label(), // "icon" => Contacts\Reachability::icon(), // "options" => Contacts\Reachability::getAll(), // ], "reachability", [], "contacts", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "contacts" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "contacts" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "contacts", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "contacts", "hashid" )) ; $buttons = $table->top()->getButtons(); foreach( Products\Sales\Type::getAll() as $type ) { $type["name"] = "type"; $buttons->addDropdown( ...Hooks::filter( "rest.generator::button.name->create", $type, "contacts" ) ); } return $table; } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Types/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\Sales\Types\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Types/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Products\Sales\Types\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Products; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Verkaufspreis nicht gefunden", "saved" => "Verkaufspreis wurde erfolgreich gespeichert", "deleted" => "Verkaufspreis wurde erfolgreich gelöscht", "created" => "Verkaufspreis wurde erfolgreich erstellt", "statuschanged.0" => "Verkaufspreis wurde erfolgreich deaktiviert", "statuschanged.1" => "Verkaufspreis wurde erfolgreich aktiviert", "statuschanged.2" => "Verkaufspreis wurde als Standard Preis gesetzt", "notcreated" => "Verkaufspreis konnte nicht erstellt werden", "notsaved" => "Verkaufspreis konnte nicht gespeichert werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /products/sales/types * @route.description Listet alle Verkaufspreise */ public static function getAll() : array { return Products\Sales\Types\Model::getAll(); } /** * @api * @method GET * * @route.path /products/sales/types/{hashid} * @route.description Gibt einen einzelnen Verkaufspreiss anhand der ID zurück */ public static function get( string $hashid ) : BaseEntity | HTTP\Response { if( $result = Products\Sales\Types\Model::get( $hashid ) ) return $result; return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /products/sales/types/{hashid} * @route.description Speichert Änderungen an einem bestehenden Verkaufspreiss */ public static function save( string $hashid, array $data ) : HTTP\Response { if( $result = Products\Sales\Types\Model::get( $hashid ) ) { if( $result->save( $data ) ) { return REST\Response::autoResponse( 200, static::getNotify("saved") ); } return REST\Response::autoResponse( 500, static::getNotify("notsaved") ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method POST * * @route.path /products/sales/types * @route.description Erstellt einen neuen Verkaufspreis */ public static function create( array $data ) : HTTP\Response { if( $hashid = Products\Sales\Types\Model::save( $data ) ) { $result = Products\Sales\Types\Model::get( $hashid ); return REST\Response::autoResponse( 200, static::getNotify("created"), [ "data" => $result ] ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method DELETE * * @route.path /products/sales/types/{hashid} * @route.description Löscht einen Verkaufspreis anhand der ID */ public static function delete( string $hashid ) : HTTP\Response { if( Products\Sales\Types\Model::delete( $hashid ) ) { return REST\Response::autoResponse( 200, static::getNotify("deleted") ); } return REST\Response::autoResponse( 500, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /products/sales/types/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Verkaufspreiss */ public static function toggleStatus( string $hashid ) : HTTP\Response { if( $result = Products\Sales\Types\Model::get( $hashid ) ) { $result->toggleStatus( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /** * @api * @method PATCH * * @route.path /products/sales/types/{hashid}/invoice * @route.description Wechselt den Status (aktiv/inaktiv) eines Verkaufspreiss */ public static function toggleInvoice( string $hashid ) : HTTP\Response { if( $result = Products\Sales\Types\Model::get( $hashid ) ) { $result->toggleInvoice( TRUE ); return REST\Response::autoResponse( 200, static::getNotify("statuschanged.{$result->status->getValue()}" ), [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /products/sales/types/{hashid} * @route.description REST-Antwort nach dem Speichern eines Verkaufspreiss */ public static function restResponseSave( string $hashid, array $data ) : HTTP\Response { $result = static::save( $hashid, $data ); if( $result->isStatus( 200 ) ) { $data = Products\Sales\Types\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /products/sales/types * @route.description REST-Antwort nach dem Erstellen eines Verkaufspreiss (inkl. Notifikation, Redirect etc.) */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::create( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/products#sales" ); // REST\Response::redirect( "/products/sales/types/{$result->getBody("data", "hashid")}" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /products/sales/types/{hashid} * @route.description REST-Antwort nach dem Löschen eines Verkaufspreiss */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::delete( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/products/sales/types" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /products/sales/types/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Verkaufspreiss (z. B. für Notifications) */ public static function restResponseToggleStatus( string $hashid ) : HTTP\Response { $result = static::toggleStatus( $hashid ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /products/sales/types * @route.description REST-Konfiguration für Verkaufspreis-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Verkaufspreise" ) ->replaceContent( static::restConfigTable() ); } /** * @internal rest * @method GET * * @route.path /products/sales/types/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Verkaufspreiss */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Verkaufspreis bearbeiten" ) ->get() ->setApi( "/products/sales/types/{$hashid}" ) ->setAction( "/products/sales/types/{$hashid}", "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => Products\Sales\Types\CalcBase::label(), "options" => Products\Sales\Types\CalcBase::getAll(), ], "calc_base", TRUE, TRUE, "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => Products\Sales\Types\CalcOperator::label(), "options" => Products\Sales\Types\CalcOperator::getAll(), ], "calc_operator", TRUE, TRUE, "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->number", [], "calc_value", TRUE, "products/sales/types" )) ; } /** * @internal rest * @method GET * * @route.path /products/sales/types/create * @route.description REST-Konfiguration für das Erstellen eines Verkaufspreiss (Formular) */ public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Verkaufspreis erstellen" ) ->get() ->setAction( "/products/sales/types", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => Products\Sales\Types\CalcBase::label(), "options" => Products\Sales\Types\CalcBase::getAll(), ], "calc_base", TRUE, TRUE, "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => Products\Sales\Types\CalcOperator::label(), "options" => Products\Sales\Types\CalcOperator::getAll(), ], "calc_operator", TRUE, TRUE, "products/sales/types" )) ->addField(...Hooks::filter( "rest.generator::control.type->number", [], "calc_value", TRUE, "products/sales/types" )) ; } /** * @internal rest * @method GET * * @route.path /products/sales/types/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Verkaufspreiss */ public static function restConfigDelete( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Verkaufspreis Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/products/sales/types/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "products/sales/types" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "products/sales/types" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $table = REST\Generator\Data\Table::create() ->setApi( "/products/sales/types" ) ->setAction( "/products/sales/types/{hashid}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "products/sales/types" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Products\Sales\Types\Status::getAll(), ], "status", [], "products/sales/types", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "label" => Products\Sales\Types\CalcBase::label(), "icon" => Products\Sales\Types\CalcBase::icon(), "options" => Products\Sales\Types\CalcBase::getAll(), ], "calc_base", [], "products/sales/types", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "name", TRUE, TRUE, TRUE, "products/sales/types" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [ "label" => "Formel", ], "output", TRUE, TRUE, TRUE, "products/sales/types" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "products/sales/types" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "products/sales/types" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "products/sales/types", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "products/sales/types", "hashid" )) ; // $buttons = $table->top()->getButtons(); // // foreach( Products\Sales\Types\Type::getAll() as $type ) { // $type["name"] = "type"; // // $buttons->addDropdown( ...Hooks::filter( "rest.generator::button.name->create", $type, "products/sales/types" ) ); // } return $table; } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Types/CalcBase.php **/ [ "color" => REST\Generator\Config\Color::Primary, "icon" => "bi-basket2", "label" => "Einkaufspreis" ], self::ListPrice => [ "color" => REST\Generator\Config\Color::Secondary, "icon" => "bi-list-columns", "label" => "Listenpreis" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Types/Entity.php **/ Status::class, "calc_base" => CalcBase::class, "calc_operator" => CalcOperator::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "output" => "output", ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } public function getOutput() { $operator = $this->calc_operator->getOperator();# if( $operator == "%" ) { $math = "+"; $unit = $operator; } if( $operator != "%" ) { $math = $operator; $unit = "€"; } $base = $this->calc_base->getLabel(); $value = number_format( $this->calc_value, 2 ); return "{$base} {$math} {$value} {$unit}"; } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Types/Status.php **/ [ "color" => REST\Generator\Config\Color::Warning, "icon" => "bi-star-fill", "label" => "Default" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct( mixed $value, $parent = NULL ) { static::$OPTIONS = array_replace( parent::$OPTIONS, static::$OPTIONS ); parent::__construct( $value, $parent ); } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Types/CalcOperator.php **/ [ "color" => REST\Generator\Config\Color::Primary, "icon" => "bi-percent", "operator" => "%", "label" => "Prozent" ], self::FixedValue => [ "color" => REST\Generator\Config\Color::Success, "icon" => "bi-graph-up-arrow", "operator" => "+", "label" => "Fester Wert" ], self::FixedDiscount => [ "color" => REST\Generator\Config\Color::Danger, "icon" => "bi-graph-down-arrow","operator" => "-", "label" => "Fester Rabatt" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Sales/Entity.php **/ Attribute\Status::class, "is_override" => Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } } /** Datei: plugins/products/library/ARUNOX/Plugins/Products/Entity.php **/ Type::class, "status" => Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } } /** Datei: plugins/products/hooks/init.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Products; Hooks::add('public::api->init', [ Products\API\v1\Routes::class, "register" ] ); Hooks::add('public::api->init', [ Products\Sales\API\v1\Routes::class, "register" ] ); Hooks::add('public::api->init', [ Products\Services\API\v1\Routes::class, "register" ] ); /** Datei: plugins/products/config.php **/ * @copyright 2025 ARUNOX * @version 0.0.0 * @since 1.0.0 File is created */