Переглянути джерело

Pokaz oferty: oferta niesymetryczna

Piotr Labudda 11 роки тому
батько
коміт
53fbec1059

+ 5 - 2
SE/odt2xhtml/1379.umowa.php

@@ -247,8 +247,8 @@ SELECT
 FROM `USERS2_OFFERS_GROUPS` as t0
  left join `USERS2_OFFERS` as t1 on (t0.ID_NET!=0 and t1.ID=t0.ID_NET and t1.A_STATUS!='DELETED' and t1.P_SERVICE='NET'  )
  left join `USERS2_OFFERS` as t2 on (t0.ID_TV!=0  and t2.ID=t0.ID_TV  and t2.A_STATUS!='DELETED' and t2.P_SERVICE='TV'   )
- left join `USERS2_OFFERS` as t5 on (t0.ID_TEL!=0 and t5.ID=t0.ID_TEL and t5.A_STATUS!='DELETED' and t5.P_SERVICE='TEL'  )
- left join `USERS2_OFFERS` as t3 on (t0.ID_TVC!=0 and t3.ID=t0.ID_TVC and t3.A_STATUS!='DELETED' and t3.P_SERVICE='TVC'  )
+ left join `USERS2_OFFERS` as t5 on (t0.ID_TEL!=0 and t5.ID=t0.ID_TEL and t5.A_STATUS!='DELETED' and t5.P_SERVICE in('TEL','OPCJA_TEL')  )
+ left join `USERS2_OFFERS` as t3 on (t0.ID_TVC!=0 and t3.ID=t0.ID_TVC and t3.A_STATUS!='DELETED' and t3.P_SERVICE in('TVC','OPCJA_TVC')  )
  left join `USERS2_OFFERS` as t4 on (t0.ID_TVCP_1!=0 and t4.ID=t0.ID_TVCP_1 and t4.A_STATUS!='DELETED' and t4.P_SERVICE='TVCP' )
  left join `USERS2_OFFERS` as t6 on (t0.ID_TVCP_2!=0 and t6.ID=t0.ID_TVCP_2 and t6.A_STATUS!='DELETED' and t6.P_SERVICE='TVCP' )
  left join `USERS2_OFFERS` as t7 on (t0.ID_TVCP_3!=0 and t7.ID=t0.ID_TVCP_3 and t7.A_STATUS!='DELETED' and t7.P_SERVICE='TVCP' ) 
@@ -271,6 +271,9 @@ ORDER BY t0.ID DESC
 		die("DB error!");
 	}
 
+	if ($group_data['5_449'] == 'OPCJA_TEL') $group_data['5_449'] = 'TEL';
+	if ($group_data['3_449'] == 'OPCJA_TVC') $group_data['5_449'] = 'TVC';
+
 	$to_convert_encoding = array();
 	$to_convert_encoding []= '0_S_ALIAS';
 	$to_convert_encoding []= '0_451';

+ 43 - 0
SE/se-lib/PokazOfertyView.php

@@ -51,6 +51,7 @@ body{font-family:arial; font-size:12px;}
  #tbl-oferty .cell-zysk {border-left:2px solid red; background:#FFB5B5; text-align:right; white-space:nowrap;}
 
 #tbl-oferty .row-oferty-opcje td {background:#FBFFCF; color:#aaa;}
+#tbl-oferty .row-oferty-opcje-srv td {background:#CFFCFF; color:#aaa;}
 #tbl-oferty .row-oferty-opcje-selected td {background:#fff; color:#444;}
 #tbl-oferty tbody.hide_options .row-oferty-opcje {display:none}
 
@@ -589,6 +590,21 @@ function show_opcje(cell_id, service){
 		} else {
 			n.append('<tr class=\"row-oferty-opcje\"><td colspan=\"{$cols}\">Brak danych</td></tr>');
 		}
