/public/calendar_db.js"></script> 
	<link rel="stylesheet" href="<?php 
echo $a['path'];
?>
/public/calendar.css">
</head>
<body>
<div id="wrap">
	<div id="main">
		<?php 
if ($_SESSION['username']) {
    ?>
		<div class="menu">
		 <ul>
			<li><a href="?load=list_billing" title="Lista de Vencimentos">Vencimentos</a></li>
			<li><a href="?load=list_services" title="Lista de Serviços">Serviços</a></li>
			<li><a href="?load=list_company" title="Lista de Clientes">Empresas</a></li>
                       	<li><a href="?load=list_statics" title="Ver tabela de ingressos e gastos">Estatística</a></li>
			<?php 
    if (mselect($_SESSION['id'], 'ugroup', 'seller') == 1) {
        ?>
				<li><a href="?load=billing" title="Adicionar NF">+NF</a></li>
				<li><a href="?load=company" title="Adicionar novo Cliente">+Empresas</a></li>
				<li><a href="?load=services" title="Adicionar novo Serviço">+Serviço</a></li>
			<?php 
    }
    ?>
		 </ul>
		</div>
		<?php 
}
    echo "Adicionar";
} else {
    echo "Atualizar";
}
?>
">&nbsp;&nbsp;
					<?php 
if (!empty($d['value_id'])) {
    ?>
					 <input type="submit" name="delete" value="Eliminar" onClick="return confirmSubmit()">
					<?php 
}
?>
				</div>
				<?php 
if (mselect($d['value_service'], 'freq', 'services') == '1') {
    ?>
				 <div class="right">
					Éste é um pagamento mensual, deseja criar o próximo pagamento? 
					<input type="checkbox" name="sycle" value="1">
				 </div>
				<?php 
}
?>
			</td> 
        	<td class="right2">&nbsp;</td> 
        </tr></tfoot>
		<tbody>
		<tr>
			<td><input type="text" name="nf" value="<?php 
echo $d['value_nf'];
    if ($freq == '0') {
        $freq = 'Unico';
    } elseif ($freq == '1') {
        $freq = 'Mensual';
    } elseif ($freq == '12') {
        $freq = 'Anual';
    } else {
        $freq = "Cada " . $freq . "meses";
    }
    $company = mselect($row['id_company'], 'name', 'companys');
    if (strlen($company) > 17) {
        $company = substr($company, 0, 15) . "...";
    }
    if ($row['pago'] == '0000-00-00') {
        $row['pago'] = "Não foi pago";
    }
    $d['values2'][$x]['id_company'] = $row['id_company'];
    $d['values2'][$x]['company'] = $company;
    $d['values2'][$x]['service'] = mselect($row['id_services'], 'notes', 'services');
    $d['values2'][$x]['quantity'] = $row['quantity'];
    $d['values2'][$x]['value'] = $row['value'];
    $d['values2'][$x]['type'] = $freq;
    $d['values2'][$x]['seller'] = mselect($row['id_seller'], 'name', 'seller');
    $d['values2'][$x]['id'] = $row['id'];
    $d['values2'][$x]['nf'] = $row['nf'];
    $d['values2'][$x]['date'] = $row['date'];
    $d['values2'][$x]['venc'] = $row['venc'];
    $d['values2'][$x]['pago'] = $row['pago'];
    $d['values2'][$x]['notes'] = $row['notes'];
}
$a['debvar'] = $d;
    // To edit some billing
    $d['value_id'] = $_GET['id'];
    $pag_data = mselect($_GET['id'], 'pago', 'billing');
    if ($pag_data == '0000-00-00') {
        $pag_data = '';
    }
    $d['value_company'] = mselect($_GET['id'], 'id_company', 'billing');
    $d['value_service'] = mselect($_GET['id'], 'id_services', 'billing');
    $d['value_quantity'] = mselect($_GET['id'], 'quantity', 'billing');
    $d['value_value'] = mselect($_GET['id'], 'value', 'billing');
    $d['value_seller'] = mselect($_GET['id'], 'id_seller', 'billing');
    $d['value_nf'] = mselect($_GET['id'], 'nf', 'billing');
    $d['value_emi_data'] = mselect($_GET['id'], 'date', 'billing');
    $d['value_ven_data'] = mselect($_GET['id'], 'venc', 'billing');
    $d['value_pag_data'] = $pag_data;
    $d['value_notes'] = mselect($_GET['id'], 'notes', 'billing');
}
$result = mysql_query("SELECT id, name FROM companys ORDER BY name ASC");
while ($row = mysql_fetch_array($result)) {
    if (strlen($row['name']) > 17) {
        $row['name'] = substr($row['name'], 0, 15) . "...";
    }
    $d['list_company'][$row['id']] = $row['name'];
}
$result = mysql_query("SELECT id, name FROM services ORDER BY name ASC");
while ($row = mysql_fetch_array($result)) {
    if (strlen($row['name']) > 17) {
        $row['name'] = substr($row['name'], 0, 15) . "...";
    }
    $d['list_service'][$row['id']] = $row['name'];
}