<?php 

include "top.php";




$q=mysqli_query($con,"SELECT * FROM adduser");
while($arr=mysqli_fetch_array($q)){



        $chkdata=f(q("SELECT * FROM tbl_change_package WHERE userid='$arr[id]'"));
        if($chkdata['pay_ch']==''){



            $totpr=f(q("SELECT SUM(prc) as total FROM `tbl_pack` WHERE pid IN(SELECT pac_id FROM tbl_change_package_details WHERE customer_id='$arr[id]')"));
            $totals=round($totpr[total],2);
            $upuser=mysqli_query($con,"UPDATE adduser SET price='$totals' WHERE id='$arr[id]'");
            
            $inspc=mysqli_query($con,"INSERT INTO tbl_change_package SET `userid`='$arr[id]',`price`='$totals',`pay_ch`='Pack Change',`packpr`='$totals',`ncf`='0',`chp`='0',`ala`='$totals',`dbp`='0',`totalc`='$totals',`chno`='0',`alano`='0',`bpno`='0'");

            $maxid=mysqli_insert_id($con);
            $upchange=mysqli_query($con,"UPDATE tbl_change_package_details SET chid='$maxid' WHERE customer_id='$arr[id]'");



        }else{

            $totpr=f(q("SELECT SUM(prc) as total FROM `tbl_pack` WHERE pid IN(SELECT pac_id FROM tbl_change_package_details WHERE customer_id='$arr[id]')"));
            $totals=round($totpr[total],2);
            $upuser=mysqli_query($con,"UPDATE adduser SET price='$totals' WHERE id='$arr[id]'");
            $inspc=mysqli_query($con,"UPDATE tbl_change_package SET `price`='$totals',`pay_ch`='Pack Change',`packpr`='$totals',`ncf`='0',`chp`='0',`ala`='$totals',`dbp`='0',`totalc`='$totals',`chno`='0',`alano`='0',`bpno`='0' WHERE `id`='$chkdata[id]'");

            $maxid=$chkdata['id'];
            $upchange=mysqli_query($con,"UPDATE tbl_change_package_details SET chid='$maxid' WHERE customer_id='$arr[id]'");



        }





}


?>