'ACCOUNTID', 'callback' => 'text', 'required' => true, 'length' => 0, 'default' => null ], //[ 'name' => 'CONTACTID', 'callback' => 'text', 'required' => true, 'length' => 0, 'default' => null ], [ 'name' => 'Account_Name', 'callback' => 'text', 'required' => true, 'length' => 100, 'default' => null ], [ 'name' => 'Contact_Name', 'callback' => 'text', 'required' => true, 'length' => 100, 'default' => null ], [ 'name' => 'Deal_Name', 'callback' => 'text', 'required' => true, 'length' => 100, 'default' => null ], [ 'name' => 'Type', 'callback' => 'entry_type', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Partner_gew_hlt', 'callback' => 'partners', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Spezialgr_ndung', 'callback' => 'special_foundation', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Amount', 'callback' => 'amount', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Closing_Date', 'callback' => 'date', 'required' => true, 'length' => 0, 'default' => null ], [ 'name' => 'Stage', 'callback' => 'text', 'required' => true, 'length' => 0, 'default' => 'Bestellung eingegangen' ], [ 'name' => 'Firmenname', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Firmenadresse', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Firma_PLZ', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Firma_Ort', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Firmenzweck', 'callback' => 'text', 'required' => false, 'length' => 2000, 'default' => null ], [ 'name' => 'Firma_Sitz', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Gr_ndungskapital', 'callback' => 'decimal', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Teil_Liberiert', 'callback' => 'equity_capital_paid', 'required' => false, 'length' => 16, 'default' => null ], [ 'name' => 'davon_Sacheinlage', 'callback' => 'decimal', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Wert_pro_Anteil', 'callback' => 'decimal', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Anzahl_Anteile', 'callback' => 'number', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Bankangaben', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Description', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Sprache', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'zc_gad', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'GCLID', 'callback' => 'gclid', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'paid_cc', 'callback' => 'checkbox', 'required' => false, 'length' => 0, 'default' => '' ], // Bezahlt (Kreditkarte) [ 'name' => 'add_sales_json', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => '[]' ], [ 'name' => 'Ref_Source', 'callback' => 'referrer', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'Ref_Medium', 'callback' => 'referrer', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'Ref_Name', 'callback' => 'referrer', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'Ref_Term', 'callback' => 'referrer', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'Ref_Content', 'callback' => 'referrer', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'Gutschein_Code', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => '' ], [ 'name' => 'Price_Gutschein', 'callback' => 'loyalty_card_value', 'required' => false, 'length' => 0, 'default' => '' ], ]; protected static $person_fields = [ [ 'name' => 'Anrede_%d', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Vorname_%d', 'callback' => 'text', 'required' => false, 'length' => 40, 'default' => null ], [ 'name' => 'Nachname_%d', 'callback' => 'text', 'required' => false, 'length' => 40, 'default' => null ], [ 'name' => 'Strasse_%d', 'callback' => 'text', 'required' => false, 'length' => 250, 'default' => null ], [ 'name' => 'Ort_%d', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'PLZ_%d', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], // *** PLZ%d [ 'name' => 'Nationalit_t_%d', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Heimatort_%d', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Geburtsdatum_%d', 'callback' => 'date', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Funktion_VR_%d', 'callback' => 'vr_function_in_company', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Funktion_Firma_%d', 'callback' => 'function_in_company', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Zeichnungsberechtigung_%d', 'callback' => 'signature_authorization', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Gehaltene_Anteile_%d', 'callback' => 'number', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Firmenname_%d', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Firmenadresse_%d', 'callback' => 'text', 'required' => false, 'length' => 250, 'default' => null ], [ 'name' => 'Firmen_Ort_%d', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Firmen_PLZ_%d', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Firmen_Land_%d', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Handelsregisternummer_%d', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], ]; protected static $first_company_fields = [ [ 'name' => 'Unternehmen', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Unternehmen_Strasse', 'callback' => 'text', 'required' => false, 'length' => 250, 'default' => null ], [ 'name' => 'Unternehmen_Ort', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Unternehmen_PLZ', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Unternehmen_Land', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Unternehmen_HR_Nummer', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Vertreter_Anrede', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Vertreter_Vorname', 'callback' => 'text', 'required' => false, 'length' => 40, 'default' => null ], [ 'name' => 'Vertreter_Nachname', 'callback' => 'text', 'required' => false, 'length' => 40, 'default' => null ], [ 'name' => 'Vertreter_Strasse', 'callback' => 'text', 'required' => false, 'length' => 250, 'default' => null ], [ 'name' => 'Vertreter_Ort', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Vertreter_PLZ', 'callback' => 'text', 'required' => false, 'length' => 30, 'default' => null ], [ 'name' => 'Vertreter_Nationalit_t', 'callback' => 'text', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Vertreter_Geburtsdatum', 'callback' => 'date', 'required' => false, 'length' => 0, 'default' => null ], [ 'name' => 'Gehaltene_Anteile_UG', 'callback' => 'number', 'required' => false, 'length' => 0, 'default' => null ], ]; protected static $fields_map = [ // Bestellung //'ACCOUNTID' => 'zoho_account_id', //'CONTACTID' => 'zoho_contact_id', 'Account_Name' => 'company_name', 'Contact_Name' => 'zoho_contact_id', 'Deal_Name' => 'company_name', 'Type' => 'entry_type', 'Partner_gew_hlt' => 'partners', 'Spezialgr_ndung' => 'persons', 'Amount' => 'price', 'Closing_Date' => 'added', 'Stage' => '', // Bestellinformationen 'Firmenname' => 'company_name', 'Firmenadresse' => 'company_street', 'Firma_PLZ' => 'company_zip', 'Firma_Ort' => 'company_city', 'Firmenzweck' => 'company_purpose', 'Firma_Sitz' => 'company_city', 'Gr_ndungskapital' => 'equity_capital', 'Teil_Liberiert' => 'equity_capital_paid', 'davon_Sacheinlage' => 'in_kind', 'Wert_pro_Anteil' => 'share_price', 'Bankangaben' => 'bank_details', 'Description' => 'comment', 'Anzahl_Anteile' => '_shares_number', 'Sprache' => 'language', //'zc_gad' => 'zc_gad', 'GCLID' => 'gclid', // Loyalty card 'Gutschein_Code' => 'loyalty_card_id', 'Price_Gutschein' => 'loyalty_card_value', ]; protected static $person_fields_map = [ 'Anrede_%d' => 'prefix', 'Vorname_%d' => 'first_name', 'Nachname_%d' => 'last_name', 'Strasse_%d' => 'street', 'Ort_%d' => 'city', 'PLZ_%d' => 'zip', // *** PLZ%d 'Nationalit_t_%d' => 'nationality', 'Heimatort_%d' => 'hometown', 'Geburtsdatum_%d' => 'birth_date', 'Funktion_VR_%d' => 'vr_function_in_company_ID', 'Funktion_Firma_%d' => 'function_in_company_ID', 'Zeichnungsberechtigung_%d' => 'signature_authorization_ID', 'Gehaltene_Anteile_%d' => 'shares_number', 'Firmenname_%d' => 'company_name', 'Firmenadresse_%d' => 'company_address', 'Firmen_Ort_%d' => 'company_city', 'Firmen_PLZ_%d' => 'company_zip', 'Firmen_Land_%d' => 'company_country', 'Handelsregisternummer_%d' => 'company_number', ]; protected static $first_company_fields_map = [ 'Unternehmen' => 'company_name', 'Unternehmen_Strasse' => 'company_address', 'Unternehmen_PLZ' => 'company_zip', 'Unternehmen_Ort' => 'company_city', 'Unternehmen_Land' => 'company_country', 'Unternehmen_HR_Nummer' => 'company_number', 'Vertreter_Anrede' => 'prefix', 'Vertreter_Vorname' => 'first_name', 'Vertreter_Nachname' => 'last_name', 'Vertreter_Strasse' => 'street', 'Vertreter_PLZ' => 'zip', 'Vertreter_Ort' => 'city', 'Vertreter_Nationalit_t' => 'nationality', 'Vertreter_Geburtsdatum' => 'birth_date', 'Gehaltene_Anteile_UG' => 'shares_number' ]; protected static $data_filter_exceptions = [ 'zc_gad' ]; protected static function get_record_data( array $data ) { $record_data = parent::get_record_data( $data ); if ( FQP::ENTRY_TYPE_AG != $data['entry_type_ID'] && array_key_exists( 'Teil_Liberiert', $record_data ) ) { unset( $record_data['Teil_Liberiert'] ); } if ( ! empty( $data['persons'] ) ) { $index = 1; $first_company_added = false; foreach ( $data['persons'] as $person ) { if ( 'company' == $person['type'] && ! $first_company_added ) { foreach ( static::$first_company_fields as $specs ) { $key = @static::$first_company_fields_map[$specs['name']]; if ( $key ) { $value = ( $key ) ? @$person[$key] : null; } else { $value = @$specs['default']; } $record_data[$specs['name']] = call_user_func_array( [ static::get_module_class(), $specs['callback'] ], [ $value, $specs, $person ] ); } $first_company_added = true; } foreach ( static::$person_fields as $specs ) { $key = @static::$person_fields_map[$specs['name']]; if ( $key ) { $value = ( $key ) ? @$person[ $key ] : null; } else { $value = @$specs['default']; } $record_data[ sprintf( $specs['name'], $index ) ] = call_user_func_array( [ static::get_module_class(), $specs['callback'] ], [ $value, $specs, $person ] ); } ++$index; } } if ( ! empty( $data['products'] ) ) { $products = []; foreach ( $data['products'] as $prod ) { $products[] = [ 'title' => $prod['title'], 'price' => $prod['price'], 'tax' => $prod['tax'], ]; } $record_data['add_sales_json'] = json_encode( $products ); } return $record_data; } public static function entry_type( $value, array $specs, array $data ) { static $entry_types; static $backing_types; if ( null === $entry_types ) { $entry_types = DB::get_entry_types( 'de', true ); } if ( null === $backing_types ) { $backing_types = DB::get_backing_types( 'de', true ); } $value = $entry_types[$data['entry_type_ID']]['title']; if ( ! empty( $data['backing_type_ID'] ) ) { $value .= " {$backing_types[$data['backing_type_ID']]['title']}"; } $value = str_replace( [ 'Sacheinlage', 'Bareinlage' ], [ 'Sach', 'Bar' ], $value ); return $value; } public static function amount( $value, array $specs, array $data ) { $price = $data['price']; if ( ! empty( $data['partners'] ) ) { foreach ( $data['partners'] as $partner ) { $price = bcsub( $price, $partner['discount'], 2 ); } } $price = bcadd( $price, $data['tax'], 2 ); $price = bcadd( $price, $data['payment_fee'], 2 ); $price = bcadd( $price, $data['payment_fee_tax'], 2 ); if ( ! empty( $data['products'] ) ) { foreach ( $data['products'] as $prod ) { $price = bcadd( $price, $prod['price'], 2 ); $price = bcadd( $price, $prod['tax'], 2 ); } } if ($data['loyalty_card_value']) { if (1 == bccomp($data['loyalty_card_value'], $price, 2)) { self::$loyalty_card_discount = $price; } else { self::$loyalty_card_discount = $data['loyalty_card_value']; } } $price = bcsub( $price, self::$loyalty_card_discount, 2 ); return $price; } public static function partners( $value ) { $partners = []; if (!empty($value) && is_array($value)) { foreach ($value as $partner) { $partners[] = ($partner['api_name']) ?: $partner['title']; } } return $partners; } public static function special_foundation( $value ) { if ( is_array( $value ) && ! empty( $value ) ) { foreach ( $value as $person ) { if ( 'company' == @$person['type'] ) { return 'JA'; } } } return 'nein'; } public static function vr_function_in_company( $vr_function_in_company_ID ) { if ( ! $vr_function_in_company_ID ) { return null; } static $vr_functions; if ( null === $vr_functions ) { $vr_functions = DB::get_vr_function_in_company( 'de', true ); } $value = $vr_functions[$vr_function_in_company_ID]; $value = static::umlaut( $value ); return $value; } public static function function_in_company( $function_in_company_ID ) { if ( ! $function_in_company_ID ) { return null; } static $functions; if ( null === $functions ) { $functions = DB::get_function_in_company( 'de', true ); } $value = $functions[$function_in_company_ID]; $value = static::umlaut( $value ); return $value; } public static function signature_authorization( $signature_authorization_ID ) { if ( ! $signature_authorization_ID ) { return null; } static $signature; if ( null === $signature ) { $signature = DB::get_signature_authorization( 'de', true ); } $value = $signature[$signature_authorization_ID]; $value = static::umlaut( $value ); return $value; } public static function equity_capital_paid( $value, array $specs, array $data ) { if ( $value ) { return self::decimal( $value, $specs ); } elseif ( !empty($data['equity_capital']) ) { return self::decimal( $data['equity_capital'], $specs ); } return @$specs['default']; } public static function gclid() { return strval( @$_COOKIE['gclid'] ); } public static function referrer( $value, array $specs, array $data ) { if ( is_array( $data['referrer'] ) && ! empty( $data['referrer'] ) ) { $referrer = $data['referrer']; if ( array_key_exists( $specs['name'], $referrer ) ) { $value = strval( $referrer[$specs['name']] ); } else { $value = null; } } else { $value = null; } return self::text( $value, $specs ); } public static function loyalty_card_value() { return self::$loyalty_card_discount; // калькулюється в self::amount(), тому треб слідкувати щоб "Amount" обраблявся першим } }