Esempio n. 1
0
 function generate_report()
 {
     access_control($this);
     $schooldetails = $this->session->userdata('schoolinfo');
     # Get the passed details into the url data array if any
     $urldata = $this->uri->uri_to_assoc(3, array('m', 'i'));
     # Pick all assigned data
     $data = assign_to_data($urldata);
     if ($this->input->post('generatepdf') || $this->input->post('generateexcel')) {
         $required_fields = array('type');
         $_POST = clean_form_data($_POST);
         $validation_results = validate_form('', $_POST, $required_fields);
         if ($validation_results['bool']) {
             $_POST = clean_form_data($_POST);
             $searchstring = '1';
             if ($_POST['type'] == 7) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(b.datetaken) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(b.datetaken) >= '" . (strtotime($_POST['datefrom']) - 86400) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND b.stockid=" . $_POST['item'];
                 }
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, 'get_borrower_list', array('isactive' => 'Y', 'searchstring' => ' b.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'borrowing_report';
                 $report_name = "BORROWING REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['datetaken']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datetaken']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date Borrowed", "Title", "Returned / Borrowed", "Name", "Date Expected");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         #check expiry of rental period
                         $currentdate = date("Y-m-d H:i:s");
                         $borrower_status = check_borrower_status($this, $row['borrowerid']);
                         $mydata = array(date("j M, Y", GetTimeStamp($row['datetaken'])), $row['stocktitle'], $row['copiestaken'] - $borrower_status . "/" . $row['copiestaken'], $row['firstname'] . " " . $row['lastname'], date("j M, Y", GetTimeStamp($row['returndate'])));
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 5) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(l.createdon) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(l.createdon) >= '" . (strtotime($_POST['datefrom']) - 86400) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND i.itemid=" . $_POST['item'];
                 }
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, 'get_stock_items_list', array('isactive' => 'Y', 'searchstring' => ' s.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'library_stock_report';
                 $report_name = "LIBRARY STOCK REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['datecreated']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['datecreated']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date Added", "Serial Number", "Title", "ISBN Number");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $mydata = array(date("j M, Y", GetTimeStamp($row['datecreated'])), $row['serialnumber'], $row['stocktitle'], $row['isbnnumber']);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 4) {
                 #Get the paginated list of the inventory
                 $data = paginate_list($this, $data, 'get_stock_list', array('isactive' => 'Y', 'searchstring' => ' school = ' . $schooldetails['id']));
                 $report_type = 'library_report';
                 $report_name = "LIBRARY REPORT";
                 if ($this->input->post('generateexcel')) {
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "", date("j M, Y", time()));
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date", "Title", "Stocked", "Available", "Out");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $stocked = get_all_stock_items($this, $row['id']);
                         $in = get_stock_items($this, $row['id'], 1);
                         $out = get_stock_items($this, $row['id'], 0);
                         $mydata = array(date("j M, Y", GetTimeStamp($row['createdon'])), $row['stocktitle'], $stocked, $in, $out);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             } elseif ($_POST['type'] == 8) {
                 if (isset($_POST['datefrom']) && isset($_POST['dateto']) && $_POST['datefrom'] != "" && $_POST['dateto'] != "") {
                     $searchstring .= " AND  UNIX_TIMESTAMP(r.returndate) <= '" . strtotime($_POST['dateto'] . ' 23:59:59') . "' AND UNIX_TIMESTAMP(r.returndate) >= '" . (strtotime($_POST['datefrom']) - 86400) . "'";
                 }
                 if (isset($_POST['item']) && $_POST['item'] != "") {
                     $searchstring .= " AND s.id=" . $_POST['item'];
                 }
                 $data['dateto'] = $_POST['dateto'];
                 $data['datefrom'] = $_POST['datefrom'];
                 #Get the paginated list of the purchases
                 $data = paginate_list($this, $data, 'get_return_list', array('isactive' => 'Y', 'searchstring' => ' b.school = ' . $schooldetails['id'] . ' AND (' . $searchstring . ')'));
                 $report_type = 'returning_report';
                 $report_name = "RETURNING REPORT";
                 if ($this->input->post('generateexcel')) {
                     $size = sizeof($data['page_list']);
                     $maxdate = date("j M, Y", GetTimeStamp($data['page_list'][$size - 1]['returndate']));
                     $mindate = date("j M, Y", GetTimeStamp($data['page_list'][0]['returndate']));
                     if (!empty($data['datefrom'])) {
                         $from = date("j M, Y", GetTimeStamp($data['datefrom']));
                     } else {
                         $from = $maxdate;
                     }
                     if (!empty($data['dateto'])) {
                         $to = date("j M, Y", GetTimeStamp($data['dateto']));
                     } else {
                         $to = $mindate;
                     }
                     $mydata = array($schooldetails['schoolname']);
                     $this->excelexport->addRow($mydata);
                     $mydata = array($report_name, "", "", "From :", $from, "", "To :", $to);
                     $this->excelexport->addRow($mydata);
                     $mydata = array("Date Returned", "Title", "Serial Number");
                     $this->excelexport->addRow($mydata);
                     foreach ($data['page_list'] as $row) {
                         $mydata = array(date("j M, Y", GetTimeStamp($row['returndate'])), $row['stocktitle'], $row['stocktitle'], $row['serialnumber']);
                         $this->excelexport->addRow($mydata);
                     }
                 }
             }
             #Format the statement
             $report_html = '';
             #$financial_details = array();
             $this->load->library('parser');
             $data['schoolname'] = $schooldetails['schoolname'];
             $data['report_html'] = $report_html;
             $output = $this->parser->parse('reports/' . $report_type, $data, true);
             if ($this->input->post('generatepdf')) {
                 gen_pdf($this, $output);
             } else {
                 $this->excelexport->download($report_type . '.xls');
             }
         }
         if ((empty($validation_results['bool']) || !empty($validation_results['bool']) && !$validation_results['bool']) && empty($data['msg'])) {
             $data['msg'] = "WARNING: The highlighted fields are required.";
         }
         $data['requiredfields'] = $validation_results['requiredfields'];
         $data['formdata'] = $_POST;
     }
     $this->load->view('library/new_report_view');
 }
