public function select($id, $domain_id = '')
 {
     global $logger;
     if (!empty($domain_id)) {
         $this->domain_id = $domain_id;
     }
     $sql = "SELECT \n                    i.*,\n\t\t            i.date as date_original, \n                    (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,\n                    p.pref_inv_wording AS preference,\n                    p.status\n                FROM \n                    " . TB_PREFIX . "invoices i LEFT JOIN \n\t\t\t\t\t" . TB_PREFIX . "preferences p  \n\t\t\t\t\t\tON (i.preference_id = p.pref_id AND i.domain_id = p.domain_id)\n                WHERE \n                    i.domain_id = :domain_id \n                AND \n\t\t\t\t\ti.id = :id";
     $sth = dbQuery($sql, ':id', $id, ':domain_id', $this->domain_id);
     $invoice = $sth->fetch();
     $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
     $invoice['date'] = siLocal::date($invoice['date']);
     $invoice['total'] = getInvoiceTotal($invoice['id'], $domain_id);
     $invoice['gross'] = $this->getInvoiceGross($invoice['id'], $this->domain_id);
     $invoice['paid'] = calc_invoice_paid($invoice['id'], $domain_id);
     $invoice['owing'] = $invoice['total'] - $invoice['paid'];
     $invoice['invoice_items'] = $this->getInvoiceItems($id, $this->domain_id);
     #invoice total tax
     $sql2 = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id =  :id AND domain_id = :domain_id";
     $sth2 = dbQuery($sql2, ':id', $id, ':domain_id', $this->domain_id);
     $result2 = $sth2->fetch();
     //$invoice['total'] = number_format($result['total'],2);
     $invoice['total_tax'] = $result2['total_tax'];
     $invoice['tax_grouped'] = taxesGroupedForInvoice($id);
     return $invoice;
 }
Example #2
0
 public static function select($id)
 {
     global $logger;
     global $db;
     global $auth_session;
     $sql = "SELECT \n                    i.*,\n\t\t            i.date as date_original, \n                    (SELECT CONCAT(p.pref_inv_wording,' ',i.index_id)) as index_name,\n                    p.pref_inv_wording AS preference,\n                    p.status\n                FROM \n                    " . TB_PREFIX . "invoices i, \n                    " . TB_PREFIX . "preferences p \n                WHERE \n                    i.domain_id = :domain_id \n                    and\n                    i.preference_id = p.pref_id\n                    and \n                    i.id = :id";
     $sth = $db->query($sql, ':id', $id, ':domain_id', $auth_session->domain_id);
     $invoice = $sth->fetch();
     $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
     $invoice['date'] = siLocal::date($invoice['date']);
     $invoice['total'] = getInvoiceTotal($invoice['id']);
     $invoice['gross'] = invoice::getInvoiceGross($invoice['id']);
     $invoice['paid'] = calc_invoice_paid($invoice['id']);
     $invoice['owing'] = $invoice['total'] - $invoice['paid'];
     $invoice['invoice_items'] = invoice::getInvoiceItems($id);
     #invoice total tax
     $sql2 = "SELECT SUM(tax_amount) AS total_tax, SUM(total) AS total FROM " . TB_PREFIX . "invoice_items WHERE invoice_id =  :id";
     $sth2 = dbQuery($sql2, ':id', $id) or die(htmlsafe(end($dbh->errorInfo())));
     $result2 = $sth2->fetch();
     //$invoice['total'] = number_format($result['total'],2);
     $invoice['total_tax'] = $result2['total_tax'];
     $invoice['tax_grouped'] = taxesGroupedForInvoice($id);
     return $invoice;
 }
					<tr>
						<th class='first' >Invoice</th>
						<th>Project</th>
						<th>Date</th>
						<th>Total</th>
						<th>Paid</th>
						<th>Balance</th>
						<th>This check</th>
						<th>after Balance</th>
						<th class='last' >Remove</th>
					</tr>
					<?
					$queryInvoices = "select * from receiptcheques JOIN invoice using (invoiceId) JOIN project using (projectId) where customerSuperCheckId = ".$paymentInfo['customerSuperCheckId'];
					$invoices = mysql_query($queryInvoices, $conexion);
					while($invoice = mysql_fetch_assoc($invoices)){
						$total = getInvoiceTotal($invoice['invoiceId'], $conexion);
						$paid = getInvoicePaid($invoice['invoiceId'], $conexion);
						echo "<tr id='receipt".$invoice['receiptchequesId']."' receiptId='".$invoice['receiptchequesId']."'>
							<td>".$invoice['invoiceId']."</td>
							<td>".$invoice['projectName']."</td>
							<td>".to_MDY($invoice['invoiceDate'])."</td>
							<td>".decimalPad($total)."</td>
							<td>".decimalPad($paid - $invoice['receiptchequesAmount'])."</td>
							<td>".decimalPad($total - ($paid - $invoice['receiptchequesAmount']))."</td>
							<td class='sumable'>".decimalPad($invoice['receiptchequesAmount'])."</td>
							<td>".decimalPad($total - $paid)."</td>
							<td><img src='/trucking/img/118.png' width='20px' height='20px' class='removableInvoice' /></td>
						</tr>";
					}
					?>
				</table>
function getInvoices(&$sth)
{
    global $config;
    $invoice = null;
    if ($invoice = $sth->fetch()) {
        $invoice['calc_date'] = date('Y-m-d', strtotime($invoice['date']));
        $invoice['date'] = siLocal::date($invoice['date']);
        #invoice total total - start
        $invoice['total'] = getInvoiceTotal($invoice['id']);
        #invoice total total - end
        #amount paid calc - start
        $invoice['paid'] = calc_invoice_paid($invoice['id']);
        #amount paid calc - end
        #amount owing calc - start
        $invoice['owing'] = $invoice['total'] - $invoice['paid'];
        #amount owing calc - end
    }
    return $invoice;
}
if($_GET['listed']!='all'){
	$queryTickets .= "limit ".$_GET['listed'];
}

