<?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'];
        $a=str_replace(',','',$a);
        $v=str_replace(',','',$v);
        $_REQUEST['commission']=str_replace(',','',$_REQUEST['commission']);
        $vr=1.2;
        if($v=="1"){
            $net=($a/$vr);
            $vat=$a-$net;
            $totals=$net."|".$vat;
        }
        if($v=="0"){
            $totals=$a."|0.00";
        }
        
        
        $sql=mysqli_query($GLOBALS['con'],"UPDATE `receipts` SET `payee`='".$p."',`details`='".$d."', `totals`='".$totals."', `commission`='".$_REQUEST['commission']."', `date`='".$date."' WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error($GLOBALS['con']));
        echo $date;
    break;

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

    case "removeInvoice":
        echo $_REQUEST['invoice'];
        $sql=mysqli_query($GLOBALS['con'],"UPDATE `invoices` SET `date_paid`='0', `status`='1' WHERE `invNo`='".$_REQUEST['invoice']."'")or die(mysqli_error($GLOBALS['con']));
        $sql=mysqli_query($GLOBALS['con'],"DELETE FROM `receipts` WHERE `id`='".$_REQUEST['id']."'")or die(mysqli_error($GLOBALS['con']));
        
    break;
}