<?php if(!empty($_REQUEST['FUNCTION'])){$_REQUEST['src']='ext2';require('../../functions/global.php');}

switch($_REQUEST['FUNCTION']){
    default:break;

    case "edit":
        $p=str_replace("'","&#39;",$_REQUEST['payee']);
        $d=str_replace("'","&#39;",$_REQUEST['details']);
        $date=strtotime($_REQUEST['date']);
        $a=$_REQUEST['amount'];
        $v=$_REQUEST['vat'];
        $vr=1.2;
        if($v=="1"){
            $net=($a/$vr);
            $vat=$a-$net;
            $totals=$net."|".$vat;
        }
        if($v=="0"){
            $totals=$a."|0.00";
        }

        if($_REQUEST['type']=="payee"){
        $sql=mysqli_query($GLOBALS['con'],"UPDATE `expenses` SET `payee`='".$p."',`desc`='".$d."', `amount`='".$_REQUEST['amount']."', `totals`='".$totals."', `date`='".$date."' WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error($GLOBALS['con']));
        }
        if($_REQUEST['type']=="employee"){
            $sql=mysqli_query($GLOBALS['con'],"UPDATE `expenses` SET `employee`='".$p."',`desc`='".$d."', `amount`='".$_REQUEST['amount']."', `totals`='".$totals."', `date`='".$date."' WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error($GLOBALS['con']));
            }
        echo $_REQUEST['type'];
    break;

    case "remove":        
        $sql=mysqli_query($GLOBALS['con'],"DELETE FROM `expenses` WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error($GLOBALS['con']));
        echo $p;
    break;
}