+
+		if ('NET' === service) {
+			tbody_opcje=jQuery('#oferty-opcje-service-OPCJA_TVC').find('tr');
+			if (tbody_opcje.length > 0) {
+				for (var i = 0; i < tbody_opcje.length; i++) {
+					n.append(jQuery(tbody_opcje[i]).clone());
+				}
+			}
+			tbody_opcje=jQuery('#oferty-opcje-service-OPCJA_TEL').find('tr');
+			if (tbody_opcje.length > 0) {
+				for (var i = 0; i < tbody_opcje.length; i++) {
+					n.append(jQuery(tbody_opcje[i]).clone());
+				}
+			}
+		}
 	} else {
 		if (!n.hasClass('hide_options')) {
 			n.addClass('hide_options');
@@ -603,6 +619,33 @@ function show_opcje(cell_id, service){
 }
 function select_option(n){
 	n=jQuery(n);
+
+	console.log('n.data(p_service):', n.data('p_service'), 'n.val', n.val());
+	var p_service = n.data('p_service'), opcja_id = n.val();
+	if ('OPCJA_' == p_service.substr(0, 6) && opcja_id > 0) {
+		var parentTr = n.parent().parent(),
+			service = p_service.substr(6);
+
+		// TODO: hide/show if checked or not
+		console.log('TODO: n.prop(checked): ', n.prop('checked'));
+		if (n.prop('checked')) {
+			console.log('TODO: p_service: ', p_service, 'n.val()', n.val(), 'service to load:', service, 'parentTr', parentTr);
+			var tbody_opcje=jQuery('#oferty-opcje-service-' + service).find('tr');
+			if (tbody_opcje.length > 0) {
+				for (var i = 0; i < tbody_opcje.length; i++) {
+					var tr = jQuery(tbody_opcje[i]).clone();
+					tr.addClass('row-oferty-opcje-to-' + opcja_id);
+					tr.insertAfter(parentTr);
+				}
+			} else {
+				n.append('<tr class=\"row-oferty-opcje\"><td colspan=\"{$cols}\">Brak danych</td></tr>');
+			}
+		}
+		else {
+			parentTr.nextAll('.row-oferty-opcje-to-' + opcja_id).remove();
+		}
+	}
+	// <a href=\"#\" onclick=\"return show_opcje('3072-2179', 'NET');\">opcje</a>
 	n.parents('tr:first').toggleClass('row-oferty-opcje-selected');
 }
 function print_umowa(n){

+ 278 - 13
SE/superedit-POKAZ_OFERTY_AKTUALNE_FUNC.php

@@ -671,7 +671,11 @@ $oferty_group_cols ['0_1627']= array('label'=>"", 'title'=>"", 'field'=>'M_REWIR
 
 	$oferty_filters = array();
 	$oferty_filters ['f_COM'] = array('label'=>"COMPANY", 'values'=>array('BIALL-NET'=>"t0.`P_SERVICE_COMPANY`='BN'", 'NETDAY'=>"t0.`P_SERVICE_COMPANY`='NETDAY'"), 'default'=>"BIALL-NET");
-	$oferty_filters ['f_A_STATUS'] = array('label'=>"Oferty A_STATUS", 'values'=>array('NORMAL'=>"t0.`A_STATUS`='NORMAL'", 'WSZYSTKIE'=>"t0.`A_STATUS`in('WAITING','NORMAL')"), 'default'=>"NORMAL");
+	$oferty_filters ['f_A_STATUS'] = array('label'=>"Oferty A_STATUS", 'default'=>"NORMAL");
+	$oferty_filters ['f_A_STATUS']['values'] = array();
+	$oferty_filters ['f_A_STATUS']['values']['NORMAL'] = "t0.`A_STATUS`='NORMAL'";
+	$oferty_filters ['f_A_STATUS']['values']['WSZYSTKIE'] = "t0.`A_STATUS`in('WAITING','NORMAL')";
+	$oferty_filters ['f_A_STATUS']['values']['TEST'] = "t0.`A_STATUS`in('WAITING','NORMAL','MONITOR')";
 	$oferty_filters ['f_ID_NET'] = array('label'=>"Internet", 'values'=>array('MOZE'=>"", 'TAK'=>"t0.`ID_NET`>0", 'NIE'=>"t0.`ID_NET`=0"), 'default'=>"MOZE");
 	$oferty_filters ['f_ID_TV'] = array('label'=>"TV", 'values'=>array('MOZE'=>"", 'TAK'=>"t0.`ID_TV`>0", 'NIE'=>"t0.`ID_TV`=0"), 'default'=>"MOZE");
 	$oferty_filters ['f_ID_TVC'] = array('label'=>"TVC", 'values'=>array('MOZE'=>"", 'TAK'=>"t0.`ID_TVC`>0", 'NIE'=>"t0.`ID_TVC`=0"), 'default'=>"MOZE");
@@ -914,8 +918,8 @@ SELECT
 FROM `USERS2_OFFERS_GROUPS` as t0
  left join `USERS2_OFFERS` as t1 on (t0.ID_NET!=0 and t1.ID=t0.ID_NET and t1.A_STATUS!='DELETED' and t1.P_SERVICE='NET'  )
  left join `USERS2_OFFERS` as t2 on (t0.ID_TV!=0  and t2.ID=t0.ID_TV  and t2.A_STATUS!='DELETED' and t2.P_SERVICE='TV'   )
- left join `USERS2_OFFERS` as t5 on (t0.ID_TEL!=0 and t5.ID=t0.ID_TEL and t5.A_STATUS!='DELETED' and t5.P_SERVICE='TEL'  )
- left join `USERS2_OFFERS` as t3 on (t0.ID_TVC!=0 and t3.ID=t0.ID_TVC and t3.A_STATUS!='DELETED' and t3.P_SERVICE='TVC'  )
+ left join `USERS2_OFFERS` as t5 on (t0.ID_TEL!=0 and t5.ID=t0.ID_TEL and t5.A_STATUS!='DELETED' and t5.P_SERVICE in('TEL','OPCJA_TEL')  )
+ left join `USERS2_OFFERS` as t3 on (t0.ID_TVC!=0 and t3.ID=t0.ID_TVC and t3.A_STATUS!='DELETED' and t3.P_SERVICE in('TVC','OPCJA_TVC')  )
  left join `USERS2_OFFERS` as t4 on (t0.ID_TVCP_1!=0 and t4.ID=t0.ID_TVCP_1 and t4.A_STATUS!='DELETED' and t4.P_SERVICE='TVCP' )
  left join `USERS2_OFFERS` as t6 on (t0.ID_TVCP_2!=0 and t6.ID=t0.ID_TVCP_2 and t6.A_STATUS!='DELETED' and t6.P_SERVICE='TVCP' )
  left join `USERS2_OFFERS` as t7 on (t0.ID_TVCP_3!=0 and t7.ID=t0.ID_TVCP_3 and t7.A_STATUS!='DELETED' and t7.P_SERVICE='TVCP' )
@@ -944,6 +948,9 @@ if ($DBG) {echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;
 		if ($row['5_1385'] > 0) $oferty_costs_ids[ $row['5_1385'] ] = true;
 		if ($row['6_1385'] > 0) $oferty_costs_ids[ $row['6_1385'] ] = true;
 		if ($row['7_1385'] > 0) $oferty_costs_ids[ $row['7_1385'] ] = true;
+
+		if ($row['5_449'] == 'OPCJA_TEL') $row['5_449'] = 'TEL';
+		if ($row['3_449'] == 'OPCJA_TVC') $row['5_449'] = 'TVC';
 	}
 
 	$oferty_costs = PokazOfertyHelper::get_offers_costs_by_offer_ids(array_keys($oferty_costs_ids));
@@ -1278,19 +1285,24 @@ $specialFltrs = array();
 	echo '</div>';
 //}
 
-$oferty_opcje = PokazOfertyHelper::get_oferty_opcje();
+$oferty_opcje_all = PokazOfertyHelper::get_oferty_opcje_all();
 $oferty_opcje_cols = PokazOfertyHelper::get_oferty_opcje_visible_cols();
 //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">$oferty_opcje: ';print_r($oferty_opcje);echo'</pre>';
 //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">';print_r($oferty_group_add_info ['labels']);echo'</pre>';
 echo '<table cellspacing="0" cellpadding="0" border="1" id="tbl-oferty-opcje" style="display:none;">';
 echo '<caption>' . "Oferty dodatkowe" . '</caption>';
-foreach ($oferty_opcje as $k_service => $v_oferty) {
+foreach ($oferty_opcje_all as $k_service => $v_oferty) {
+	$isOpcjaService = in_array($k_service, array('OPCJA_TVC','OPCJA_TEL'));
+
 	echo '<tbody id="oferty-opcje-service-'.$k_service.'">';
 	foreach ($v_oferty as $k_id => $v_oferta) {
-		echo '<tr class="row-oferty-opcje">';
+		echo '<tr class="row-oferty-opcje' . (($isOpcjaService)? ' row-oferty-opcje-srv' : '') . '">';
 			echo '<td>';
+				if ($isOpcjaService) {
+					echo substr($k_service, 6) . '<br>';
+				}
 				$option_name = 'id_options_' . $k_service . '[]';
-				echo '<input type="checkbox" name="'.$option_name.'" value="' . $k_id . '" onclick="return select_option(this);" />';
+				echo '<input type="checkbox" name="'.$option_name.'" value="' . $k_id . '" data-p_service="' . $k_service . '" onclick="return select_option(this);" />';
 			echo '</td>';
 			foreach ($oferty_opcje_cols as $k_field => $v_type_label) {
 				if ($k_field == 'koszt') {
@@ -1630,6 +1642,22 @@ function POKAZ_OFERTY_AKTUALNE_FUNC__dodaj_aneks() {
 	$con = new PokazOfertyController();
 	$con->set_params_from_request();
 echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;display:none">con: (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($con);echo'</pre>';
+	if ($con->hasOptionsToServices()) {
+		?>
+		<div class="alert alert-warning">
+			<strong>Uwaga wersja testowa!</strong> wymagane utworzenie specjalengo pakietu na podstawie wybranych opcji.
+		</div>
+		<?php if (!$con->convertOptionsToSrv()) : ?>
+			<div class="alert alert-error">
+				<strong>Bład!</strong> nie udało się utworzyć nowej grupy na podstawie wybranych parametrów.
+			</div>
+		<?php else : ?>
+			<div class="alert alert-success">
+				Nowy numer oferty to <?php echo $con->get_param('id_group'); ?>.
+			</div>
+		<?php endif; ?>
+		<?php
+	}
 
 	echo '<h1>';
 		echo '<a href="' . $con->url(array('task'=>'')) . '">' . "POKAZ OFERTY AKTUALNE" . '</a>';
@@ -1900,6 +1928,8 @@ class PokazOfertyController {
 		$this->id_options = array();
 		$this->active_deals_by_id = array();
 		$this->group = null;
+		$this->allowed_options_to_srv = array('TVC'=>'OPCJA_TVC', 'TEL'=>'OPCJA_TEL');
+		$this->options_to_srv = array();// special options to convert to services
 	}
 
 	/**
@@ -1925,6 +1955,187 @@ class PokazOfertyController {
 			$this->params['id_options_' . $v_option] = V::get('id_options_' . $v_option . '', array(), $_GET, 'array');
 			$this->id_options[$v_option] = V::get('id_options_' . $v_option . '', array(), $_GET, 'array');
 		}
+
+		// fetch id options to services
+		foreach ($this->allowed_options_to_srv as $kSrv => $vOption) {
+			$this->id_options_to_srv[$kSrv]['id_options_' . $vOption] = V::get('id_options_' . $vOption, array(), $_GET, 'array');
+		}
+		// filter options - remove empty and not numeric values
+		foreach ($this->allowed_options_to_srv as $kSrv => $vOption) {
+			if (is_array($vOption) && !empty($vOption)) foreach ($vOption as $kOption => $vValue) {
+				$this->id_options_to_srv[$kSrv][$kOption] = array_filter($this->id_options_to_srv[$kSrv][$kOption], function($value) {
+					return !empty($value) && is_numeric($value);
+				});
+			}
+			$this->id_options_to_srv[$kSrv] = array_filter($this->id_options_to_srv[$kSrv], function($value) {
+				return !empty($value);
+			});
+		}
+		$this->id_options_to_srv = array_map(function($value) {
+			if (count($value) == 1) {
+				$vOptions = reset($value);
+				if (count($vOptions) == 1) {
+					return reset($vOptions);
+				}
+			}
+			return null;
+		}, $this->id_options_to_srv);
+		$this->id_options_to_srv = array_filter($this->id_options_to_srv, function($value) {
+			return !empty($value);
+		});
+	}
+
+	public function hasOptionsToServices() {
+		return !empty($this->id_options_to_srv);
+	}
+
+	public function convertOptionsToSrv() {
+		$DBG = ('123' == V::get('DBG', '', $_GET));
+		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->id_options_to_srv);echo'</pre>';}
+
+		$db = DB::getDB();
+		if (!$db) return false;
+
+		$group = $this->get_group();
+		if (!$group) return false;
+
+		/*
+		 * 'TVC' => ID_TVC in USERS2_OFFERS_GROUPS
+		 * 'TEL' => ID_TEL in USERS2_OFFERS_GROUPS
+		 */
+		$sqlSearch = array();
+		foreach ($this->id_options_to_srv as $kService => $vOfferId) {
+			switch ($kService) {
+				case 'TVC': $sqlSearch[] = "g.`ID_TVC`='{$vOfferId}'"; break;
+				case 'TEL': $sqlSearch[] = "g.`ID_TEL`='{$vOfferId}'"; break;
+				default:
+			}
+		}
+		if (count($sqlSearch) <= 0) return false;
+		$sqlSearch = implode(" and ", $sqlSearch);
+
+		$offersIds = array_values($this->id_options_to_srv);
+		if ($this->group->_data['ID_NET'] > 0) $offersIds[] = $this->group->_data['ID_NET'];
+		$offersByIds = PokazOfertyHelper::get_offers_by_id($offersIds);
+		foreach ($this->id_options_to_srv as $kService => $vOfferId) {
+			if (empty($offersByIds[$vOfferId])) {
+				return false;
+			}
+		}
+
+		$sqlIdGroup = $this->params['id_group'];
+		$sql = "select g.`ID`
+			from `USERS2_OFFERS_GROUPS` as g
+			where g.`A_STATUS` in('WAITING','NORMAL','MONITOR')
+				and {$sqlSearch}
+				and g.`PARENT_ID`='{$sqlIdGroup}'
+		";
+		if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';}
+		$groupsFound = array();
+		$res = $db->query($sql);
+		while ($r = $db->fetch($res)) {
+			$groupsFound[] = $r->ID;
+		}
+
+		if (empty($groupsFound)) {
+			$sqlObj = (object)array_map(function($v) { return $v; }, $this->group->_data);
+			$sqlObj->PARENT_ID = $sqlObj->ID;
+			unset($sqlObj->ID);
+			/* $sqlObj:
+					[S_ALIAS] => ADRENALINET#7
+					[P_PROMOTION_NAME] => TESTOWA OFERTA BIALL-NET#1
+					[ID_TVC] => 0
+					[ID_TEL] => 0
+					[RABAT_IF_OPCJA_TVC] => 10
+					[RABAT_IF_OPCJA_TEL] => 10
+			 */
+			/* $offersByIds[$vOfferId]:
+            [S_ALIAS] => PAKIET CYFROWY - PLATYNOWY
+            [P_SERVICE_NAME] => PAKIET CYFROWY - PLATYNOWY
+            [P_PROMOTION_NAME] => OFERTA TESTOWA
+			*/
+			$rabat = 0;
+			foreach ($this->id_options_to_srv as $kService => $vOfferId) {
+				switch ($kService) {
+					case 'TVC':
+						$sqlObj->ID_TVC = $vOfferId;
+						$sqlObj->S_ALIAS .= " + {$offersByIds[$vOfferId]->S_ALIAS}"; 
+						$sqlObj->P_PROMOTION_NAME .= " + {$offersByIds[$vOfferId]->P_SERVICE_NAME}"; 
+						if ($sqlObj->RABAT_IF_OPCJA_TVC > 0) {
+							$rabat += $sqlObj->RABAT_IF_OPCJA_TVC;
+						}
+						break;
+					case 'TEL':
+						$sqlObj->ID_TEL = $vOfferId;
+						$sqlObj->S_ALIAS .= " + {$offersByIds[$vOfferId]->S_ALIAS}"; 
+						$sqlObj->P_PROMOTION_NAME .= " + {$offersByIds[$vOfferId]->P_SERVICE_NAME}"; 
+						if ($sqlObj->RABAT_IF_OPCJA_TEL > 0) {
+							$rabat += $sqlObj->RABAT_IF_OPCJA_TEL;
+						}
+						break;
+					default:
+				}
+			}
+
+			if ($rabat > 0) {
+				$offerNet = $db->get_by_id('USERS2_OFFERS', $sqlObj->ID_NET);
+				$newOfferNet = new stdClass();
+				$rabatPr = 1 - $rabat/100;
+				$newOfferNet->P_CONTRACT_PRICE    = round($rabatPr * $offerNet->P_CONTRACT_PRICE, 2);
+				$newOfferNet->P_PROMO_MONTH_PRICE = round($rabatPr * $offerNet->P_PROMO_MONTH_PRICE, 2);
+
+				$sql = "select o.`ID`
+					from `USERS2_OFFERS` as o
+					where o.`A_STATUS` in('WAITING','NORMAL','MONITOR')
+						and o.`PARENT_ID`={$sqlObj->ID_NET}
+						and o.`P_CONTRACT_PRICE`='{$newOfferNet->P_CONTRACT_PRICE}'
+						and o.`P_PROMO_MONTH_PRICE`='{$newOfferNet->P_PROMO_MONTH_PRICE}'
+				";
+				$foundOfferNet = null;
+				$res = $db->query($sql);
+				while ($r = $db->fetch($res)) {
+					$foundOfferNet = $r;
+				}
+
+				if (!$foundOfferNet) {
+					foreach ($offerNet as $kFld => $vFld) {
+						if (!isset($newOfferNet->$kFld)) {
+							if ('ID' == $kFld) continue;
+							if ('_NETTO' == substr($kFld, -6)) continue;
+							if ('A_' == substr($kFld, 0, 2)) continue;
+							$newOfferNet->$kFld = $offerNet->$kFld;
+						}
+					}
+					$newOfferNet->S_ALIAS .= " (rabat {$rabat}%)";
+					$newOfferNet->P_SERVICE_NAME .= " (rabat {$rabat}%)";
+					$newOfferNet->P_PROMOTION_NAME .= " (rabat {$rabat}%)";
+					$newOfferNet->PARENT_ID = $offerNet->ID;
+					$newOfferNetId = $db->ADD_NEW_OBJ('USERS2_OFFERS', $newOfferNet);
+					if ($newOfferNetId <= 0) {
+						return false;
+					}
+				}
+				else {
+					$newOfferNetId = $foundOfferNet->ID;
+				}
+				if ($newOfferNetId <= 0) return false;
+				$sqlObj->ID_NET = $newOfferNetId;
+			}
+
+			$sqlObj->A_STATUS = 'WAITING';
+			if($DBG){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sqlObj (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sqlObj);echo'</pre>';}
+			$newGroupId = $db->ADD_NEW_OBJ('USERS2_OFFERS_GROUPS', $sqlObj);
+			if ($newGroupId <= 0) return false;
+		} else {
+			$newGroupId = reset($groupsFound);
+			if ($newGroupId <= 0) return false;
+		}
+
+		$this->params['id_group'] = $newGroupId;
+		unset($this->group);
+		$group = $this->get_group();
+		$group->fetch_offers();
+		return true;
 	}
 
 	/**
@@ -2641,7 +2852,7 @@ class PokazOfertyHelper {
 		return $deal;
 	}
 
-	function get_group($id_group) {
+	public static function get_group($id_group) {
 		$group = null;
 		if ($id_group <= 0) {
 			return $group;
@@ -2662,7 +2873,9 @@ class PokazOfertyHelper {
 				t0.`ID_TVCP_2` ,
 				t0.`ID_TVCP_3` ,
 				t0.`ID_TVCP_4` ,
-				t0.`ID_TEL`
+				t0.`ID_TEL`,
+				t0.`RABAT_IF_OPCJA_TVC`,
+				t0.`RABAT_IF_OPCJA_TEL`
 			from `USERS2_OFFERS_GROUPS` as t0
 			where t0.`ID`='" . $id_group . "'
 			group by t0.ID
@@ -2676,7 +2889,7 @@ class PokazOfertyHelper {
 		return $group;
 	}
 
-	function get_offers_by_id($offers_ids, $params = array()) {
+	public static function get_offers_by_id($offers_ids, $params = array()) {
 		$offers = array();
 		$db = DB::getDB();
 		$sql_select = array();
@@ -2742,7 +2955,9 @@ class PokazOfertyHelper {
 			echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">sql (F.' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($sql);echo'</pre>';
 		}
 		while ($r = $db->fetch($res)) {
-			$offers [$r->ID]= $r;
+			if ($r->P_SERVICE == 'OPCJA_TVC') $r->P_SERVICE = 'TVC';
+			else if ($r->P_SERVICE == 'OPCJA_TEL') $r->P_SERVICE = 'TEL';
+			$offers[$r->ID] = $r;
 		}
 		return $offers;
 	}
@@ -2783,7 +2998,7 @@ class PokazOfertyHelper {
 	 * @param array $offer_ids
 	 * @returns array $oferty_costs
 	 */
-	function get_offers_costs_by_offer_ids($offer_ids = array()) {
+	public static function get_offers_costs_by_offer_ids($offer_ids = array()) {
 		$oferty_costs = array();
 		$db = DB::getDB();
 		$sql_where = "";
@@ -2808,7 +3023,7 @@ class PokazOfertyHelper {
 	 * @param array $offer_ids
 	 * @returns array $oferty_costs_start
 	 */
-	function get_offers_costs_start_by_offer_ids($offer_ids = array()) {
+	public static function get_offers_costs_start_by_offer_ids($offer_ids = array()) {
 		$oferty_costs_start = array();
 		$db = DB::getDB();
 		$sql_where = "";
@@ -2890,6 +3105,56 @@ class PokazOfertyHelper {
 		return $oferty_opcje;
 	}
 
+	function get_oferty_opcje_all() {
+		$oferty_opcje = array();// [ service ] => array(ID => {oferta})
+		$oferty_costs = self::get_offers_costs_by_offer_ids();
+		// TODO: use [P_OFFER_TERM_BEGIN] => 0000-00-00, [P_OFFER_TERM] => 2011-12-31, [M_REWIR] => gd
+		$sqlStatus = array('NORMAL');
+		if (V::get('TEST_MONITOR', '', $_GET)) $sqlStatus[] = 'MONITOR';
+		$sqlStatus = "and o.`A_STATUS` in('" . implode("','", $sqlStatus) . "')";
+		$sql = "select
+				o.`ID`
+				, o.`P_SERVICE`
+				, o.`P_SERVICE_PARENT`
+				, o.`P_SERVICE_NAME`
+				, o.`P_INSTALL_QUOTE`
+				, o.`P_INSTALL_QUOTE_NORMAL`
+				, o.`P_CONTRACT_PRICE`
+				, o.`P_PROMO_MONTH_PRICE`
+				, o.`P_NORMAL_PRICE`
+				, o.`P_DEAL_PROMO_MONTHS`
+				, o.`P_DEALTERM_MONTHS`
+				, o.`ID_PRODUKT` as `ID_PRODUKT`
+				, '' as `upust`
+				, '' as `koszt`
+				, IF(o.`ID_PROCES`>0, o.`ID_PROCES`, '') as `ID_PROCES`
+				, o.`S_OTHER_INFO`
+				, o.`S_TECHNOLOGY`
+				, o.`P_MULTIROOM_ADD_CARDS`
+				, o.`P_MULTIROOM_ADD_DEKODER_SD`
+				, o.`P_MULTIROOM_ADD_DEKODER_HD`
+				, o.`P_MULTIROOM_ADD_MODUL_CAM`
+			from `USERS2_OFFERS` as o
+			where o.`P_SERVICE` in('OPCJE', 'OPCJA_TVC', 'OPCJA_TEL')
+				{$sqlStatus}
+				and o.`P_SERVICE_COMPANY`='BN'
+			order by o.`ID_PRODUKT` desc, o.`P_CONTRACT_PRICE` desc
+		";
+		$res = DB::query($sql);
+		while ($r = DB::fetch($res)) {
+			$r->srednia = '';
+			if (array_key_exists($r->ID, $oferty_costs)) {
+				$r->koszt = $oferty_costs[ $r->ID ];
+			}
+			if (in_array($r->P_SERVICE, array('OPCJA_TVC', 'OPCJA_TEL'))) {
+				$oferty_opcje[ $r->P_SERVICE ][ $r->ID ] = $r;
+			} else {
+				$oferty_opcje[ $r->P_SERVICE_PARENT ][ $r->ID ] = $r;
+			}
+		}
+		return $oferty_opcje;
+	}
+
 	function find_groups_by_offers($oferty, $todo_test_deal_id = 0) {
 		$db = DB::getDB();
 		$groups = array();