sparqapi/api/application/helpers/smcpdscore_helper.php
2020-12-30 18:10:16 +05:30

377 lines
24 KiB
PHP

<?php
class SMCPDSCORE
{
public static function calculatePDScore111()
{
echo "calculatePDScore111";
}
//FULL PD SCORE CALCUALTIONS
public static function genericDIPDScoreCalculate($score_questions,$pd_master_details)
{
############ GENERIC SE-DI CASES #######################
############ SCROE VARIABLES DECLERATIONS ##############
// print_r($score_questions);//die();
$final_score_questions = array();
// LEVEL 1 WEIGHTAGES
$l1_general = 20;
$l1_business = 65;
$l1_final = 15;
// LEVEL2 WEIGHTAGES - Questions Weightages
/*-------- GENERAL --------------*/
// $approcah_to_pd_location_L2 = 25;
$approcah_to_pd_location_L2 = 31.25;
// $comment_locality_L2 = 15;
$comment_locality_L2 = 18.75;
// $customer_behaviour_L2 = 25;
$customer_behaviour_L2 = 31.25;
// $neighbourhood_status_L2 = 20;
// $name_board_seen_L2 = 15;
$name_board_seen_L2 = 18.75;
/*-------- BUSNIESS --------------*/
$no_of_years_business_run_L2 = 20;
$business_seasonality_L2 = 10;
$employees_total_L2 = 15;
$owned_property_L2 = 10;
$stock_visited_L2 = 10;
// $stock_of_fm_L2 = 5;
$location_suited_for_busienss_L2 = 15;
$business_activity_has_seen_L2 = 20;
/*-------- FINAL --------------*/
$pd_officer_recommadations_L2 = 100;
//LEVEL3 SCORES - ANSWER SCORES
/*-------- GENERAL --------------*/
$approcah_to_pd_location = array('Very Easy to locate & Reach' => 10,'Easy to locate & Reach' => 7,'Difficult to locate & Reach' => 4,'Very Difficult to locate & Reach' => 2);
$comment_locality = array('Excellent' => 10,'Good' => 7,'Poor' => 5,'Very Poor' => 2);
$customer_behaviour = array('Rude' => 0,'Polite' => 10,'Others' => 0);
$neighbourhood_status = array( 'Positive' => 10, 'Negative' => 0,'Could Not Verify' => 0);
$name_board_seen = array('yes' => 10, 'no' => 0);
/*-------- BUSNIESS --------------*/
$no_of_years_business_run = array('100> to >=10' => 10,'5<= to <10' => 8,'3<= to <5' => 6,'1<= to <3' => 4,' 1> to >0' => 2);
$business_seasonality = array('Yes' => 5, 'No' => 10);
$employees_total = array('1000> to >50' => 10,'21<= to <=50' => 8, '11<= to <=20' => 6, '6<= to <10' =>4,'5>= to >0' => 2) ;
$owned_property = array('Yes' => 10, 'No' => 0);
$stock_raw_material_enough = array('Provided' => 10, 'Not Provided' => 0,'Not Applicable' => 0);
$stock_finished_goods_enough = array('Provided' => 10, 'Not Provided' => 0,'Not Applicable' => 0);
$stock_answer_scores = array('yes' => 10, 'no' => 0,'not applicable' => 0);
$location_suited_for_busienss = array('Well Suited' => 10 ,'Fairly suited' => 6,'Not suited' => 0);
$business_activity_has_seen = array('Yes' => 10, 'No' => 0);
/*-------- FINAL --------------*/
$pd_officer_recommandations = array('Positive' => 10,'Negative' => 0,'Refer to Credit' => 5,'Others' => 0);
/*-----------CALCULATION PART -----------*/
/*-----------GENERAL SECTION -----------*/
//echo "##################################################";
$over_all_general_l2 = 0;
$over_all_general_round_l2 = 0;
$general_distribute_level_weightage = 0;
//General Section L2 Weightage Distribution section
// if(!strcmp($score_questions['neighbourhood_status']['answer'],'Could not verify'))
// {
// //echo "Yes could not";
// $general_distribute_level_weightage += $neighbourhood_status_L2;
// }
//End of General Section L2 Weightage Distribution section
//######1.5 neibourhood_check_as_per_pd_officer
// if(!strcmp($score_questions['neighbourhood_status']['answer'],'Could not verify'))
// {
// $final_score_questions['general']['neighbourhood_status'] = array('l1_weightage' => $l1_general,'l2_weightage' => 0,'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['neighbourhood_status']['answer'],'attributed_score' => 0.00, 'max_score' => 0.00,'score_band'=>$neighbourhood_status[ $score_questions['neighbourhood_status']['answer'] != "" || $score_questions['neighbourhood_status']['answer'] != null ?$score_questions['neighbourhood_status']['answer']: "Negative" ],'max_score_band' => 0);
// }
// else
// {
// $neighbourhood_status_L2 = $general_distribute_level_weightage ? ($neighbourhood_status_L2 + ($neighbourhood_status_L2 / (100 - $general_distribute_level_weightage )) * $general_distribute_level_weightage) : $neighbourhood_status_L2;
// $neibourhood_check_as_per_pd_officer_actual_score = ($l1_general/100) * ($neighbourhood_status_L2/100) * $neighbourhood_status[$score_questions['neighbourhood_status']['answer'] != "" || $score_questions['neighbourhood_status']['answer'] != null ? $score_questions['neighbourhood_status']['answer'] : "Negative" ];
// $neibourhood_check_as_per_pd_officer_max_score = ($l1_general/100) * ($neighbourhood_status_L2/100) * max($neighbourhood_status);
// $final_score_questions['general']['neighbourhood_status'] = array('l1_weightage' => $l1_general,'l2_weightage' => $neighbourhood_status_L2,'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['neighbourhood_status']['answer'],'attributed_score' => ($neibourhood_check_as_per_pd_officer_actual_score), 'max_score' => ($neibourhood_check_as_per_pd_officer_max_score),'score_band'=>$neighbourhood_status[$score_questions['neighbourhood_status']['answer'] != "" || $score_questions['neighbourhood_status']['answer'] != null ?$score_questions['neighbourhood_status']['answer']: "Negative" ],'max_score_band' => max($neighbourhood_status));
// }
//echo $general_distribute_level_weightage = round($general_distribute_level_weightage,2);die();
//echo $general_distribute_level_weightage;
//#######1.1 person_met_is_applicant
// $person_met_is_applicant_L2 = $general_distribute_level_weightage ? ($person_met_is_applicant_L2 + ($person_met_is_applicant_L2 / (100 - $general_distribute_level_weightage )) * $general_distribute_level_weightage) : $person_met_is_applicant_L2 ;
// $person_met_is_applicant_actual_score = ($l1_general/100) * ($person_met_is_applicant_L2/100) * $person_met_is_applicant[$score_questions['general']['person_met_is_applicant']];
// $person_met_is_applicant_max_score = ($l1_general/100) * ($person_met_is_applicant_L2/100) * max($person_met_is_applicant);
// //echo $person_met_is_applicant_L2;
// //echo $person_met_is_applicant_max_score;
// $score_questions['general']['person_met_is_applicant'] = array('l1_weightage' => $l1_general,'l2_weightage' => ($person_met_is_applicant_L2),'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['general']['person_met_is_applicant'],'attributed_score' => ($person_met_is_applicant_actual_score), 'max_score' => ($person_met_is_applicant_max_score),'score_band'=>($person_met_is_applicant[$score_questions['general']['person_met_is_applicant']]),'max_score_band' => max($person_met_is_applicant));
//######1.2 pd_location_approach
$approcah_to_pd_location_L2 = $general_distribute_level_weightage ? ($approcah_to_pd_location_L2 + ($approcah_to_pd_location_L2 / (100 - $general_distribute_level_weightage )) * $general_distribute_level_weightage) : $approcah_to_pd_location_L2 ;
$pd_location_approach_actual_score = ($l1_general/100) * ($approcah_to_pd_location_L2/100) * $approcah_to_pd_location[$score_questions['approcah_to_pd_location']['answer']];
$approcah_to_pd_location_max_score = ($l1_general/100) * ($approcah_to_pd_location_L2/100) * max($approcah_to_pd_location);
$final_score_questions['general']['approcah_to_pd_location'] = array('l1_weightage' => $l1_general,'l2_weightage' => ($approcah_to_pd_location_L2),'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['approcah_to_pd_location']['answer'],'attributed_score' => ($pd_location_approach_actual_score), 'max_score' => ($approcah_to_pd_location_max_score),'score_band'=>$approcah_to_pd_location[$score_questions['approcah_to_pd_location']['answer']],'max_score_band' => max($approcah_to_pd_location));
//######1.3 comment_locality
$comment_locality_L2 = $general_distribute_level_weightage ? ($comment_locality_L2 + ($comment_locality_L2 / (100 - $general_distribute_level_weightage )) * $general_distribute_level_weightage) : $comment_locality_L2;
$comment_locality_actual_score = ($l1_general/100) * ($comment_locality_L2/100) * $comment_locality[$score_questions['comment_locality']['answer']];
$comment_locality_max_score = ($l1_general/100) * ($comment_locality_L2/100) * max($comment_locality);
$final_score_questions['general']['comment_locality'] = array('l1_weightage' => $l1_general,'l2_weightage' => ($comment_locality_L2),'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['comment_locality']['answer'],'attributed_score' => ($comment_locality_actual_score), 'max_score' => ($comment_locality_max_score),'score_band'=>$comment_locality[$score_questions['comment_locality']['answer']],'max_score_band' => max($comment_locality));
//######1.4 customer_behaviour
$customer_behaviour_L2 = $general_distribute_level_weightage ? ($customer_behaviour_L2 + ($customer_behaviour_L2 / (100 - $general_distribute_level_weightage )) * $general_distribute_level_weightage) : $customer_behaviour_L2;
$customer_behaviour_actual_score = ($l1_general/100) * ($customer_behaviour_L2/100) * $customer_behaviour[$score_questions['customer_behaviour']['answer']];
$customer_behaviour_max_score = ($l1_general/100) * ($customer_behaviour_L2/100) * max($customer_behaviour);
$final_score_questions['general']['customer_behaviour'] = array('l1_weightage' => $l1_general,'l2_weightage' => ($customer_behaviour_L2),'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['customer_behaviour']['answer'],'attributed_score' => ($customer_behaviour_actual_score), 'max_score' => ($customer_behaviour_max_score),'score_band'=>$customer_behaviour[$score_questions['customer_behaviour']['answer']],'max_score_band' => max($customer_behaviour));
//######1.6 was_the_company_name_board_sighted
$name_board_seen_L2 = $general_distribute_level_weightage ? ($name_board_seen_L2 + ($name_board_seen_L2 / (100 - $general_distribute_level_weightage )) * $general_distribute_level_weightage) : $name_board_seen_L2;
$was_the_company_name_board_sighted_actual_score = ($l1_general/100) * ($name_board_seen_L2/100) * $name_board_seen[$score_questions['name_board_seen']['answer']];
$was_the_company_name_board_sighted_max_score = ($l1_general/100) * ($name_board_seen_L2/100) * max($name_board_seen);
$final_score_questions['general']['name_board_seen'] = array('l1_weightage' => $l1_general,'l2_weightage' => ($name_board_seen_L2),'distributed_weightage' => $general_distribute_level_weightage,'answer' => $score_questions['name_board_seen']['answer'],'attributed_score' => ($was_the_company_name_board_sighted_actual_score), 'max_score' => ($was_the_company_name_board_sighted_max_score),'score_band'=>$name_board_seen[$score_questions['name_board_seen']['answer']],'max_score_band' => max($name_board_seen));
/*-----------END OF GENERAL SECTION -----------*/
/*-----------FINAL REMARKS SECTION -----------*/
//###### 3.1 PD Officer Recommandation
$pd_officer_recommandations_actual_score = ($l1_final/100) * ($pd_officer_recommadations_L2/100) * $pd_officer_recommandations[ $score_questions['pd_officer_recommendation']['answer'] ];
$pd_officer_recommandations_max_score = ($l1_final/100) * ($pd_officer_recommadations_L2/100) * max($pd_officer_recommandations);
$final_score_questions['final_remarks']['pd_officer_recommendation'] = array('l1_weightage' => $l1_final,'l2_weightage' => $pd_officer_recommadations_L2,'distributed_weightage' => 0,'answer' => $score_questions['pd_officer_recommendation']['answer'],'attributed_score' => round($pd_officer_recommandations_actual_score,2), 'max_score' => $pd_officer_recommandations_max_score,'score_band'=>$pd_officer_recommandations[ $score_questions['pd_officer_recommendation']['answer'] ],'max_score_band' => max($pd_officer_recommandations));
/*-----------END OF FINAL REMARKS SECTION -----------*/
/*-----------BUSINESS SECTION -----------*/
/* First Calculate Shortfall Type Questions to get distribute level
From 2.7 to 2.10 Questions are shortfall type questions (REF :- SSA_ScoreCard_Ver_090219(2))
*/
$business_distribute_level_weightage = 0;
//echo $score_questions['business']['minimum_supplier_info'];die();
// if(!strcasecmp($score_questions['business']['minimum_supplier_info'],'Not Applicable'))
// {
// $business_distribute_level_weightage += $minimum_supplier_info_L2;
// $minimum_supplier_info_L2 = 0;
// }
// if(!strcasecmp($score_questions['business']['minimum_client_info'],'Not Applicable'))
// {
// $business_distribute_level_weightage += $minimum_client_info_L2;
// $minimum_client_info_L2 = 0;
// }
// if(!strcasecmp($score_questions['business']['stock_raw_material_enough'],'Not Applicable'))
// {
// $business_distribute_level_weightage += $stock_raw_material_enough_L2;
// $stock_raw_material_enough_L2 = 0;
// }
if(!strcasecmp($score_questions['stock_visited']['answer'],'Not Applicable'))
{
$business_distribute_level_weightage += $stock_visited_L2;$stock_visited_L2 = 0;
}
//echo $business_distribute_level_weightage;
//######2.10 stock_finished_goods_enough
$stock_visited_L2 = $business_distribute_level_weightage ? ($stock_visited_L2 + ($stock_visited_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $stock_visited_L2 ;
$stock_finished_goods_enough_actual_score = ($l1_business/100) * ($stock_visited_L2/100) * $stock_answer_scores [ $score_questions['stock_visited']['answer'] != "" || $score_questions['stock_visited']['answer'] != null ? strtolower($score_questions['stock_visited']['answer']) : "no" ];
$stock_finished_goods_enough_max_score = strcasecmp($score_questions['stock_visited']['answer'],'Not Applicable') ? ($l1_business/100) * ($stock_visited_L2/100) * max($stock_answer_scores) : 0;
$temp_stock_finished_goods_enough = strtolower($score_questions['stock_visited']['answer']);
$final_score_questions['business']['stock_visited'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($stock_visited_L2),'answer' => $score_questions['stock_visited']['answer'],'attributed_score' => ($stock_finished_goods_enough_actual_score), 'max_score' => ($stock_finished_goods_enough_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' => $stock_answer_scores [ $temp_stock_finished_goods_enough != "" || $temp_stock_finished_goods_enough != null ? $temp_stock_finished_goods_enough : "no" ],'max_score_band' => max($stock_answer_scores));
//######2.1 no_of_years_business_run
$no_of_years_business_run_actual_score = 0;
$score_band = 0;
if($score_questions['no_of_years_business_run'])
{
foreach($no_of_years_business_run as $key => $value)
{
$exp = explode('to',$key);
//print_r($exp);
$left = $exp[0].$score_questions['no_of_years_business_run']['answer'];
$right = $score_questions['no_of_years_business_run']['answer'].$exp[1];
//echo $left.'````'.$right;echo "\n";die();
eval( '$left_exp = ' . $left . ';');
eval( '$right_exp = ' . $right . ';');
if($left_exp && $right_exp)
{
$no_of_years_business_run_L2 = $business_distribute_level_weightage ? ($no_of_years_business_run_L2 + ($no_of_years_business_run_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $no_of_years_business_run_L2 ;
$no_of_years_business_run_actual_score = ($l1_business/100) * ($no_of_years_business_run_L2/100) * $value;
$score_band = $value;
}
}
}
$no_of_years_business_run_max_score = ($l1_business/100) * ($no_of_years_business_run_L2/100) * max($no_of_years_business_run);
$final_score_questions['business']['no_of_years_business_run'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($no_of_years_business_run_L2),'answer' => $score_questions['no_of_years_business_run']['answer'],'attributed_score' => ($no_of_years_business_run_actual_score), 'max_score' => ($no_of_years_business_run_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' => $score_band,'max_score_band' => max($no_of_years_business_run));
//######2.2 business seasonal
$business_seasonality_L2 = $business_distribute_level_weightage ? ($business_seasonality_L2 + ($business_seasonality_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $business_seasonality_L2 ;
$business_seasonality_actual_score = ($l1_business/100) * ($business_seasonality_L2/100) * $business_seasonality[ $score_questions['business_seasonality']['answer'] ];
$business_seasonality_max_score = ($l1_business/100) * ($business_seasonality_L2/100) * max($business_seasonality);
$final_score_questions['business']['business_seasonality'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($business_seasonality_L2),'answer' => $score_questions['business_seasonality']['answer'],'attributed_score' => ($business_seasonality_actual_score), 'max_score' =>($business_seasonality_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' => $business_seasonality[ $score_questions['business_seasonality']['answer'] ],'max_score_band' => max($business_seasonality));
//######2.3 employees_total
$employees_total_actual_score = 0;
$employees_total_L2 = $business_distribute_level_weightage ? ($employees_total_L2 + ($employees_total_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $employees_total_L2 ;
$score_band = 0;
if($score_questions['employees_total']['answer'])
{
foreach($employees_total as $key => $value)
{
$exp = explode('to',$key);
//print_r($exp);
$left = $exp[0].$score_questions['employees_total']['answer'];
$right = $score_questions['employees_total']['answer'].$exp[1];
//echo $left.'````'.$right;echo "\n";
eval( '$left_exp = ' . $left . ';');
eval( '$right_exp = ' . $right . ';');
if($left_exp && $right_exp)
{
$employees_total_actual_score = ($l1_business/100) * ($employees_total_L2/100) * $value;
$score_band = $value;
}
}
}
// echo $score_band;
// die();
$employees_total_max_score = ($l1_business/100) * ($employees_total_L2/100) * max($employees_total);
$final_score_questions['business']['employees_total'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($employees_total_L2),'answer' => $score_questions['employees_total']['answer'],'attributed_score' => ($employees_total_actual_score), 'max_score' => ($employees_total_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' =>$score_band,'max_score_band' => max($employees_total));
//######2.5 owned_property
$owned_property_L2 = $business_distribute_level_weightage ? ($owned_property_L2 + ($owned_property_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $owned_property_L2 ;
$owned_property_actual_score = ($l1_business/100) * ($owned_property_L2/100) * $owned_property[ $score_questions['owned_property']['answer'] ];
$owned_property_max_score = ($l1_business/100) * ($owned_property_L2/100) * max($owned_property);
$final_score_questions['business']['owned_property'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($owned_property_L2),'answer' => $score_questions['owned_property']['answer'],'attributed_score' => ($owned_property_actual_score), 'max_score' => ($owned_property_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' => $owned_property[ $score_questions['owned_property']['answer'] ],'max_score_band' => max($owned_property));
//######2.11 location_suited_for_busienss
$location_suited_for_busienss_L2 = $business_distribute_level_weightage ? ($location_suited_for_busienss_L2 + ($location_suited_for_busienss_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $location_suited_for_busienss_L2 ;
$location_suited_for_busienss_actual_score = ($l1_business/100) * ($location_suited_for_busienss_L2/100) * $location_suited_for_busienss[ $score_questions['location_suited_for_busienss']['answer'] ];
$location_suited_for_busienss_max_score = ($l1_business/100) * ($location_suited_for_busienss_L2/100) * max($location_suited_for_busienss);
$final_score_questions['business']['location_suited_for_busienss'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($location_suited_for_busienss_L2),'answer' => $score_questions['location_suited_for_busienss']['answer'],'attributed_score' => ($location_suited_for_busienss_actual_score), 'max_score' => ($location_suited_for_busienss_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' => $location_suited_for_busienss[ $score_questions['location_suited_for_busienss']['answer'] ],'max_score_band' => max($location_suited_for_busienss));
//######2.11 business_activity_has_seen
$business_activity_has_seen_L2 = $business_distribute_level_weightage ? ($business_activity_has_seen_L2 + ($business_activity_has_seen_L2 / (100 - $business_distribute_level_weightage )) * $business_distribute_level_weightage) : $business_activity_has_seen_L2 ;
$business_activity_has_seen_actual_score = ($l1_business/100) * ($business_activity_has_seen_L2/100) * $business_activity_has_seen[ $score_questions['business_activity_has_seen']['answer'] ];
$business_activity_has_seen_max_score = ($l1_business/100) * ($business_activity_has_seen_L2/100) * max($business_activity_has_seen);
$final_score_questions['business']['business_activity_has_seen'] = array('l1_weightage' => $l1_business,'l2_weightage' => ($business_activity_has_seen_L2),'answer' => $score_questions['business_activity_has_seen']['answer'],'attributed_score' => ($business_activity_has_seen_actual_score), 'max_score' => ($business_activity_has_seen_max_score),'distributed_weightage' => $business_distribute_level_weightage,'score_band' => $business_activity_has_seen[ $score_questions['business_activity_has_seen']['answer'] ], 'max_score_band' => max($business_activity_has_seen));
/*-----------END OF BUSINESS SECTION -----------*/
/* Calculate Overall Total*/
$overall_max_score = 0;
$overall_actual_score = 0;
// print_r($final_score_questions);die();
foreach($final_score_questions as $key => $value)
{
$current_max_score = 0;
$current_actual_score = 0;
foreach($value as $v_key => $f_value)
{
$overall_max_score += $f_value['max_score'];
$overall_actual_score += $f_value['attributed_score'];
$current_max_score += $f_value['max_score'];
$current_actual_score += $f_value['attributed_score'];
}
$final_score_questions['score_summary'][$key] = array('actual_score' => $current_actual_score,'max_score' => $current_max_score,'score_per' => (($current_actual_score/$current_max_score) * 100));
}
$final_score_questions['score_summary']['overall_score'] = array('overall_actual_score' => $overall_actual_score, 'overall_max_score' => $overall_max_score,'final_score' => (($overall_actual_score/$overall_max_score) * 100));
//$score_questions['score_summary']['asset_calculation_details'] = $asset_calculation_details;
//print_r($score_questions);die();
return ($final_score_questions);
}
}
?>