iFirma - Przesyłanie cen netto
The snippet can be accessed without any authentication.
Authored by
Krzysztof Dyszczyk
iFirma - Przesyłanie cen netto.php 942 B
add_filter( 'ifirma/domestic_invoice/data', 'wpdesk_ifirma_net_price', 10, 2 );
function wpdesk_ifirma_net_price( array $data, WPDesk_iFirma_Invoice_Data $document_data ) {
if ( $data['LiczOd'] === 'BRT' ) {
$data['LiczOd'] = 'NET';
$total = 0;
foreach ( $data['Pozycje'] as $item_id => $item ) {
if ( $data['Pozycje'][ $item_id ]['CenaJednostkowa'] ) {
$price = $data['Pozycje'][ $item_id ]['CenaJednostkowa'];
$vat = str_replace( '0.', '', $data['Pozycje'][ $item_id ]['StawkaVat'] );
$priceBeforeVat = $price / ( 1 + ( $vat / 100 ) );
$net_price = $price - $priceBeforeVat;
$item_price = round( $price - $net_price, 2 );
$total += $item_price;
$data['Pozycje'][ $item_id ]['CenaJednostkowa'] = $item_price;
}
}
}
$data['Zaplacono'] = $total;
$data['ZaplaconoNaDokumencie'] = $total;
return $data;
}
Please register or sign in to comment