<? include('includes/main.php'); ?>
<? //arinvoicereppay.php
echo texttitle('AR Invoice Payment History Report - '.$companyname);
echo texttitle(createtime('Y-m-d'));
if ($submit) {
unset($custstr);
if ($customerid) $custstr=' and customer.id='.sqlprep($customerid);
if ($bgdate) $bgstr=' and arinvoicepaymentdetail.datereceived>='.sqlprep($bgdate);
if ($eddate) $edstr=' and arinvoicepaymentdetail.datereceived<='.sqlprep($eddate);
if ($order) {
$orderstr=' order by arinvoicepaymentdetail.datereceived, company.companyname, gltransvoucher.voucher';
} else {
$orderstr=' order by company.companyname, arinvoicepaymentdetail.datereceived, gltransvoucher.voucher ';
};
$recordSet = &$conn->Execute('select company.companyname,gltransvoucher.voucher,arinvoice.invoicenumber,arinvoicepaymentdetail.datereceived,sum(arinvoicepaymentdetail.amount),arinvoice.invoicetotal,sum(a.amount),arinvoicepaymentdetail.paymeth,arinvoicepaymentdetail.interest from customer cross join company cross join gltransvoucher cross join arinvoice cross join arinvoicepaymentdetail left join arinvoicepaymentdetail as a on a.datereceived>arinvoicepaymentdetail.datereceived and arinvoice.id=a.invoiceid where customer.companyid=company.id and company.id=arinvoice.orderbycompanyid and arinvoice.id=arinvoicepaymentdetail.invoiceid and arinvoicepaymentdetail.voucherid=gltransvoucher.id and arinvoice.cancel=0 and arinvoice.gencompanyid='.sqlprep($active_company).$custstr.$bgstr.$edstr.' group by arinvoice.id,company.companyname,gltransvoucher.voucher,arinvoice.invoicenumber,arinvoicepaymentdetail.datereceived,arinvoice.invoicetotal,arinvoicepaymentdetail.paymeth,arinvoicepaymentdetail.interest'.$orderstr);
if (!$recordSet||$recordSet->EOF) die(texterror('No matching invoice payments found.'));
echo '<table border="1"><tr><th>Customer</th><th>Voucher</th><th>Date</th><th>Invoice #</th><th>Begin '.CURRENCY_SYMBOL.'</th><th>Amount '.CURRENCY_SYMBOL.'</th><th>Interest</th><th>Method</th></tr>';
while ($recordSet&&!$recordSet->EOF) {
if ($order) {
$new=$recordSet->fields[3];
} else {
$new=$recordSet->fields[0];
};
if (!$old==$new) {
if (isset($old)) {
echo '<tr><td colspan="5">'.$old.' Total:</td><td>'.CURRENCY_SYMBOL.num_format($atotal,PREFERRED_DECIMAL_PLACES).'</td><td colspan="2"></td></tr>';
$atotal=0;
};
$old=$new;
};
echo '<tr><td>'.$recordSet->fields[0].'</td><td>'.$recordSet->fields[1].'</td><td>'.$recordSet->fields[3].'</td><td>'.$recordSet->fields[2].'</td><td>'.CURRENCY_SYMBOL.num_format($recordSet->fields[5]-$recordSet->fields[6],PREFERRED_DECIMAL_PLACES).'</td><td>'.CURRENCY_SYMBOL.num_format($recordSet->fields[4],PREFERRED_DECIMAL_PLACES).'</td><td>'.checkequal($recordSet->fields[8],1,'Y').'</td><td>'.method($recordSet->fields[7]).'</td></tr>';
$atotal+=$recordSet->fields[4]+$recordSet->fields[8];
${'paymethtot'.$recordSet->fields[7]}+=$recordSet->fields[4]+$recordSet->fields[8];
$recordSet->MoveNext();
};
echo '<tr><td colspan="5">'.$old.' Total:</td><td>'.CURRENCY_SYMBOL.num_format($atotal,PREFERRED_DECIMAL_PLACES).'</td><td colspan="2"></td></tr>';
echo '<tr><td colspan="8"> </td></tr>';
for ($i=1; $i<=4; $i++) echo '<tr><td colspan="5">Total for all '.method($i).' Vouchers:</td><td>'.CURRENCY_SYMBOL.num_format(${'paymethtot'.$i},PREFERRED_DECIMAL_PLACES).'</td><td colspan="2"></td></tr>';
echo '</table>';
} else {
$timestamp=time();
$date_time_array=getdate($timestamp);
$hours=$date_time_array["hours"];
$minutes=$date_time_array["minutes"];
$seconds=$date_time_array["seconds"];
$month=$date_time_array["mon"];
$day=$date_time_array["mday"];
$year=$date_time_array["year"];
$timestamp=mktime($hour, $minute, $second, $month, $day, $year);
$eddate=date("Y-m-d", $timestamp);
$timestamp=mktime($hour, $minute, $second, $month-1, $day, $year);
$bgdate=date("Y-m-d", $timestamp);
echo '<form action="arinvoicereppay.php" method="post" name="mainform"><table>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Begin Period:</td><td><input type="text" name="bgdate" onchange="formatDate(this)" value="'.$bgdate.'" size="30"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="setDateField(document.mainform.bgdate); top.newWin = window.open(\'calendar.html\',\'cal\',\'dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes\')"><img src="'.IMAGE_DATE_LOOKUP.'" border="0" alt="Display Calendar"></a></td></tr>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">End Period:</td><td><input type="text" name="eddate" onchange="formatDate(this)" value="'.$eddate.'" size="30"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="setDateField(document.mainform.eddate); top.newWin = window.open(\'calendar.html\',\'cal\',\'dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes\')"><img src="'.IMAGE_DATE_LOOKUP.'" border="0" alt="Display Calendar"></a></td></tr>';
echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Order By:</td><td><select name="order"'.INC_TEXTBOX.'><option value="0">Customer<option value="1">Date</select></td></tr>';
echo '</table><input type="submit" name="submit" value="Continue"></form>';
};
function method($paymeth) {
switch ($paymeth) {
case 1:
return 'Cash';
break;
case 2:
return 'Check';
break;
case 3:
return 'Credit Card';
break;
case 4:
return 'Other';
break;
};
};
?>
<? include('includes/footer.php'); ?>