<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/

$products_id = $HTTP_GET_VARS['products_id'];
$vat = 1 + (tep_get_tax_rate($product_info['products_tax_class_id'])/100);
$stawka_vat = tep_get_tax_rate($product_info['products_tax_class_id']);

if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
  $display_nb = 1;
} else {
  $display_nb = 0;
}

//Sprawdzenie czy jest ukrywanie cen promocyjnych
$query_special_prices_hide = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " WHERE configuration_key = 'SPECIAL_PRICES_HIDE'");
$query_special_prices_hide_result = tep_db_fetch_array($query_special_prices_hide);
$special_hide = $query_special_prices_hide_result['configuration_value'];

////////////////////////////////////////////////////////////////////////////////////////////////

$retail = osc_ez(($currencies->display_price_nodiscount($product_info['products_id'],
$product_info['products_retail_price'],tep_get_tax_rate($product_info['products_tax_class_id']))));

$cena_promocyjna = tep_get_products_special_price($product_info['products_id']);
$cena_katalogowa = $product_info['products_retail_price'];
$cena_podstawowa = tep_xppp_getproductprice($product_info['products_id']);
$cena_z_rabatami = czysc_cene($currencies->display_price($product_info['products_id'],$product_info['products_price'], '',1,0,false));

$special_flag = false;
$cust_flag = false;

