Need Assistance in Loan Application logic

Discussion in 'General Chat' started by kilongi, Jun 1, 2018.

  1. kilongi

    kilongi New Member

    Hi im fairly new in php, i have this code working well but i have been given further instructions and im struggling with logic. This is one of the files in my app. It is a loan application developed in php. When a client borrows less than $5500,the amount should be paid in 5 months at 15%, else any amount greater than $5500 should be paid in 12 months at 22%. When i enter an amount i expect the program to calculate this. check the code below
    <?php
    extract($_POST);
    if(isset($save))
    {

    if($source=="" || $amount=="" || $group=="" || $payment=="" || $due=="")
    {
    $err="<font color='red'>fill all the fileds first</font>";
    }
    else
    {
    $sql=mysqli_query($conn,"select * from loan where group_id='$group'");
    $r=mysqli_num_rows($sql);
    if($r!=true)
    {
    mysqli_query($conn,"insert into loan values('','$group','$source','$amount','$intereset','$payment_term','$total_paid','$emi_per_month','$payment','$due')");
    $err="<font color='blue'>Congractulations Rising Star Member grants Loan to this Member</font>";
    }
    else
    {

    $err="<font color='red'>Loan already allotted to this Member</font>";
    }
    }
    }

    ?>
    <h2align="center"style="color:#00FFFF;text-decoration:underline">Rising Star Ventures Loan Book</h2>
    <formmethod="post">
    <divclass="row">
    <divclass="col-sm-4"></div>
    <divclass="col-sm-4"><?phpecho @$err;?></div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Select Member</div>
    <divclass="col-sm-5">
    <selectname="group"class="form-control"required>
    <optionvalue="">Select Member</option>
    <?php
    $q1=mysqli_query($conn,"select * from groups");
    while($r1=mysqli_fetch_assoc($q1))
    {
    echo"<option value='".$r1['group_id']."'>".$r1['group_name']."</option>";

    }
    ?>
    </select>
    </div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Income Source</div>
    <divclass="col-sm-5">
    <selectname="source"class="form-control"required>
    <optionvalue="">Select Income Source</option>
    <option>Government</option>
    <option>Private Sector</option>
    </select>
    </div>
    </div>
    <script>
    functionloanamount()
    {
    varoriginal=document.getElementById("original").value;
    varinterest=document.getElementById("interest").value;
    varyear=document.getElementById("payment_term").value;
    varinterest1=(Number(original)*Number(interest)*Number(year))/100;
    vartotal=Number(original)+Number(interest1);
    varemi=(Number(original)*Number(interest)*Number(year))/100;
    document.getElementById("total_paid").value=total;
    document.getElementById("emi_per_month").value=emi;
    }
    </script>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Requested Amount(Ksh.)</div>
    <divclass="col-sm-5">
    <inputtype="number"id="original"name="amount"class="form-control"required/></div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Interest Rate(30%)</div>
    <divclass="col-sm-5">
    <inputtype="text"name="intereset"id="interest"value="30"readonly="true"class="form-control"required/></div>
    </div>

    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Payment period(Monthly)</div>
    <divclass="col-sm-5">
    <selectonchange="loanamount()"name="payment_term"id="payment_term"class="form-control"required>
    <optionvalue="">No of months</option>
    <?php
    for($i=1;$i<=10;$i++)
    {
    echo"<option value='".$i."'>".$i."</option>";
    }
    ?>
    </select>
    </div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Interest Per Month(Ksh.)</div>
    <divclass="col-sm-5">
    <inputtype="text"id="emi_per_month"name="emi_per_month"class="form-control"readonly/></div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Total Payable Amount(Inclusive Interest)</div>
    <divclass="col-sm-5">
    <inputtype="text"id="total_paid"name="total_paid"class="form-control"readonly/></div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Loan Approval Date</div>
    <divclass="col-sm-5">
    <inputtype="date"name="payment"min="2016-01-01"class="form-control"required/>
    </div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-4">Payment Due Date</div>
    <divclass="col-sm-5">
    <inputtype="date"name="due"min="2016-01-01"class="form-control"required/>
    </div>
    </div>
    <divclass="row"style="margin-top:10px">
    <divclass="col-sm-2"></div>
    <divclass="col-sm-8">
    <inputtype="submit"value="Allow New Loan"name="save"class="btn btn-success"/>
    <inputtype="reset"class="btn btn-success"/>
    </div>
    </div>
    </form>

Share This Page