mindestens %s betragen.'), fqp_money_currency(static::$min_equity_capital_ag));
} elseif ( FQP\FQP::ENTRY_TYPE_COLLECTIVE_COMPANY == static::$entry_type ) {
$label = sprintf(fqp__('EN Gesellschaftskapital (mind. %s)'), fqp_money_currency(static::$min_equity_capital_collective_company));
$description = sprintf(fqp__('EN Das Stammkapital muss mindestens %s betragen.'), fqp_money_currency(2000 /*static::$min_equity_capital_collective_company*/ ));
} else {
$label = sprintf( fqp__( 'EN Stammkapital (mind. %s)' ), fqp_money_currency( static::$min_equity_capital_ltd ) );
$description = sprintf( fqp__( 'EN Das Stammkapital muss mindestens %s betragen.' ), fqp_money_currency( static::$min_equity_capital_ltd ) );
}
$fields['equity_capital'] = [
'type' => 'text',
'description' => $description,
'label' => $label,
'attribs' => [
//'required' => true,
'class' => 'price',
],
];
if ( FQP\FQP::ENTRY_TYPE_AG == static::$entry_type ) {
$description = fqp__( 'EN Die Mindesteinlage bei der Aktiengesellschaft beträgt 25 Prozent des Nennwertes jeder Aktie. Sacheinlagen sind vollständig zu leisten.' );
$fields['equity_capital_paid'] = [
'type' => 'text',
'description' => $description,
'label' => fqp__( 'EN Einbezahltes Aktienkapital' ),
'attribs' => [
//'required' => true,
'class' => 'price',
],
];
} elseif ( FQP\FQP::ENTRY_TYPE_LTD == static::$entry_type ) {
$description = sprintf( fqp__( 'EN Die Mindesteinlage bei der GmbH beträgt mindestens EUR %s.' ), fqp_money_currency( static::$min_equity_capital_paid_ltd ) );
$fields['equity_capital_paid'] = [
'type' => 'text',
'description' => $description,
'label' => fqp__( 'EN Einbezahltes Stammkapital' ),
'attribs' => [
//'required' => true,
'class' => 'price',
],
];
}
if ( FQP\FQP::BACKING_TYPE_GOODS == static::$backing_type ) {
$fields['in_kind'] = [
'type' => 'text',
'description' => 'EN Erfassen Sie den Wert Ihrer Sacheinlage. Falls Sie diesen nicht genau kennen können Sie eine einfache Schätzung machen.',
'label' => fqp__( 'EN Davon als Sacheinlage' ),
'attribs' => [
//'required' => true,
'class' => 'price',
]
];
$fields['in_cash'] = [
'type' => 'text',
'label' => fqp__( 'EN Davon in Bar' ),
'attribs' => [
//'required' => true,
'class' => 'price',
]
];
}
if ( FQP\FQP::ENTRY_TYPE_AG == static::$entry_type ) {
$label = 'EN Nennwert pro Aktie';
$description = 'EN Der Nennwert der Aktie muss mindestens EURO 1.- betragen.';
} else {
$label = 'EN Nennwert pro Stammanteil';
$description = 'EN Der Nennwert eines Stammanteils muss mindestens EUR 1.- betragen.';
}
$fields['share_price'] = [
'type' => 'text',
'description' => $description,
'label' => fqp__( $label ),
'attribs' => [
//'required' => true,
'class' => 'price',
]
];
if ( FQP\FQP::ENTRY_TYPE_AG == static::$entry_type ) {
$label = 'EN Anzahl Aktien';
} else {
$label = 'EN Anzahl Stammanteile';
}
$fields['_shares_number'] = [
'type' => 'text',
'attribs' => [
'placeholder' => $label,
'readonly' => 'readonly',
],
];
static::$fields['capital'] = $fields;
}
protected static function init_bank_fields() {
$fields = [];
if ( FQP\FQP::ENTRY_TYPE_COLLECTIVE_COMPANY != static::$entry_type ) {
$description = '';
if ( FQP\FQP::ENTRY_TYPE_AG == static::$entry_type ) {
$description = 'EN Bei der Gründung einer Aktiengesellschaft muss bei einer Bank ein Konto eröffnet werden. Dies ist ein Bankkonto, auf welchem das (liberierte) Kapital des entsprechenden Unternehmens hinterlegt wird, bis dieses im Handelsregister eingetragen ist.';
} elseif ( FQP\FQP::ENTRY_TYPE_LTD == static::$entry_type ) {
$description = 'EN Bei der Gründung einer GmbH muss bei einer Bank ein Konto eröffnet werden. Dies ist ein Bankkonto, auf welchem das (liberierte) Kapital des entsprechenden Unternehmens hinterlegt wird, bis dieses im Handelsregister eingetragen ist.';
}
$fields['bank_details'] = [
'type' => 'textarea',
'description' => $description,
'label' => 'Bank details (if known)',
'attribs' => [
],
];
}
static::$fields['bank'] = $fields;
}
protected static function init_persons_fields( $persons ) {
$fields = [];
unset( $persons['_completed'] );
$label = '';
if ( FQP\FQP::ENTRY_TYPE_AG == static::$entry_type ) {
$label = 'EN Anzahl Aktien';
} elseif ( FQP\FQP::ENTRY_TYPE_LTD == static::$entry_type ) {
$label = 'EN Anzahl Stammanteile';
}
foreach ( $persons as $_persons ) {
foreach ( array_keys( $_persons ) as $person_id ) {
$name = static::get_person_shares_element_name( $person_id );
$fields[$name] = [
'type' => 'text',
'attribs' => [
'class' => 'number',
'placeholder' => $label,
],
];
}
}
static::$fields['persons'] = $fields;
}
public static function get_person_shares_element_name( $person_id ) {
return "person_shares[{$person_id}]";
}
public static function get_fields( $type = 'capital', $params = [] ) {
if ( empty( static::$fields[$type] ) ) {
$method = "init_{$type}_fields";
if ( ! method_exists( __CLASS__, $method )) {
return false;
}
call_user_func_array( [ __CLASS__, $method ], $params );
}
return static::$fields[$type];
}
public static function sanitize_data( &$data, $persons = [] ) {
if ( !is_array( $data ) ) {
$data = [];
}
$errors = [];
$required_msg = fqp__( '%s is required' );
$price_fields = [ 'equity_capital', 'equity_capital_paid', 'share_price', 'in_cash', 'in_kind' ];
foreach ( $price_fields as $name ) {
if ( array_key_exists( $name, $data ) ) {
$data[$name] = preg_replace('/[^.0-9]+/', '', $data[$name]);
}
}
foreach ( [ 'capital', 'bank' ] as $type ) {
$fields = static::get_fields( $type );
if ( $fields ) {
foreach ( $fields as $name => $specs ) {
if ( @$specs['attribs']['required'] && empty( $data[$name] ) ) {
$title = ( ! empty( $specs['label'] ) ) ? $specs['label'] : $specs['attribs']['placeholder'];
$errors[] = esc_html( sprintf( $required_msg, fqp__( $title ) ) );
}
}
}
}
/*if ( in_array( static::$entry_type, [ FQP\FQP::ENTRY_TYPE_AG, FQP\FQP::ENTRY_TYPE_LTD ] ) ) {
$required_msg = fqp__( '%s Number of shares is required' );
foreach ($persons as $_persons) {
foreach ($_persons as $person_id => $person) {
$name = static::get_person_shares_element_name($person_id);
if (empty(fqp_array_get($data, $name))) {
$person_name = "{$person['prefix']} {$person['first_name']} {$person['last_name']}";
$errors[] = esc_html(sprintf($required_msg, fqp__($person_name)));
}
}
}
}*/
if ( FQP\FQP::ENTRY_TYPE_AG == static::$entry_type ) {
if ( $data['equity_capital'] && $data['equity_capital'] < static::$min_equity_capital_ag ) {
$errors[] = [
'no_esc' => true,
'msg' => sprintf( fqp__( 'EN Das Aktienkapital muss mindestens %s betragen.'), fqp_money_currency( static::$min_equity_capital_ag ) )
];
}
/*if ( $data['equity_capital_paid'] && $data['equity_capital_paid'] < static::$min_equity_capital_paid_ag ) {
$errors[] = [
'no_esc' => true,
'msg' => sprintf( fqp__( 'EN Das Einbezahltes Aktienkapital muss mindestens %s betragen.'), fqp_money_currency( static::$min_equity_capital_paid_ag ) )
];
}*/
} elseif ( FQP\FQP::ENTRY_TYPE_LTD == static::$entry_type ) {
if ( $data['equity_capital'] && $data['equity_capital'] < static::$min_equity_capital_ltd ) {
$errors[] = [
'no_esc' => true,
'msg' => sprintf( fqp__( 'EN Das Stammkapital muss mindestens %s betragen.'), fqp_money_currency( static::$min_equity_capital_ltd ) )
];
}
if ( $data['equity_capital_paid'] && $data['equity_capital_paid'] < static::$min_equity_capital_paid_ltd ) {
$errors[] = [
'no_esc' => true,
'msg' => sprintf( fqp__( 'EN Das Einbezahltes Stammkapital muss mindestens %s betragen.'), fqp_money_currency( static::$min_equity_capital_paid_ltd ) )
];
}
}
return ( empty( $errors ) ) ? true : $errors;
}
public static function get_filter_fields() {
return [];
}
public static function filter_data( &$data, $persons = [] ) {
$fields = static::get_fields( 'capital' ) + static::get_fields( 'persons', [ $persons ] ) + static::get_fields( 'bank' );
$filtered = [];
foreach ( array_keys( $fields ) as $field ) {
if ( false !== ( $bracket_pos = strpos( $field, '[' ) ) ) {
if ( 2 < count( explode( '[', $field ) ) ) {
wp_die( 'Opps. It\'s multidimensional array!' );
}
$base_name = substr( $field, 0, $bracket_pos );
$index_name = substr( $field, $bracket_pos + 1, -1 );
$filtered[$base_name][$index_name] = fqp_array_get( $data, $field );
} else {
$filtered[$field] = fqp_array_get( $data, $field );
}
}
$data = $filtered;
}
}