Buchungssätze für 0 EUR-Bestellungen erstellen

Bei komplett kostenlosen Bestellungen, die nicht durch Gutscheine hervorgerufen werden, erstellt das Plugin im "normalen Betrieb" keine Buchungssätze.

Denn: Hier sind dann keine Umbuchungen erforderlich.

Es kann in Einzelfällen trotzdem hilfreich sein, solche Buchungen zu erstellen. Zum Beispiel, damit alle Rechnungen (auch solche für kostenlose Bestellungen) exportiert und in DATEV archiviert werden. Damit kritisiert der Betriebsprüfer dann keine fehlenden Rechnungsnummern.

Mit diesem Code-Snippet werden auch Buchungen für 0 EUR-Bestellungen erstellt.

Wichtig: Bitte passe noch das Debitorkonto ("TODO: SET THIS") passend an.

PS: Dieser Code ist bisher bei "nur" einem Kunden im Einsatz. Wenn du "dasselbe" Problem hast, gib mir bitte Bescheid. Denn dann macht es wahrscheinlich Sinn, diese Funktion direkt im Plugin ohne Extra-Code anzubieten.

// This hook/action is called after all accounting records are supposed to be created
add_action( 'wcdtvfe_create_all_accounting_records', 'wcdtvfec_add_zero_value_records', 10, 2 );

function wcdtvfec_add_zero_value_records( $accounting_records, $order_id ) {
	if( count( $accounting_records ) > 0 ) {
		return $accounting_records;
	}

	// No accounting records have been created for this order so far

	$order = wc_get_order( $order_id );

	if ( !$order ) {
		return $accounting_records;
	}

	// Do not create if the order total is larger than 0 (something probably wrong in this case)
	if( $order->get_total() > 0 ) {
		return $accounting_records;
	}

	// The order value is 0 and an additional accounting record should be created
	$global_settings = WooCommerce_DATEV_Format_Export\Utils::get_decoded_json_settings( "wcdtvfe_general_settings" );

	// The new accounting record 
	$accounting_record_data = [];

	// See includes/system/accounting-records/receivable-refund-records-factory for details
	// Get the posting date as per the settings,
	$posting_date = $order->get_date_created();

	if ( $global_settings->receivable_posting_date == "date_paid" ) {
		$posting_date = $order->get_date_paid();
	}
	else if ( $global_settings->receivable_posting_date == "date_completed" ) {
		$posting_date = $order->get_date_completed();
	}

	// Get the debtor account (this is mostly cosmetic as the order value will be 0, 
	// and has no actual effect on accounting)

	$debtor_account = false;

	try {
		$debtor_account = (new WooCommerce_DATEV_Format_Export\Accounting_Numbers_Helper())->get_debtor_account_number( $order );
	}
	catch( WooCommerce_DATEV_Format_Export\FallbackAccountInexistantException $e) {
		return $accounting_records;
	}

	if ( !$debtor_account ) {
		return $accounting_records;
	}

	// Build the actual 0-entry

	$accounting_record_data[ "type" ] = "F";
	$accounting_record_data[ "order_id" ] = $order_id;
	$accounting_record_data[ "actual_date" ] = $posting_date;
	$accounting_record_data[ "002_soll_haben" ] = "H";
	$accounting_record_data[ "001_revenue" ] = 0;
	$accounting_record_data[ "007_debit" ] = 8000; // TODO: SET THIS YOURSELF!
	$accounting_record_data[ "008_credit" ] = $debtor_account;
	$accounting_record_data[ "010_transaction_date" ] = $posting_date;

	// OPTIONAL - may be needed for some customizations. Do not use (keep it commented out) in 
	// most cases or in case of doubt.
	// $accounting_record_data = apply_filters( 'wcdtvfe_create_receivables_record', $accounting_record_data, $order_id, $tax_rate_id, $accounting_group );

	$accounting_records[] = $accounting_record_data;

	return $accounting_records;
}

Sie haben Fragen oder möchten ein Angebot anfordern?

Jetzt Kontakt aufnehmen
crosslist