<?php 
// Database connection
$conn = mysqli_connect("localhost", "aksoftwarecoimba_yugam", "9994613878@@", "aksoftwarecoimba_yugam");

if (!$conn) {
    echo json_encode([
        "status" => "error",
        "message" => "Database connection failed"
    ]);
    exit;
}



/* READ JSON INPUT */
$data = json_decode(file_get_contents("php://input"), true);

if(!empty($data))
{
    foreach($data as $row)
    {

        $snoid = $row['snoid'];
        $accountno = $row['accountno'];
        $name = $row['name'];
        $Phone_no = $row['Phone_no'];
        $address1 = $row['address1'];
        $address2 = $row['address2'];
        $Doorno = $row['Doorno'];
        $StreetName = $row['StreetName'];
        $lasttransdt = $row['lasttransdt'];
        $actype = $row['actype'];
        $amount = $row['amount'];
        $multiplicationamt = $row['multiplicationamt'];
        $limitamt = $row['limitamt'];
        $insamt = $row['insamt'];
        $opendt = $row['opendt'];
        $duedt = $row['duedt'];
        $ag_code = $row['ag_code'];
        $ag_name = $row['ag_name'];
        $optcl = $row['optcl'];
        $minamt = $row['minamt'];
        $multiamtlimit = $row['multiamtlimit'];
        $period = $row['period'];
        $interestamt = $row['interestamt'];
        $totalamt = $row['totalamt'];
        $penaltyamt = $row['penaltyamt'];
        $interestpaid = $row['interestpaid'];
        $interestdue = $row['interestdue'];
        $loanbaldue = $row['loanbaldue'];
        $rate = $row['rate'];
        $pendingpenalty = $row['pendingpenalty'];
        $colinterest = $row['colinterest'];
        $Totinsttno = $row['Totinsttno'];
        $Paidinstno = $row['Paidinstno'];
        $EnableInst = $row['EnableInst'];
        $branch_id = $row['branch_id'];

        $sql = "INSERT INTO master
        (snoid,accountno,name,Phone_no,address1,address2,Doorno,StreetName,lasttransdt,actype,amount,multiplicationamt,limitamt,insamt,opendt,duedt,ag_code,ag_name,optcl,minamt,multiamtlimit,period,interestamt,totalamt,penaltyamt,interestpaid,interestdue,loanbaldue,rate,pendingpenalty,colinterest,Totinsttno,Paidinstno,EnableInst,branch_id)
        VALUES
        ('$snoid','$accountno','$name','$Phone_no','$address1','$address2','$Doorno','$StreetName','$lasttransdt','$actype','$amount','$multiplicationamt','$limitamt','$insamt','$opendt','$duedt','$ag_code','$ag_name','$optcl','$minamt','$multiamtlimit','$period','$interestamt','$totalamt','$penaltyamt','$interestpaid','$interestdue','$loanbaldue','$rate','$pendingpenalty','$colinterest','$Totinsttno','$Paidinstno','$EnableInst','$branch_id')";

        mysqli_query($conn,$sql);
    }

    echo json_encode(["status"=>"success","message"=>"Master data inserted"]);

}
else
{
    echo json_encode(["status"=>"error","message"=>"No data received"]);
}


?>