<?php 
if(isset($_REQUEST['btnprint'])){
    $memoreceipt = $_REQUEST['memoreceipt'];
    $subj = $_REQUEST['subj'];
    $msgecontent = $_REQUEST['msgecontent'];
    $userSent = $_REQUEST['userSent'];
    $sentAppoint = $_REQUEST['sentAppoint'];
    $DeptSent = $_REQUEST['DeptSent'];
    $document_type = $_REQUEST['document_type'];
    $infoRecip = $_REQUEST['infoRecip'];

    $dueDate = date('Y-m-d');
    $today = date('Y-m-d H:i:s');
    $year= date('Y');
    ###### GENERATE CODE ######
    $this_Yr =  substr($year,2,2);
    $mon = date('m');
    $dy = date('d');

    $client = 1;

    $stms_last = $db->prepare("SELECT regst_id FROM tbl_info_register ORDER BY regst_id DESC LIMIT 1");
	try {
	$stms_last->execute(array());
	$row_count_last = $stms_last->rowCount();
	if ($row_count_last > 0){
		$rows = $stms_last->fetch(PDO::FETCH_ASSOC);
		$reg = $rows['regst_id']+1;
	}else{
		$reg = 1;
	}

	}
	catch (PDOException $ex) {
		echo $ex->getMessage();
	}
    
    ####### INFO #####
    $uniqueNo = $this_Yr.$mon.$dy.$reg; 
    $statement = $db->prepare("INSERT INTO tbl_info_register(track_id, clnt_id, sub_matt,info_notes, reg_due, acc_sder, appointsnt, reg_dept, prio, created_reg_trm, doctype, informto, stts_reg)
    VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");
    $statement->execute(array($uniqueNo,$client,$subj,$msgecontent,$dueDate,$userSent,$sentAppoint,$DeptSent,0,$today,$document_type,$infoRecip,1));
    $infoLastId = $db->lastInsertId();
    
    ######## CON ########
    $stmt = $db->prepare("INSERT INTO tbl_con_infos (reg_info_id, dSent, appntsent, iSd,info_sts,conTrm,dRcv,recvappnt,iRcv,dueCon) VALUES(?,?,?,?,?,?,?,?,?,?)");
    $stmt->execute( array($infoLastId, $DeptSent, $sentAppoint,$userSent,1,$today,0,$memoreceipt,0, $dueDate));
    
   
echo'<script type="text/javascript">
    jQuery(function validation(){
    swal("INTER MEMO SAVED", "Successfully", "success", {
    button: "Continue",
    });
    });
</script>';
    
echo'<script type="text/javascript">
window.open("memo?infoid='.$infoLastId.'");
</script>';


}
?>