Esempio n. 2
0
<td align="right" width="50%"><?php 
echo date("j M, Y", time());
?>
</td>
</tr>
</table>
</div><br /><br />
<?php 
if (!empty($page_list)) {
    echo "<table width='100%' border='0' cellspacing='0' cellpadding='5'>\r\r\n          \t<tr>\r\r\n\t\t\t<td class='listheader' nowrap>Date</td>\r\r\n\t\t\t<td class='listheader' nowrap>Title</td>\r\r\n\t\t\t\r\r\n\t\t\t<td class='listheader' nowrap>Stocked</td>\r\r\n\t\t\t<td class='listheader' nowrap>Available</td>\r\r\n\t\t\t<td class='listheader' nowrap>Out</td>\r\r\n\t\t\t</tr>";
    $counter = 0;
    foreach ($page_list as $row) {
        $stocked = get_all_stock_items($this, $row['id']);
        $in = get_stock_items($this, $row['id'], 1);
        $out = get_stock_items($this, $row['id'], 0);
        #Show one row at a time
        echo "<tr style='" . get_row_color($counter, 2) . "'>";
        echo "\r\r\n\t\t\r\r\n\t\t<td valign='top'>" . date("j M, Y", GetTimeStamp($row['createdon'])) . "</td>\r\r\n\t\t\r\r\n\t\t<td valign='top'>" . $row['stocktitle'] . "</td>\r\r\n\t\t\r\r\n\t\t<td valign='top'>" . $stocked . "</td>\r\r\n\t\t\r\r\n\t\t<td valign='top'>" . $in . "</td>\r\r\n\t\t\r\r\n\t\t<td valign='top'>" . $out . "</td>\r\r\n\t\t\r\r\n\t\t\r\r\n\t\t\r\r\n\t\t</tr>";
        $counter++;
    }
    echo "</table>";
} else {
    echo format_notice("There are no library data matching that criteria at the moment.");
}
?>
<br /><br />
<?php 
$this->load->view('incl/footer');
?>
function details($_POST, $err = "")
{
    # Get vars
    extract($_POST);
    if (isset($back) and isStock($accid)) {
        return get_stock_items($_POST);
    } elseif (isset($back)) {
        return slctacc($_POST);
    }
    $accid += 0;
    $amount = $amount + 0;
    # validate input
    require_lib("validate");
    $v = new validate();
    $v->isOk($refnum, "num", 1, 10, "Invalid Reference number.");
    $v->isOk($ct_day, "num", 1, 2, "Invalid to Date ct_day.");
    $v->isOk($ct_month, "num", 1, 2, "Invalid to Date ct_monthth.");
    $v->isOk($ct_year, "num", 1, 4, "Invalid to Date Year.");
    $date = $ct_day . "-" . $ct_month . "-" . $ct_year;
    if (!checkdate($ct_month, $ct_day, $ct_year)) {
        $v->isOk($date, "num", 1, 1, "Invalid date.");
    }
    $v->isOk($accid, "num", 1, 50, "Invalid Contra Account.");
    $v->isOk($cusnum, "num", 1, 50, "Invalid Customer number.");
    $v->isOk($vatinc, "string", 1, 6, "Invalid Transaction VAT Option.");
    if (sprint($amount) <= 0) {
        $v->addError($amount, "Invalid Or Too Small Amount Entered.");
    }
    if ($accid == "0") {
        $v->addError($accid, "No Allowed Accounts Found. <a href='settings/credit-note-accounts.php'>Please Add One First</a>");
    }
    # display errors, if any
    if ($v->isError()) {
        $confirm = "";
        $errors = $v->getErrors();
        foreach ($errors as $e) {
            $confirm .= "<li class='err'>" . $e["msg"] . "</li>";
        }
        return slctacc($_POST, $confirm . "<br>");
    }
    # CHECK IF THIS DATE IS IN THE BLOCKED RANGE
    $blocked_date_from = getCSetting("BLOCKED_FROM");
    $blocked_date_to = getCSetting("BLOCKED_TO");
    if (strtotime($date) >= strtotime($blocked_date_from) and strtotime($date) <= strtotime($blocked_date_to) and !user_is_admin(USER_ID)) {
        return slctacc($_POST, "<li class='err'>Period Range Is Blocked. Only an administrator can process entries within this period.</li><br>");
    }
    #if stock returned is selected ... override the setting
    if (isset($gotstock) and strlen($gotstock) > 0) {
        #get a stock id
        db_conn('exten');
        $get_stkid = "SELECT stkacc FROM warehouses ORDER BY whid ASC LIMIT 1";
        $run_stkid = db_exec($get_stkid) or errDie("Unable to get inventory account information.");
        if (pg_numrows($run_stkid) < 1) {
            return "<li class='err'>No Inventory Account Found.</li>";
        } else {
            $accid = pg_fetch_result($run_stkid, 0, 0);
        }
    }
    # get contra account details
    $accRs = get("core", "*", "accounts", "accid", $accid);
    $acc = pg_fetch_array($accRs);
    #### handle the stock we selected
    if ((isStock($accid) or isset($gotstock)) and !isset($stockcontinue)) {
        #for whatever reason ... we need to get stock ...
        return get_stock_items($_POST);
    }
    db_connect();
    # Select customer
    $sql = "SELECT * FROM customers WHERE cusnum = '{$cusnum}' AND div = '" . USER_DIV . "'";
    $custRslt = db_exec($sql) or errDie("Unable to access databse.", SELF);
    if (pg_numrows($custRslt) < 1) {
        return "<li class='err'>Invalid customer ID, or customer has been blocked.</li>";
    } else {
        $cust = pg_fetch_array($custRslt);
    }
    db_conn("exten");
    $sql = "SELECT * FROM departments WHERE deptid = '{$cust['deptid']}' AND div = '" . USER_DIV . "'";
    $deptRslt = db_exec($sql);
    if (pg_numrows($deptRslt) < 1) {
        return "<i class='err'>Customer Department Not Found</i>";
    } else {
        $dept = pg_fetch_array($deptRslt);
    }
    #get a stock total
    $stock_total = 0;
    if (isset($stock_items) and is_array($stock_items)) {
        foreach ($stock_items as $each => $own) {
            $stock_total = $stock_total + $stock_cost[$each] * $own;
        }
    }
    $stkamount = 0;
    $send_stock = "";
    $show_stock = "";
    if (isset($stock_items) and is_array($stock_items)) {
        $unit_total = array_sum($stock_items);
        if ($unit_total == 0) {
            $stock_unit_avg_cost = 0;
        } else {
            $stock_unit_avg_cost = sprint(($amount - $stock_total) / $unit_total);
        }
        foreach ($stock_items as $each => $own) {
            if ($own > 0) {
                if (!isset($own) or strlen($own) < 1) {
                    $own = 1;
                }
                if (!isset($stock_cost[$each]) or strlen($stock_cost[$each]) < 1) {
                    $stock_cost[$each] = 0;
                }
                $send_stock .= "<input type='hidden' name='stock_items[{$each}]' value='{$own}'>\n";
                $send_stock .= "<input type='hidden' name='stock_cost[{$each}]' value='{$stock_cost[$each]}'>\n";
                db_connect();
                $get_stk = "SELECT stkdes,whid FROM stock WHERE stkid = '{$each}' LIMIT 1";
                $run_stk = db_exec($get_stk) or errDie("Unable to get stock information.");
                if (pg_numrows($run_stk) < 1) {
                    $stock_name = "Unknown";
                } else {
                    $stock_name = pg_fetch_result($run_stk, 0, 0);
                    $whid = pg_fetch_result($run_stk, 0, 1);
                    db_conn('exten');
                    $get_cos = "SELECT cosacc FROM warehouses WHERE whid = '{$whid}' LIMIT 1";
                    $run_cos = db_exec($get_cos) or errDie("Unable to get cost of sale information. (1)");
                    if (pg_numrows($run_cos) < 1) {
                        $show_cos = "";
                    } else {
                        $cos_id = pg_fetch_result($run_cos, 0, 0);
                        db_conn('core');
                        $get_acc = "SELECT topacc,accnum,accname FROM accounts WHERE accid = '{$cos_id}' LIMIT 1";
                        $run_acc = db_exec($get_acc) or errDie("Unable to get cost of sale information. (2)");
                        if (pg_numrows($run_acc) < 1) {
                            $show_cos = "";
                        } else {
                            $aarr = pg_fetch_array($run_acc);
                            $show_cos = "{$aarr['topacc']}/{$aarr['accnum']} - {$aarr['accname']}";
                        }
                    }
                }
                if (!isset($stock_prof[$each])) {
                    $stock_prof[$each] = sprint($stock_unit_avg_cost * $own);
                }
                $show_stock .= "\n\t\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t\t<td colspan='2'>{$stock_name}</td>\n\t\t\t\t\t\t\t\t\t\t<td>{$own}</td>\n\t\t\t\t\t\t\t\t\t\t<td nowrap>" . CUR . " " . sprint($stock_cost[$each]) . "</td>\n\t\t\t\t\t\t\t\t\t\t<td nowrap>" . CUR . " " . sprint($stock_cost[$each] * $own) . "</td>\n\t\t\t\t\t\t\t\t\t\t<td><input type='text' size='7' name='stock_prof[{$each}]' value='{$stock_prof[$each]}'></td>\n\t\t\t\t\t\t\t\t\t\t<td nowrap>{$show_cos}</td>\n\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t";
                $stkamount = $stkamount + $stock_cost[$each] * $own;
            }
        }
    }
    if (strlen($send_stock) == 0) {
        $send_stock = "<input type='hidden' name='stock_items' value='0'>";
        $send_stock .= "<input type='hidden' name='stock_cost' value='0'>";
        $send_stock .= "<input type='hidden' name='stock_prof' value='0'>";
        $get_gds_note = "";
    } else {
        $send_stock .= "<input type='hidden' name='stockcontinue' value='0'>";
        $send_stock .= "<input type='hidden' name='gotstock' value='1'>";
        if (isset($gds_note) and strlen($gds_note) > 0) {
            $gds_note_sel = "checked='yes'";
        } else {
            $gds_note_sel = "";
        }
        $get_gds_note = "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td>Print Goods Received Note</td>\n\t\t\t\t\t\t\t\t<td><input type='checkbox' name='gds_note' value='yes' {$gds_note_sel}></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t";
    }
    db_conn('core');
    $get_sales_acc = "SELECT topacc,accnum,accname FROM accounts WHERE accid = '{$dept['incacc']}' LIMIT 1";
    $run_sales_acc = db_exec($get_sales_acc) or errDie("Unable to get sales account information. (1)");
    if (pg_numrows($run_sales_acc) < 1) {
        $show_sales = "";
    } else {
        $sarr = pg_fetch_array($run_sales_acc);
        $show_sales = "{$sarr['topacc']}/{$sarr['accnum']} - {$sarr['accname']}";
    }
    if (strlen($show_stock) > 0) {
        $show_stock = "\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='2'>Stock Description</th>\n\t\t\t\t\t\t\t<th>Number Of Units Returned</th>\n\t\t\t\t\t\t\t<th>Unit Cost</th>\n\t\t\t\t\t\t\t<th>Total</th>\n\t\t\t\t\t\t\t<th>Profit/Loss</th>\n\t\t\t\t\t\t\t<th>Cost Of Sale Account</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t{$show_stock}\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td colspan='4' align='right'><b>Total:</b></td>\n\t\t\t\t\t\t\t<td nowrap>" . CUR . " " . sprint($stock_total) . "</td>\n\t\t\t\t\t\t\t<td colspan='2' nowrap><li class='err'>Difference ({$amount} - " . sprint($stock_total) . "): " . CUR . " " . sprint($amount - $stock_total) . "</li></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td colspan='7'><li class='err'>Sales Account To Be Used: {$show_sales}</li></td>\n\t\t\t\t\t\t</tr>";
    }
    # Probe tran type
    if ($entry == "CT") {
        $tran = "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td colspan='3'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t\t\t<td colspan='2'>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t\t\t</tr>";
    } else {
        $tran = "\n\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t<td colspan='3'>{$cust['accno']} - {$cust['cusname']} {$cust['surname']}</td>\n\t\t\t\t\t\t<td colspan='2'>{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}</td>\n\t\t\t\t\t</tr>";
    }
    if (!isset($amount)) {
        $amount = $stkamount;
        $details = "";
    }
    if (!isset($vataccid)) {
        $vataccid = 0;
    }
    if (isset($vatinc) and $vatinc != "novat") {
        db_connect();
        $get_vatcodes = "SELECT * FROM vatcodes ORDER BY code";
        $run_vatcodes = db_exec($get_vatcodes) or errDie("Unable to get vat code inoformation.");
        if (pg_numrows($run_vatcodes) < 1) {
            return "No Vatcodes Found. Please Add One First.";
        } else {
            $vatcode_drop = "<select name='vatcode'>";
            while ($varr = pg_fetch_array($run_vatcodes)) {
                $vatcode_drop .= "<option value='{$varr['id']}'>({$varr['code']}) {$varr['description']}</option>";
            }
            $vatcode_drop .= "</select>";
        }
        db_conn('core');
        $vatacc = "<select name='vataccid'>";
        $sql = "SELECT * FROM accounts WHERE div = '" . USER_DIV . "' ORDER BY accname ASC";
        $accRslt = db_exec($sql);
        if (pg_numrows($accRslt) < 1) {
            return "<li>There are No accounts in Cubit.</li>";
        }
        $vatacc_newid = gethook("accnum", "salesacc", "name", "VAT", "VAT");
        $vataccid = getCSetting("CRED_NOTE_VAT_ACC");
        if (!isset($vataccid) or strlen($vataccid) < 1 or $vataccid == "0") {
            $vataccid = $vatacc_newid;
        }
        //		if (!isset($vataccid) OR $vataccid == "0")
        //			$vataccid = $vatacc_newid;
        //		while($acc_arr = pg_fetch_array($accRslt)){
        //			# Check Disable
        //			if(isDisabled($acc_arr['accid']))
        //				continue;
        //			if($vataccid == $acc_arr['accid']) {
        //				$sel = "selected";
        //			} else {
        //				$sel = "";
        //			}
        //			$vatacc .= "<option value='$acc_arr[accid]' $sel>$acc_arr[topacc]/$acc_arr[accnum] - $acc_arr[accname]</option>";
        //		}
        //		$vatacc .= "</select>";
        if (isset($vatdedacc) and $vatdedacc == "dt") {
            $dsel1 = "checked='yes'";
        } else {
            $dsel1 = "";
        }
        if (isset($vatdedacc) and $vatdedacc == "ct") {
            $dsel2 = "checked='yes'";
        } else {
            $dsel2 = "";
        }
        if ($dsel1 == "" and $dsel2 == "") {
            $dsel1 = "checked='yes'";
        }
        if (isStock($accid) and isset($gotstock)) {
            $showgetvatacc = "<input type='hidden' name='vatdedacc' value='dt'>";
        } else {
            $showgetvatacc = "\n\t\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t\t<td colspan='2'valign='top'>VAT Deductable Account</td>\n\t\t\t\t\t\t\t\t\t<td colspan='2'>\n\t\t\t\t\t\t\t\t\t\t<input type='radio' name='vatdedacc' value='dt' {$dsel1} />{$acc['topacc']}/{$acc['accnum']} - {$acc['accname']}<br />\n\t\t\t\t\t\t\t\t\t\t<input type='radio' name='vatdedacc' value='ct' {$dsel2} />{$cust['accno']} - {$cust['surname']}\n\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t";
        }
        db_conn('core');
        $get_vatacc = "SELECT accname FROM accounts WHERE accid = '{$vataccid}' LIMIT 1";
        $run_vatacc = db_exec($get_vatacc) or errDie("Unable to get vat account details.");
        if (pg_numrows($run_vatacc) < 1) {
            $showvatacc = "";
        } else {
            $vatacc_id = pg_fetch_result($run_vatacc, 0, 0);
            $showvatacc = "\n\t\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t\t<td colspan='2'>VAT Account</td>\n\t\t\t\t\t\t\t\t<td colspan='3'>{$vatacc_id} <a target='_blank' href='settings/credit-note-accounts.php'>Change Account</a></td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t";
        }
        //		<tr class='".bg_class()."'>
        //			<td colspan='2'>VAT Account</td>
        //			<td colspan='3'>$vatacc</td>
        //		</tr>
        $get_vats = "\n\t\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t\t<input type='hidden' name='vataccid' value='{$vataccid}'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='5'>VAT Detail</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t{$showgetvatacc}\n\t\t\t\t\t\t{$showvatacc}\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td colspan='2'>VAT Code</td>\n\t\t\t\t\t\t\t<td colspan='3'>{$vatcode_drop}</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t" . TBL_BR . "\n\t\t\t\t\t";
    } else {
        $get_vats = "\n\t\t\t\t\t\t<input type='hidden' name='vatinc' value='novat'>\n\t\t\t\t\t\t<input type='hidden' name='vatcode' value='0'>\n\t\t\t\t\t";
    }
    // Layout Details
    $details = "\n    \t\t\t\t<h3>Confirm Credit Note Details</h3>\n    \t\t\t\t{$err}\n    \t\t\t\t<form action='" . SELF . "' method='POST' name='form'>\n\t\t\t\t        <input type='hidden' name='key' value='write'>\n\t\t\t\t\t\t<input type='hidden' name='type' value='1'>\n\t\t\t\t\t\t<input type='hidden' name='date' value='{$date}'>\n\t\t\t\t\t\t<input type='hidden' name='cusnum' value='{$cusnum}'>\n\t\t\t\t        <input type='hidden' name='accid' value='{$accid}'>\n\t\t\t\t        <input type='hidden' name='accname' value='{$acc['accname']}'>\n\t\t\t\t\t\t<input type='hidden' name='entry' value='{$entry}'>\n\t\t\t\t\t\t<input type='hidden' name='ct_day' value='{$ct_day}'>\n\t\t\t\t        <input type='hidden' name='ct_month' value='{$ct_month}'>\n\t\t\t\t        <input type='hidden' name='ct_year' value='{$ct_year}'>\n\t\t\t\t        <input type='hidden' name='vatinc' value='{$vatinc}'>\n\t\t\t\t        <input type='hidden' name='ac' value=''>\n\t\t\t\t        <input type='hidden' name='amount' value='{$amount}'>\n\t\t\t\t        <input type='hidden' name='refnum' value='{$refnum}'>\n\t\t\t\t        <input type='hidden' name='difference' value='" . sprint($amount - $stock_total) . "'>\n\t\t\t\t        {$send_stock}\n\t\t\t        <table " . TMPL_tblDflts . " width='500'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<th colspan='3'>Debit</th>\n\t\t\t\t\t\t\t<th colspan='2'>Credit</th>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t{$tran}\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t{$show_stock}\n    \t\t\t\t\t{$get_vats}\n    \t\t\t\t</table>\n    \t\t\t\t<table " . TMPL_tblDflts . " width='500'>\n    \t\t\t\t\t" . TBL_BR . "\n    \t\t\t\t\t<tr>\n    \t\t\t\t\t\t<th colspan='2'>Transaction Details</th>\n    \t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Transaction Details</td>\n\t\t\t\t\t\t\t<td valign='center'><textarea cols='30' rows='5' name='details'>{$details}</textarea></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t{$get_gds_note}\n\t\t\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t\t\t<td>Person Authorising</td>\n\t\t\t\t\t\t\t<td valign='center'><input type='hidden' size='20' name='author' value=" . USER_NAME . ">" . USER_NAME . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr><td><br></td></tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td><input type='submit' name='back' value='&laquo; Correction'></td>\n\t\t\t\t\t\t\t<td valign='center' align='right'><input type='submit' value='Confirm &raquo;'></td>\n\t\t\t\t\t\t</tr>\n\t\t\t        </table>\n\t\t\t        </form>";
    return $details;
}