فهرست منبع

Pokaz oferty - umowy zysk tip

Piotr Labudda 11 سال پیش
والد
کامیت
ad0bebadf8

+ 1 - 1
SE/VERSION

@@ -1 +1 @@
-3.9.7.7
+3.9.7.8

+ 12 - 12
SE/se-lib/ColumnDealsStatus.php

@@ -3,15 +3,15 @@
 
 class ColumnDealsStatus {
 
-	function get_table() {
+	public static function get_table() {
 		return 'temp_DEALS_STATUS';
 	}
 
-	function get_drop_query() {
+	public static function get_drop_query() {
 		return "DROP TABLE IF EXISTS `" . self::get_table() . "`;";
 	}
 
-	function get_create_query() {
+	public static function get_create_query() {
 		return "CREATE TABLE IF NOT EXISTS `" . self::get_table() . "` (
 			`ID_DEALS` int(11) NOT NULL,
 			`ID_BILLING_USERS` int(11) NOT NULL,
@@ -27,7 +27,7 @@ class ColumnDealsStatus {
 		";
 	}
 
-	function get_update_query($userID = null) {
+	public static function get_update_query($userID = null) {
 		$sqlUserID = '';
 		if ($userID > 0) {
 			$sqlUserID = " and `ID_BILLING_USERS`='{$userID}' ";
@@ -39,7 +39,7 @@ class ColumnDealsStatus {
 		";
 	}
 
-	function get_insert_query($userID = null) {
+	public static function get_insert_query($userID = null) {
 		global $A_STATUS_L2_SQL;// @from .config.php
 		if (empty($A_STATUS_L2_SQL)) {
 			die('Config Error: variable "$A_STATUS_L2_SQL" not exists!');
@@ -112,7 +112,7 @@ class ColumnDealsStatus {
 		";
 	}
 
-	function get_last_update() {
+	public static function get_last_update() {
 		$db = DB::getDB();
 		$_table = self::get_table();
 		if (empty($_SESSION["{$_table}_COLUMN"]['_last_update'])) {
@@ -128,18 +128,18 @@ class ColumnDealsStatus {
 		return $_SESSION["{$_table}_COLUMN"]['_last_update'];
 	}
 
-	function set_last_update( $date ) {
+	public static function set_last_update( $date ) {
 		$_SESSION[self::get_table().'_COLUMN']['_last_update'] = $date;
 	}
 
-	function is_updated() {
+	public static function is_updated() {
 		if (self::get_last_update() >= date("Y-m-d")) {
 			return true;
 		}
 		return false;
 	}
 
-	function run_update( $force = false, &$dbg_msgs = array() ) {
+	public static function run_update( $force = false, &$dbg_msgs = array() ) {
 		$run = false;
 		if ($force) {
 			$run = true;
@@ -171,7 +171,7 @@ class ColumnDealsStatus {
 		return true;
 	}
 
-	function run_update_for_user($userID) {
+	public static function run_update_for_user($userID) {
 		$db = DB::getDB();
 
 		$_table = self::get_table();
@@ -189,7 +189,7 @@ class ColumnDealsStatus {
 		return true;
 	}
 
-	function get_deals_stats_by_months( $force = false ) {
+	public static function get_deals_stats_by_months( $force = false ) {
 		$deals_stats = array();
 
 		// read from cache if not force
@@ -261,7 +261,7 @@ class ColumnDealsStatus {
 		return $deals_stats;
 	}
 
-	function get_deals_stats_by_month($_month, $_limitstart) {
+	public static function get_deals_stats_by_month($_month, $_limitstart) {
 		$sql_where = "";
 		$sql_limit = "limit 100";
 		if ($_limitstart > 0) {

+ 73 - 1
SE/se-lib/PokazOfertyView.php

@@ -582,7 +582,7 @@ jQuery(document).ready(function(){
 		<?php
 	}
 
-	function print_js_umowa($cols = null) {
+	public static function print_js_umowa($cols = null) {
 		$cols = (!$cols)? 10 : $cols;
 		return '<script type="text/javascript">' . "
 function show_opcje(cell_id, service){
@@ -666,6 +666,78 @@ function print_umowa(n){
 	n.attr('href', n.attr('href_base') + add);
 	return true;
 }
+
+function umowaZysk_click(n) {
+	var n = $(n);
+	var visible = n.data('tip-visible');
+	console.log('visible: ', visible, ' if', (!visible));
+	if (!visible) {
+		n.data('tip-visible', true);
+	} else {
+		n.data('tip-visible', false);
+	}
+	n.popover('destroy');
+
+
+	if (!visible) {
+		var tip = {
+			placement: 'left',
+			html: true,
+			trigger: 'manual',
+			title: 'Zysk',
+			content: 'loading...'
+		};
+		n.popover(tip);
+		n.popover('show');
+
+		umowaZysk_load(n);
+	}
+	return false;
+}
+
+function umowaZysk_loadResult(n, result) {
+	var content = 'Error!';
+	if (result && result.html) {
+		content = result.html;
+	}
+
+	n.data('tip-visible', true);
+	n.popover('destroy');
+	var tip = {
+		placement: 'left',
+		html: true,
+		trigger: 'manual',
+		title: 'Zysk',
+		content: content
+	};
+	$(n).popover(tip);
+	$(n).popover('show');
+}
+
+function umowaZysk_load(n) {
+	var reqData = {};
+
+	n.parents('table').find('input[type=\'checkbox\']:checked').each(function(ind, o){
+		if (o.value > 0) {
+			reqData[o.name] = o.value;
+		}
+	});
+	reqData['id_group'] = n.data('id_group');
+
+	jQuery.ajax({
+		data: reqData,
+		dataType: 'json',
+		type: 'GET',
+		url: 'index.php?FUNCTION_INIT=POKAZ_OFERTY_AKTUALNE_FUNC&HEADER_NOT_INIT=YES&task=ajaxUmowaZysk'
+	})
+	.done(function(data, textStatus, jqXHR){
+		umowaZysk_loadResult(n, data);
+	})
+	.fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
+		umowaZysk_loadResult(n, 'error');
+	});
+}
+
 " . '</script>';
 	}
 

+ 96 - 31
SE/superedit-POKAZ_OFERTY_AKTUALNE_FUNC.php

@@ -85,6 +85,10 @@ switch ($_GET['task']) {
 		POKAZ_OFERTY_AKTUALNE_FUNC__activate_services_voip();
 		return;
 		break;
+	case 'ajaxUmowaZysk':
+		POKAZ_OFERTY_AKTUALNE_FUNC__ajaxUmowaZysk();
+		return;
+		break;
 	default:
 		
 }
@@ -1070,7 +1074,6 @@ if ($DBG) {echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;
 
 $pokaz_oferty_view = new PokazOfertyView();
 echo $pokaz_oferty_view->print_css();
-echo '<script type="text/javascript" src="stuff/jquery.js"></script>';
 echo '<script type="text/javascript">' . "
 jQuery(document).ready(function(){
 	jQuery('#tbl-oferty').on('click', '.tbl-row', function(event){
@@ -1446,7 +1449,7 @@ foreach ($oferty as $row) {
 				echo '</thead>';
 				echo '<tfoot>';
 					echo '<tr>';
-						echo '<th colspan="'.(count($oferty_group_add_info['labels']) + 1).'" style="text-align:left">';
+						echo '<th colspan="'.(count($oferty_group_add_info['labels']) + 2).'" style="text-align:left">';
 							$link_href = "?MENU_INIT=POKAZ_OFERTY_AKTUALNE_FUNC";
 							//"S_ADDRESS_STREET=&ADD=SZUKAJ";
 							$link_href .= "&task=dodaj_aneks";
@@ -1455,6 +1458,11 @@ foreach ($oferty as $row) {
 							$link_href .= "&user_id=" . $_GET['user_id'];
 							$js = "return print_umowa(this);";
 							echo '<a href="' . $link_href . '" href_base="' . $link_href . '" title="' . "Dodaj aneks lub nową umowę" . '" onclick="' . $js . '">' . '<img src="icon/add.gif" alt="+" />' . " Dodaj aneks lub nową umowę" . '</a>';
+
+							$js = "return umowaZysk_click(this); return false;";
+							?>
+								<a class="btn btn-mini pull-right" href="#" data-id_group="<?php echo $row['0_1380']; ?>" title="Oblicz zysk" onclick="<?php echo $js; ?>">Oblicz zysk</a>
+							<?php
 						echo '</th>';
 					echo '</tr>';
 				echo '</tfoot>';
@@ -1464,7 +1472,8 @@ foreach ($oferty as $row) {
 							echo '<tbody id="' . $html_cell_id . '">';
 							echo '<tr>';
 								echo '<td>';
-									echo reset(explode('_', $v_p_service));
+									$outPService = explode('_', $v_p_service);
+									echo reset($outPService);
 									echo '<br />';
 									$js = "return show_opcje('" . $html_cell_id . "', '" . $v_p_service . "');";
 									echo '<a href="' . "#" . '" onclick="' . $js . '">' . "opcje" . '</a>';
@@ -2341,7 +2350,7 @@ class PokazOfertyHelper {
 	 * @return array or null
 	 *   [ID_BILLING_USERS => array of object deal]
 	 */
-	function get_deals_active_by_street($S_ADDRESS_STREET) {
+	public static function get_deals_active_by_street($S_ADDRESS_STREET) {
 		return self::get_deals_active(array('S_ADDRESS_STREET'=>$S_ADDRESS_STREET));
 	}
 
@@ -2351,19 +2360,19 @@ class PokazOfertyHelper {
 	 * @return array or null
 	 *   [ID_DEALS => deal]
 	 */
-	function get_deals_active_with_info($S_ADDRESS_STREET, $ID_BILLING_USERS, $only_active = true) {
+	public static function get_deals_active_with_info($S_ADDRESS_STREET, $ID_BILLING_USERS, $only_active = true) {
 		$active_deals_by_id = self::get_deals_active(array('S_ADDRESS_STREET'=>$S_ADDRESS_STREET, 'ID_BILLING_USERS'=>$ID_BILLING_USERS, 'return_by'=>'ID', 'P_DEALNUMBER'=>true));
 		self::deals_active_add_info($active_deals_by_id, $ID_BILLING_USERS, $only_active);
 		return $active_deals_by_id;
 	}
 
-	function get_deals_active_by_user($ID_BILLING_USERS, $only_active = true) {
+	public static function get_deals_active_by_user($ID_BILLING_USERS, $only_active = true) {
 		$active_deals_by_id = self::get_deals_active(array('ID_BILLING_USERS'=>$ID_BILLING_USERS, 'return_by'=>'ID', 'P_DEALNUMBER'=>true));
 		self::deals_active_add_info($active_deals_by_id, $ID_BILLING_USERS, $only_active);
 		return $active_deals_by_id;
 	}
 
-	function deals_active_add_info(&$active_deals_by_id, $ID_BILLING_USERS, $only_active = false) {
+	public static function deals_active_add_info(&$active_deals_by_id, $ID_BILLING_USERS, $only_active = false) {
 		if (empty($active_deals_by_id)) {
 			return;
 		}
@@ -2419,7 +2428,7 @@ class PokazOfertyHelper {
 	 * @return array or null
 	 *   [ID_BILLING_USERS => array of object deal]
 	 */
-	function get_deals_active($params = array()) {
+	public static function get_deals_active($params = array()) {
 
 		$forceUpdate = false;
 		Lib::loadClass('ColumnDealsStatus');
@@ -2472,7 +2481,7 @@ class PokazOfertyHelper {
 		return $active_deals;
 	}
 
-	function get_l2_list_status_name($status) {
+	public static function get_l2_list_status_name($status) {
 		static $l2_list_status;
 		if (!is_array($l2_list_status)) {
 			$l2_list_status = array();
@@ -2492,7 +2501,7 @@ class PokazOfertyHelper {
 		return null;
 	}
 
-	function get_services_by_user_deals($user_id, $deals_ids = array(), $only_active = false) {
+	public static function get_services_by_user_deals($user_id, $deals_ids = array(), $only_active = false) {
 		$deals = array();
 		if (empty($deals_ids)) {
 			return $deals;
@@ -2566,7 +2575,7 @@ class PokazOfertyHelper {
 		return $deals;
 	}
 
-	function get_services_params($uslugi) {
+	public static function get_services_params($uslugi) {
 		$ses_x_a = array();
 		if (empty($uslugi)) return $ses_x_a;
 
@@ -2594,7 +2603,7 @@ class PokazOfertyHelper {
 		return $ses_x_a;
 	}
 
-	function get_users_by_query($q) {
+	public static function get_users_by_query($q) {
 		$users_rows = array();
 		$db = DB::getDB();
 		$sql_order_by = 'order by a.`P_NAME` asc';
@@ -2683,7 +2692,7 @@ class PokazOfertyHelper {
 		return $users_rows;
 	}
 
-	function get_user_info($user_id) {
+	public static function get_user_info($user_id) {
 		$user = null;
 		$user_id = (int)$user_id;
 		if ($user_id <= 0) {
@@ -2717,15 +2726,15 @@ class PokazOfertyHelper {
 		return $user;
 	}
 
-	function get_users2_deals_empty_object() {
+	public static function get_users2_deals_empty_object() {
 		return new Column_users2_deals();
 	}
 
-	function get_deals_table_empty_object() {
+	public static function get_deals_table_empty_object() {
 		return new Column_deals_table();
 	}
 
-	function get_buildings_cols() {
+	public static function get_buildings_cols() {
 		$buildings_sql_cols = array();
 		$buildings_sql_cols ['ID']= "ID";
 		$buildings_sql_cols ['S_ADDRESS_STREET']= "S ADDRESS STREET";
@@ -2740,7 +2749,7 @@ class PokazOfertyHelper {
 		return $buildings_sql_cols;
 	}
 
-	function get_marketing_cols() {
+	public static function get_marketing_cols() {
 		$marketing_sql_cols = array();
 		$marketing_sql_cols ['ID']= "ID";
 		$marketing_sql_cols ['S_ADDRESS_STREET']= "S ADDRESS STREET";
@@ -2752,7 +2761,7 @@ class PokazOfertyHelper {
 		return $marketing_sql_cols;
 	}
 
-	function get_buildings_by_mieszk($street) {
+	public static function get_buildings_by_mieszk($street) {
 		$buildings = array();
 		if (empty($street)) {
 			//return self::get_buildings($street);
@@ -2791,7 +2800,7 @@ class PokazOfertyHelper {
 		return $buildings;
 	}
 
-	function get_buildings($street) {
+	public static function get_buildings($street) {
 		$buildings = array();
 		$db = DB::getDB();
 		$buildings_sql_cols = self::get_buildings_cols();
@@ -2821,7 +2830,7 @@ class PokazOfertyHelper {
 		return $buildings;
 	}
 
-	function get_deal($id_deal) {
+	public static function get_deal($id_deal) {
 		$deal = null;
 		if ($id_deal <= 0) {
 			return $deal;
@@ -2963,7 +2972,7 @@ class PokazOfertyHelper {
 		return $offers;
 	}
 
-	function get_users2_deals_by_deal_id($deal_id, $params = array()) {
+	public static function get_users2_deals_by_deal_id($deal_id, $params = array()) {
 		$users2_deals = array();
 		$db = DB::getDB();
 		$sql_status = "";
@@ -3045,7 +3054,7 @@ class PokazOfertyHelper {
 		return $oferty_costs_start;
 	}
 
-	function get_oferty_opcje_visible_cols() {
+	public static function get_oferty_opcje_visible_cols() {
 		$cols = array();
 		$cols ['ID'] = 'ID oferty';
 		//$cols ['ID_PROCES' ] = '';
@@ -3063,7 +3072,7 @@ class PokazOfertyHelper {
 		return $cols;
 	}
 
-	function get_oferty_opcje() {
+	public static function get_oferty_opcje() {
 		$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
@@ -3106,7 +3115,7 @@ class PokazOfertyHelper {
 		return $oferty_opcje;
 	}
 
-	function get_oferty_opcje_all() {
+	public static 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
@@ -3156,7 +3165,7 @@ class PokazOfertyHelper {
 		return $oferty_opcje;
 	}
 
-	function find_groups_by_offers($oferty, $todo_test_deal_id = 0) {
+	public static function find_groups_by_offers($oferty, $todo_test_deal_id = 0) {
 		$db = DB::getDB();
 		$groups = array();
 		$sql_where_arr = array();
@@ -3191,7 +3200,7 @@ class PokazOfertyHelper {
 		return $groups;
 	}
 
-	function date_diff_days($d1, $d2) {
+	public static function date_diff_days($d1, $d2) {
 		$d1_sec = strtotime($d1);
 		$d2_sec = strtotime($d2);
 		$diff_sec = $d1_sec - $d2_sec;
@@ -3199,7 +3208,7 @@ class PokazOfertyHelper {
 		return $diff_days;
 	}
 
-	function date_diff_months($d1, $d2) {
+	public static function date_diff_months($d1, $d2) {
 		$d1_sec = strtotime($d1);
 		$d2_sec = strtotime($d2);
 		$diff_sec = $d1_sec - $d2_sec;
@@ -3207,7 +3216,7 @@ class PokazOfertyHelper {
 		return $diff_months;
 	}
 
-	function get_aneks_loss($offers_ids, $diff_months, $deal_month, &$loss_log) {
+	public static function get_aneks_loss($offers_ids, $diff_months, $deal_month, &$loss_log) {
 		if (empty($offers_ids) || $diff_months <= 0) {
 			return 0;
 		}
@@ -3227,7 +3236,7 @@ class PokazOfertyHelper {
 		return $loss;
 	}
 
-	function get_aneks_loss_abonament_netto($offers_ids, $diff_months, $deal_month, &$loss_log) {
+	public static function get_aneks_loss_abonament_netto($offers_ids, $diff_months, $deal_month, &$loss_log) {
 		if (empty($offers_ids) || $diff_months <= 0) {
 			return 0;
 		}
@@ -3241,7 +3250,7 @@ class PokazOfertyHelper {
 		return $loss;
 	}
 
-	function get_deals_by_month($month, $params = array()) {
+	public static function get_deals_by_month($month, $params = array()) {
 		$deals = array();
 
 		$sql_status = "";
@@ -3276,7 +3285,7 @@ class PokazOfertyHelper {
 		return $deals;
 	}
 
-	function get_deals_created_in_month($month, $params = array()) {
+	public static function get_deals_created_in_month($month, $params = array()) {
 		$deals = array();
 
 		$sql_status = "";
@@ -8846,3 +8855,59 @@ function POKAZ_OFERTY_AKTUALNE_FUNC__activate_services_save($tblAcl, $fieldsList
 
 
 }
+
+function POKAZ_OFERTY_AKTUALNE_FUNC__ajaxUmowaZysk() {
+	$jsonData = new stdClass();
+	
+	try {
+		$jsonData = POKAZ_OFERTY_AKTUALNE_FUNC__ajaxUmowaZysk_createJson();
+	}
+	catch (Exception $e) {
+		$jsonData->type = 'error';
+		$jsonData->msg = $e->getMessage();
+	}
+	echo json_encode($jsonData);
+	exit;
+}
+
+function POKAZ_OFERTY_AKTUALNE_FUNC__ajaxUmowaZysk_createJson() {
+	$jsonData = new stdClass();
+	$con = new PokazOfertyController();
+	$con->set_params_from_request();
+
+	if ($con->hasOptionsToServices()) {
+		if (!$con->convertOptionsToSrv()) {
+			throw new Exception("Nie udało się utworzyć nowej grupy na podstawie wybranych parametrów.");
+		}
+	}
+
+	$jsonData->con = $con;
+
+	$group = $con->get_group();
+	if (!$group) {
+		throw new Exception("Brak grupy");
+	}
+
+	$group->fetch_offers();
+	$jsonData->zysk = $group->get_zysk_netto();
+	$jsonData->zyskabonament_srednia_netto = $group->get_srednia_netto();
+
+	$procenty = array();
+	$procenty[]= 2;
+	$procenty[]= 5;
+	$procenty[]= 10;
+	$procenty[]= 15;
+	$procenty[]= 30;
+
+	ob_start();
+	?>
+Zysk: <?php echo number_format($jsonData->zysk, 2, ',', ''); ?>
+<?php foreach ($procenty as $procent) : ?>
+	<br><?php echo $procent; ?>%: <?php echo number_format($jsonData->zysk * $procent / 100, 2, ',', ''); ?>
+<?php endforeach; ?>
+	<?php
+	$jsonData->html = ob_get_contents();
+	ob_clean();
+
+	return $jsonData;
+}

+ 0 - 1
SE/superedit-USERS2_WINDYKACJA_STATUS.php

@@ -1572,7 +1572,6 @@ body{font-family:arial;}
 .hide .btn-show{display:inline;}
 		";
 		echo'</style>';
-		echo'<script type="text/javascript" src="stuff/jquery.js"></script>';
 		Lay_Html_Toggle::show_js();
 
 		$billing_docs = WindykacjaStatsModel::get_bill_dosc_by_date( $user );