?>
<table border="0" cellspacing="0" cellpadding="2" width="300">

  <?php

  //TotalB2B start
  if ($product_info['products_retail_price'] != 0) {                                                                //Produkt ma cene katalogowa
    if ($new_price = tep_get_products_special_price($product_info['products_id']) ) {                               //Jest cena promocyjna
      $product_info['products_price'] = $new_price;                                                                 //Cena produktu = Cena promocyjna
      if ($special_hide == 'false') {                                                                               //Jezeli nie ma ukrywania cen promocyjnych
        $product_info_org['products_price'] = tep_xppp_getproductprice($product_info['products_id']);               //Niesformatowa podstawowa cena produktu bez promocji

        $special_price = $currencies->display_price_nodiscount($product_info['products_id'], $product_info['products_price'],tep_get_tax_rate($product_info['products_tax_class_id']),1,$display_nb);    //Sformatowana cena promocyjna

        $our = $currencies->display_price($product_info['products_id'], $product_info_org['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']),1,$display_nb);                                    //Sformatowana cena produktu
        $our_tylko_brutto = $currencies->display_price($product_info['products_id'], $product_info_org['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']),1,0);                                              //Sformatowana cena produktu tylko brutto

        if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
          $save2 = '<span class="kwot_netto">' . osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( $cena_katalogowa - tep_get_products_special_price($product_info['products_id'])), '', 1, 0)) . '</span><span class="netbru_text">' . TEXT_NETTO . '</span><br><span class="kwot_brutto">' . osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( round($cena_katalogowa*$vat,2) - round(tep_get_products_special_price($product_info['products_id'])*$vat,2)), '', 1, 0)) . '</span><span class="netbru_text">'.TEXT_BRUTTO.'</span>';
        } else {
          $save2 = osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( round($cena_katalogowa*$vat,2) - round(tep_get_products_special_price($product_info['products_id'])*$vat,2)), '', 1, 0));
        }

        $special_flag = true;                                                                                       //Flaga ze jest promocja

      } else {                                                                                                      //Cena promocyjna jest niewidoczna
        $product_info_org['products_price'] = tep_xppp_getproductprice($product_info['products_id']);               //Niesformatowa podstawowa cena produktu bez promocji

        $our = $currencies->display_price($product_info['products_id'], $product_info_org['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']),1,$display_nb);                                    //Sformatowana cena produktu bez promocji
        $our_tylko_brutto = $currencies->display_price($product_info['products_id'], $product_info_org['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']),1,0);                                              //Sformatowana cena produktu bez promocji tylko brutto

        if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
          $save2 = '<span class="kwot_netto">' . osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( $cena_katalogowa - czysc_cene($our)), '', 1, 0)) . '</span><span class="netbru_text">' . TEXT_NETTO . '</span><br><span class="kwot_brutto">' . osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( round($cena_katalogowa*$vat,2) - round(czysc_cene($our)*$vat,2)), '', 1, 0)) . '</span><span class="netbru_text">'.TEXT_BRUTTO.'</span>';
        } else {
          $save2 = osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( round($cena_katalogowa*$vat,2) - round(czysc_cene($our)*$vat,2)), '', 1, 0));
        }
      }
    } else {                                                                                                        //Nie ma ceny promocyjnej

      $product_info['products_price'] = tep_xppp_getproductprice($product_info['products_id']);                     //Niesformatowa podstawowa cena produktu

      $our = osc_ez($currencies->display_price($product_info['products_id'],$product_info['products_price'],tep_get_tax_rate($product_info['products_tax_class_id']),1,$display_nb));                                                                                                     //Sformatowana cena produktu
      $our_tylko_brutto = osc_ez($currencies->display_price($product_info['products_id'],$product_info['products_price'],tep_get_tax_rate($product_info['products_tax_class_id']),1,0));                                                                                                         //Sformatowana cena produktu tylko brutto

      if (DISPLAY_PRICE_BRUTTO_NETTO == 'true') {
        $save2 = '<span class="kwot_netto">' . osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( $cena_katalogowa - $cena_z_rabatami), '', 1, 0)) . '</span><span class="netbru_text">' . TEXT_NETTO . '</span><br><span class="kwot_brutto">' . osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( round($cena_katalogowa*$vat,2) - round($cena_z_rabatami*$vat,2)), '', 1, 0)) . '</span><span class="netbru_text">'.TEXT_BRUTTO.'</span>';
      } else {
        $save2 = osc_ez($currencies->display_price_nodiscount($product_info['products_id'], ( round($cena_katalogowa*$vat,2) - round($cena_z_rabatami*$vat,2)), '', 1, 0));
      }
    }

    //TotalB2B end & TotalB2B end

    echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_RETAIL_PRICE_INFO . '</td>';
    echo '<td class="PriceRetailProduct" align="right" valign="middle" width="50%"><span style="display:none" id="katalCena_bz">' .  $retail . '</span><span class="PriceRetailProduct" id="katalCena" style="text-decoration: line-through">' . $retail . '</span></td></tr>';

    if ($special_flag == true) {
      if ( $cena_z_rabatami < $cena_promocyjna ) {
        echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_PRICE_SPECIAL_INFO . '</td>';
        echo '<td align="right" width="50%"><span id="nowaCena" class="productSpecialPrice"><span id="nowaCena">'. $special_price . '</span></td></tr>';
      } else {
        echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_PRICE_INFO . '</td>';
        echo '<td class="Cena" align="right" width="50%"><span style="display:none" id="staraCena_bz">' .  $our_tylko_brutto . '</span><span class="SmallPriceProduct" id="staraCena" style="text-decoration: line-through">' .  $our . '</span></td></tr>';
        echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_PRICE_SPECIAL_INFO . '</td>';
        echo '<td align="right" width="50%"><span id="nowaCena" class="productSpecialPrice"><span id="nowaCena">'. $special_price . '</span></td></tr>';
      }
    } else {
      echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_PRICE_INFO . '</td>';
      echo '<td class="Cena" align="right" width="50%"><span id="nowaCena">' .  $our . '</span></td></tr>';
    }

    echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_SAVE_INFO . '</td>';
    echo '<td align="right" class="PriceRetailProduct" width="50%">' . $save2 . '</td></tr>';

  } else {

    echo '<tr><td align="right" class="smallText" width="50%">' . TEXT_PRODUCTS_PRICE_INFO . '</td>';
    echo '<td align="right" width="50%">' . (($product_info['products_price'] > 0) ? $products_price : ''.TEMPORARY_NO_PRICE.'') . '</td></tr>';

  }

?>
</table>

<?php
    function czysc_cene($data) {
      global $currency,$currencies;
      
      $data = str_replace ($currencies->get_thousands_point($currency),'',$data);
      $data = str_replace ($currencies->get_decimal_point($currency),',',$data);
      //
      $data = preg_replace ('/[^0-9,]/', '', $data);
      $data = preg_replace ('/ /', '', $data);
      $data = preg_replace ('/,/', '.', $data);

      return $data;
    }
?>