//echo $queryTickets;
	
//echo $queryTickets;	
$colorFlag=true;
$terms = mysql_query($queryTickets,$conexion);
$numTerms = mysql_num_rows($terms);
$tbody = "<tbody>";
while($term = mysql_fetch_assoc($terms)){
	
	//get invoice balance
	$invoiceTotal = getInvoiceTotal($term['invoiceId'], $conexion);
	$invoicePaid = getInvoicePaid($term['invoiceId'], $conexion);
	$balance = decimalPad($invoiceTotal - $invoicePaid);
	$cheques = mysql_fetch_assoc(mysql_query("select count(*) as paidCheques from receiptcheques WHERE invoiceId = ".$term['invoiceId'], $conexion));
	
	if($cheques['paidCheques'] > 0 && $balance <= 0)continue;
	//if already paid continue
	if($balance <= 0)/*continue;*/$paid = true;
	else $paid = false;
	//
	//TODO: try with mysql query
	//if($_GET['vendorId']!=0 && $_GET['vendorId']!=$term['vendorId'])continue;
	//if($_GET['supplierId']!=0 && $_GET['supplierId']!=$term['supplierId'])continue;
	/*if($term['supplierInvoiceId'] == null){
		
	}else{
<?php

include_once '../function_header.php';
include '../common_server_functions.php';
//print_r($_REQUEST);
$responseCode = 0;
$invoice = $_REQUEST['reportId'];
if ($invoice == '') {
    die(wrapFormError(ERROR_CODE_INVALID_VALUE, 'Internal Error', ''));
}
$invoiceTotal = getInvoiceTotal($invoice, $conexion);
$invoicePaid = getInvoicePaid($invoice, $conexion);
$invoiceBalance = $invoiceTotal - $invoicePaid;
if ($invoiceBalance <= 0) {
    die(wrapFormError(ERROR_CODE_INVALID_VALUE, 'This invoice is already paid. Please refresh your page.', ''));
}
$check = $_REQUEST['check'];
if ($check == '') {
    die(wrapFormError(ERROR_CODE_INVALID_VALUE, 'Internal Error', ''));
}
$number = $_REQUEST['number'];
if ($number == '') {
    die(wrapFormError(ERROR_CODE_INVALID_VALUE, 'Internal Error', ''));
}
$date = $_REQUEST['date'];
if ($date == '0') {
    die(wrapFormError(ERROR_CODE_INVALID_VALUE, 'The date si not in a correct format', ''));
}
$amount = $_REQUEST['amount'];
if ($amount > $invoiceBalance) {
    die(wrapFormError(ERROR_CODE_INVALID_VALUE, "The amount you want to pay ({$amount}) is greater than the amount left to pay ({$invoiceBalance}). Please refresh your page. ", ''));
	<table class="listing form" cellpadding="0" cellspacing="0">
		<tr>
			<th colspan='5'>Payment for Customer Invoice [<?php 
echo $reportId;
?>
]</th>
		</tr>
		<tr>
			<th>Customer Check</th>
			<th>Credit</th>
			<th>Amount to Pay</th>
			<th>Date</th>
			<th></th>
		</tr>
		<?php 
$reportTotal = getInvoiceTotal($reportId, $conexion);
$paidTotal = getInvoicePaid($reportId, $conexion);
$balance = decimalPad($reportTotal - $paidTotal);
$invoiceInfo = getCustomerInvoiceInfo($conexion, $reportId);
//Truck
$flag = true;
$credits = mysql_query("SELECT * FROM customer_credit JOIN customer_super_check USING (customerSuperCheckId) WHERE\tcustomerId = '" . $invoiceInfo['customerId'] . "'", $conexion);
while ($credit = mysql_fetch_assoc($credits)) {
    $creditValue = decimalPad($credit['customerCreditAmount']);
    echo printRow(($flag ? "class='bg'" : "") . " rowId='F" . $reportId . "W" . $credit['customerSuperCheckId'] . "' ", array($credit['customerSuperCheckNumber'], $creditValue, createInputText("paymentF" . $reportId . "W" . $credit['customerSuperCheckId'], '', "size='10px'", decimalPad($creditValue > $balance ? $balance : $creditValue)), createInputText("dateF" . $reportId . "W" . $credit['customerSuperCheckId'], "", "size='10px'", to_MDY($credit['customerSuperCheckDate'])), createInputHidden("checkF" . $reportId . "W" . $credit['customerSuperCheckId'], "", "size='10px'", $credit['customerSuperCheckId']) . " " . createInputHidden("numberF" . $reportId . "W" . $credit['customerSuperCheckId'], "", "size='10px'", $credit['customerSuperCheckNumber']) . " " . printImgLink(IMG_PAY, "customerPayable", "Pay with check " . $credit['customerSuperCheckNumber'], ' width="22" height="22"')));
    $flag = !$flag;
    //createInputText($id, $name = '', $attributes = '', $startingValue ='')
}
echo printRow(($flag ? "class='bg'" : "") . " rowId='F" . $reportId . "W0' ", array("Cash", "N/A", createInputText("paymentF" . $reportId . "W0", '', "size='10px'", decimalPad($balance)), createInputText("dateF" . $reportId . "W0", "", "size='10px'", date('m/d/Y')), createInputHidden("checkF" . $reportId . "W0", '', "size='10px'", "0") . " " . createInputHidden("numberF" . $reportId . "W0", '', "size='10px'", "Cash") . " " . printImgLink(IMG_PAY, "customerPayable", "Pay with cash", ' width="22" height="22"')));
?>
	</table>