sparqapi/api/application/helpers/financialform_helper.php
2020-02-07 10:31:33 +05:30

235 lines
14 KiB
PHP

<?php
class Financialform
{
//other loan obligations
public static function getOtherLoanDetails($data,$pdid){
$total_tables = count($data) / 5;
$total_tables = ceil($total_tables);
//print_r(array_values($values));
// die();
$overall_data = array();
$total_no_of_valid_data = 0;
$values = array_values($data);
$latest_applicants_names = APPLICANTNAME_GRABBER::getLatestApplicantsName($pdid);
for($i = 1;$i<= $total_tables;$i++)
{
$rupee_symbol = '<span style="font-family: DejaVu Sans; sans-serif;font-size:10px">₹</span>';
$first_row = '<tr><td class="customtd">Loan Type</td>';
$second_row = '<tr><td class="customtd">Loan Amount</td>';
// $third_row = '<tr><td class="customtd">Loan Amount (Rs)</td>';
$fourth_row = '<tr><td class="customtd">Availed From</td>';
$fifth_row = '<tr><td class="customtd">Borrower</td>';
$sixth_row = '<tr><td class="customtd">Instalment Amount</td>';
$seventh_row = '<tr><td class="customtd">Instalment Frequency</td>';
$eigth_row = '<tr><td class="customtd">Original Tenure (Months)</td>';
$ninth_row = '<tr><td class="customtd">Elapsed Tenure (Months)</td>';
$tenth_row = '<tr><td class="customtd">Balance Tenure (Months)</td>';
$total_header = 0;
foreach($values as $key => $tag)
{
if(isset($tag['loan_type_master']) && $tag['loan_type_master'] != '')
{
$total_header++;
$total_no_of_valid_data++;
$setFrequencyType='';
switch($tag['frequency']) {
case 1:
$setFrequencyType = ' per '.$tag['other_frequency'];
break;
case 2:
$setFrequencyType = ' per annum';
break;
case 3:
$setFrequencyType = ' per halfyearly';
break;
case 4:
$setFrequencyType = ' per fortnightly';
break;
case 5:
$setFrequencyType = ' per daily';
break;
case 6:
$setFrequencyType = ' per quarterly';
break;
case 7:
$setFrequencyType = ' per month';
break;
default:
$setFrequencyType = ' per';
}
$name_of_borrower = '';
foreach ($tag['loan_taken_by'] as $l_key => $l_value) {
if($l_value['id'] == 0)
{
$name_of_borrower .= $tag['others_loan_taken'].' ,';
}
else
{
$name_of_borrower .= $l_value['group_id'] == 1 ? $l_value['name'] . ' , ': APPLICANTNAME_GRABBER::getApplicantsNameById($l_value['id'],$latest_applicants_names).' ,';
}
}
$name_of_borrower = substr_replace($name_of_borrower, '', -1);
// if(strrpos($name_of_borrower,',')) { $name_of_borrower = substr_replace($name_of_borrower,' and ',strrpos($name_of_borrower,','),1); }
$name_of_borrower = str_replace(',','and', $name_of_borrower);
$first_row .= $tag['loan_type']==1 ? '<td class="customtd">'.$tag['others_loan_type'].'</td>' : '<td class="customtd">'.$tag['loan_type_master'] .'</td>';
$loan_amt = $tag['loan_amount'] ? $rupee_symbol.' '.MYUTIL::customIndianNumberFormat($tag['loan_amount']) : 'Not Provided';
$second_row .= '<td class="customtd">'.$loan_amt.'</td>';
//$third_row = '<td class="customtd">'.MYUTIL::customIndianNumberFormat($tag['loan_amount']).'</td>';
$fourth_row .= $tag['lender']==1 ? '<td class="customtd">'.$tag['others_lender'].'</td>' : '<td class="customtd">'.$tag['lender_master'].'</td>';
$fifth_row .= '<td class="customtd">'.$name_of_borrower.'</td>';
$sixth_row .= '<td class="customtd">'.$rupee_symbol.' '.MYUTIL::customIndianNumberFormat($tag['emi']).'</td>';
$seventh_row .= $tag['frequency']==1 ? '<td class="customtd">'.$tag['other_frequency'].'</td>' : '<td class="customtd">'.$tag['frequency_master'].'</td>';
$eigth_row .= $tag['original_tenure'] ? '<td class="customtd">'.$tag['original_tenure'].'</td>' : '<td class="customtd"> Not Provided </td>';
$ninth_row .= $tag['elapsed_tenure'] ? '<td class="customtd">'.$tag['elapsed_tenure'].'</td>' : '<td class="customtd"> Not Provided </td>';
$bal = is_numeric($tag['original_tenure']) && is_numeric($tag['elapsed_tenure']) ? ($tag['original_tenure'] - $tag['elapsed_tenure']) : 'Not Provided';
$tenth_row .= '<td class="customtd">'.$bal.'</td>';
unset($values[$key]);
// echo count($values).' - keyy is - '.$key.'*';
if( $total_header == 5)
{
break;
}
}
}
$overall_data[$i] = array(
'first_row' => $first_row.'</tr>','second_row' => $second_row.'</tr>','fourth_row' => $fourth_row.'</tr>','fifth_row' => $fifth_row.'</tr>','sixth_row' => $sixth_row.'</tr>','seventh_row' => $seventh_row.'</tr>','eigth_row' => $eigth_row.'</tr>', 'ninth_row' => $ninth_row.'</tr>', 'tenth_row' => $tenth_row.'</tr>','total_header' => $total_header);
// echo 'TABLE VALIUES - '.count($values);
}
$overall_data['valid_data'] = $total_no_of_valid_data;
return $overall_data;
}
// business financial details
public static function getBusinessFinancialDetails($values){
$values = array_map(function($tag) {
return array(
'financial_year' => $tag['financial_year'],
'financial_sales_revenue' => $tag['financial_annual_sale'],
'financial_net_profit_mode' => $tag['finanical_profit_or_loss']==1 ? 1 : 0,
'financial_net_profit' => $tag['finanical_profit_or_loss']==1 ? $tag['financial_net_profit'] : '',
'financial_net_loss' => $tag['finanical_profit_or_loss']!=1 ? $tag['financial_net_loss'] : '',
'financial_margin_of_profit' => $tag['finanical_profit_or_loss']==1 ? $tag['financial_margin_of_profit'] : '',
'financial_margin_of_loss' => $tag['finanical_profit_or_loss']!=1 ? $tag['financial_margin_of_loss'] : '',
'profit_variation' => $tag['financial_variation'],
'sale_variation' => $tag['financial_annualsales_variation'],'financial_profit_to_sale_variation' => $tag['financial_profit_to_sale_variation']
);
}, $values);
return $values;
}
// get customer financial
public static function getBusinessCustomerFinancialDetails($values) {
$values = array_map(function($tag) {
if($tag['estimate_profit_or_loss']==1){
return array(
'estimate_profit_or_loss' => $tag['estimate_profit_or_loss'],
'estimate_sales_average' => $tag['estimate_sales_average'],
'estimate_sales_from' => $tag['estimate_sales_from'],
'estimate_sales_to' => $tag['estimate_sales_to'],
'estimate_net_margin_availablity' => $tag['estimate_net_margin_availablity'],
//'estimate_net_margin' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ?$tag['estimate_profit_margin'] : $tag['estimate_net_profit'],
'net_profit_loss_sales_per_from' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_profit_range_from']: $tag['estimate_net_profit_from'],
'net_profit_loss_sales_per_to' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_profit_range_to']: $tag['estimate_net_profit_to'],
'net_profit_loss_sales_final_per' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_profit_margin_percent']:$tag['estimate_net_profit'],
//Pre - estimate_profit_margin
'net_profit_loss_sales_final_rs' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_profit_margin']: $tag['estimate_net_profit_percent'],//pre_ estimate_profit_margin_percent
//'estimate_net_margin_from' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? $tag['estimate_net_profit_from']: '',
//'estimate_net_margin_to' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? $tag['estimate_net_profit_to']:'',
//'estimate_net_margin_range' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? $tag['estimate_net_profit_percent'] : $tag['estimate_profit_margin_percent'],
//'estimate_net_margin_range_from' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? '' : $tag['estimate_profit_range_from'],
// 'estimate_net_margin_range_to' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? '' : '( '.$tag['estimate_profit_range_from'].', '.$tag['estimate_profit_range_to'].')',
);
}
else if($tag['estimate_profit_or_loss']==2){
return array(
'estimate_profit_or_loss' => $tag['estimate_profit_or_loss'],
'estimate_sales_average' => $tag['estimate_sales_average'],
'estimate_sales_from' =>$tag['estimate_sales_from'],
'estimate_sales_to' => $tag['estimate_sales_to'],
'estimate_net_margin_availablity' => $tag['estimate_net_margin_availablity'],
'net_profit_loss_sales_per_from' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_loss_range_from']: $tag['estimate_net_profit_from'],
'net_profit_loss_sales_per_to' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_loss_range_to']: $tag['estimate_net_loss_to'],
'net_profit_loss_sales_final_per' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_loss_margin_percent']: $tag['estimate_loss_margin'],//$tag['estimate_net_loss_percent'],
'net_profit_loss_sales_final_rs' => strtoupper($tag['estimate_net_margin_availablity'])=='YES' ? $tag['estimate_loss_margin']: $tag['estimate_loss_margin_percent']//$tag['estimate_net_loss'],
//'estimate_net_margin' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? 'Rs.'.$tag['estimate_net_loss'] : 'Rs.'.$tag['estimate_loss_margin'],
//'estimate_net_margin_from_to' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? '(Rs.'.$tag['estimate_net_loss_from'].', Rs.'.$tag['estimate_net_loss_to'].')' : '',
//'estimate_net_margin_range' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? $tag['estimate_net_loss_percent'] : $tag['estimate_loss_margin_percent'],
//'estimate_net_margin_range_from_to' => strtoupper($tag['estimate_net_margin_availablity'])=='NO' ? '' : '('.$tag['estimate_loss_range_from'].', '.$tag['estimate_loss_range_to'].')',
);
}
}, $values);
return $values;
}
// not in use
public static function getBusinessCustomerHeader($values){
if(count($values)>0 && $values[0]['estimate_profit_or_loss']==1){
return array("Sales","Net Profit","Net Margin %");
}
else if(count($values)>0 && $values[0]['estimate_profit_or_loss']==2){
return array("Sales","Net Loss","Net Margin %");
}
else {
return array();
}
}
//not in use
public static function getAvailableFacilities($arr)
{
echo "@@@@@@@@@@@@@@";
print_r($arr);
die();
$word_array = array('1' => 'Others', '2' => 'Bank Guarantee', '3' => 'Cash Credit Limit','4' => 'Factoring', '5' => 'Forfaiting', '6' => 'Letter of Credit');
if(is_array($array))
{
//$array = array_map(function($arr){ },$array);
}
return $array;
}
}
?>