<?php
function gcFormula($bidin_uom_val1, $bidin_uom_val2, $maps_uom_val1, $maps_uom_val2, $maps_uom_val3, $maps_uom_val4){
    $basePrice= $maps_uom_val1; 
    $grassHeightLimit = $maps_uom_val2; 
    $grassLimitPrice = $maps_uom_val3;
    $equipmentCost = $maps_uom_val4;
    if($grassLimitPrice > 0){
        $eq_set = 'set';
    }elseif($grassLimitPrice == 0){
        $eq_set = 'unset';
    }

    if($equipmentCost > 0){
        $cutting_set = 'set';
    }elseif($equipmentCost == 0){
        $cutting_set = 'unset';
    }

    $factorLot1 = 970.0000;
    $factorLot2 = 4.0000;
    $factorLot3 = 0.0050;
    $factorGrass1 = 0.0900;
    $lotSize = $bidin_uom_val1;
    $grassHeight = $bidin_uom_val2;
    $sum1 = $basePrice;
    $sum2 = 0.0000;

    if($grassHeight>$grassHeightLimit){
        $sum3 = $grassLimitPrice + $equipmentCost;
    }else{
        $sum3 = 0.0000;
        $cutting_set = 'unset';
        $eq_set = 'unset';

    }
    $sum4 = $grassHeight * $grassHeight * $factorGrass1 ;
    $sum5 = $lotSize* $factorLot3 / $factorLot2;
    $sum6 = bcdiv($lotSize, $factorLot1, 4);
    $total  = $sum1 + $sum2 + $sum3 + $sum4 + $sum5 + $sum6;
    $gc_cost = $sum1 + $sum4 + $sum5 + $sum6;
    $gc_cost = number_format($gc_cost, 2, '.', '');
    $total = number_format($total, 2, '.', '');
    $total_arr = array("bid_item_total"=>"$total","cutting_is_set"=>"$cutting_set","eq_is_set"=>"$eq_set","eq_cost"=>"$grassLimitPrice","cutting_cost" => "$equipmentCost","gc_cost" =>"$gc_cost");
    
    return $total_arr;
}

function tarpFormula($tarp_area, $tarp_time, $tarp_storey, $tarp_pitch, $maps_uom_val1, $maps_uom_val2, $maps_uom_val3, $maps_uom_val4,$maps_uom_val5,$maps_uom_val6,$maps_uom_val7,$maps_uom_val8,$maps_uom_val9){
    $normal_cost_per_area = $maps_uom_val1; 
   $emer_cost_per_area = $maps_uom_val2; 
    $roof_pitch_8_12 = $maps_uom_val3;
    $roof_pitch_9_12 = $maps_uom_val4;
    $roof_pitch_10_12 = $maps_uom_val5;
    $roof_pitch_11_12 = $maps_uom_val6;
    $roof_pitch_12_12 = $maps_uom_val7;
    $storey_2 = $maps_uom_val8;
    $storey_3 = $maps_uom_val9;

    
    if($tarp_time == 1){
        $main_unit_cost = $normal_cost_per_area;
    }elseif($tarp_time ==2){
        $main_unit_cost = $emer_cost_per_area;
    }

    if($tarp_pitch == 1){
        $pitch_unit_cost = 0;
    }elseif($tarp_pitch == 2){
        $pitch_unit_cost =  $roof_pitch_8_12;
    }elseif($tarp_pitch == 3){
        $pitch_unit_cost =  $roof_pitch_9_12;
    }elseif($tarp_pitch == 4){
        $pitch_unit_cost =  $roof_pitch_10_12;
    }elseif($tarp_pitch == 5){
        $pitch_unit_cost =  $roof_pitch_11_12;
    }elseif($tarp_pitch == 6){
        $pitch_unit_cost =  $roof_pitch_12_12;
    }
     

    if($tarp_storey == 1){
        $storey_unit_cost = 0;
    }elseif($tarp_storey == 2){
        $storey_unit_cost =  $storey_2;
    }elseif($tarp_storey == 3){
        $storey_unit_cost =  $storey_3;
    }


    $unit_cost = $main_unit_cost + $pitch_unit_cost + $storey_unit_cost;
    $total = $tarp_area * $unit_cost;
    $total = number_format($total, 2, '.', '');
    return $total;
}

function sfFormula($bidin_uom_val1, $bidin_uom_val2, $maps_uom_val1){
    $pricePer = $maps_uom_val1; 
    $length = $bidin_uom_val1;
    $width = $bidin_uom_val2;
    $total = $pricePer * $length * $width;
    $total = number_format($total, 2, '.', '');    
    return $total;
}

function hourFormula($bidin_uom_val1, $maps_uom_val1){
    $pricePer = $maps_uom_val1; 
    $time = $bidin_uom_val1;
    $total = $pricePer * $time;
    $total = number_format($total, 2, '.', '');    
    return $total;
}

function lfFormula($bidin_uom_val1, $maps_uom_val1){
    $pricePer = $maps_uom_val1; 
    $inches = $bidin_uom_val1;
    $feet = $inches / 12;
    $total = $pricePer * $feet;
    $total = number_format($total, 2, '.', '');    
    return $total;
}

function uiFormula($bidin_uom_val1, $bidin_uom_val2, $maps_uom_val1){
    $pricePer = $maps_uom_val1; 
    $length = $bidin_uom_val1;
    $width = $bidin_uom_val2;
    $total = $pricePer * $length * $width;
    $total = number_format($total, 2, '.', '');    
    return $total;
}


function cydFormula($bidin_uom_val1, $bidin_uom_val2, $bidin_uom_val3, $maps_uom_val1){
    $pricePer = $maps_uom_val1; 
    $length = $bidin_uom_val1;
    $width = $bidin_uom_val2;
    $height = $bidin_uom_val3;
    $cyd = $length * $width * $height;
    $cyd_units = $cyd / 27;
    $total = $pricePer * $cyd_units;
    $total = number_format($total, 2, '.', '');    
    return $total;
}

?>