本文整理汇总了PHP中open函数的典型用法代码示例。如果您正苦于以下问题:PHP open函数的具体用法?PHP open怎么用?PHP open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* @coroutine
*
* @param string $path
* @param string $data
* @param bool $append
*
* @return \Generator
*
* @resolve int Number of bytes written.
*
* @throws \Icicle\File\Exception\FileException
*/
function put(string $path, string $data, bool $append = false) : \Generator
{
/** @var \Icicle\File\File $file */
$file = (yield from open($path, $append ? 'a' : 'w'));
try {
$written = (yield from $file->write($data));
} finally {
$file->close();
}
return $written;
}
示例2: open
function open($path)
{
$dirs = array();
foreach (scandir($path) as $file) {
if (in_array($file, $GLOBALS['ignore'])) {
continue;
}
if (is_dir($path . DS . $file)) {
$dirs[] = realpath($path . DS . $file);
$dirs = array_merge($dirs, open($path . DS . $file));
}
}
return $dirs;
}
示例3: create
function create()
{
$_SESSION['election'] = 1;
$name = $_SESSION['name'];
$election = $_SESSION['election'];
$content = $_POST['message'];
$content .= "|{$name}|";
echo $content;
if (!file_exists("Discussions/")) {
mkdir("Discussions/", 0777, true);
}
file_put_contents("Discussions/" . $election . ".txt", $content, FILE_APPEND);
open($name, $election);
}
示例4: borrar
function borrar()
{
if ($flag == 0) {
$conn->EjecutarSQL("COMMIT TRANSACTION A1");
$MSG = "Datos borrados con exito";
}
$respuesta->addAlert($MSG);
return $respuesta;
// ajax = objetoAjax();
$respuesta = new xajaxResponse();
ajax . open("GET", "eliminar.php");
$MSG = "cambiando de pagina";
$respuesta->addAlert($MSG);
return $respuesta;
}
示例5: test_pic_show
public function test_pic_show()
{
$info = D('pic');
$pic_name = 4;
$res = $info->query("select name from ld_pic where id='{$pic_name}'");
// $this->display();
if ($res) {
echo "OK";
$image = new \Think\Image();
open();
} else {
echo "No";
}
// 这里是取出的数据结果集
echo $res[0]['name'];
}
示例6: beautify
function beautify($inputfile, $outputfile)
{
$settings = array('indent_width' => 2, 'indent_long_comments' => true, 'file' => $inputfile);
$beauty = new phpBeautify($settings);
$rs = $beauty->beautify();
if (PEAR::isError($rs)) {
$fp = open("php://stderr", "w");
fputs($fp, $rs->getMessage() . "\n");
fclose($fp);
} else {
$fp = fopen($outputfile, "w");
fputs($fp, $rs, strlen($rs));
fclose($fp);
}
unset($beauty);
}
示例7: topheading
function topheading($current_id, $title = null)
{
global $MENU_OPTIONS;
open('table', array('id' => 'topheading'));
tag('tr', array('id' => 'r1'), txttag('td', array('id' => 'c11'), ' ') . txttag('td', array('id' => 'c12'), ' '));
open('tr', array('id' => 'r2'));
tag('td', array('id' => 'c21'), ' ');
open('td', array('id' => 'menu'));
$i = 0;
foreach ($MENU_OPTIONS as $t_id => $t_link) {
if ($i++ != 0) {
echo ' - ';
}
tag('a', array('class' => $t_id == $current_id ? 'current' : null, 'href' => $t_link['link'], 'title' => $t_link['tooltip']), escape($t_link['text']));
}
close('table');
}
示例8: open
echo $row[title];
?>
"></td>
</tr>
<tr>
<td width="100">Content</td>
<td><textarea name="content" cols="50" rows="10" class="box" id="content"><?php
echo $row[content];
?>
</textarea></td>
</tr>
<tr>
<td width="100">Page</td>
<td><select name="page"><option value="0">Geen</option>
<?php
open();
$result = mysql_query("SELECT * FROM page");
while ($row2 = mysql_fetch_array($result)) {
if ($row[id_page] == $row2[id]) {
echo '<option value="' . $row2[id] . '" selected="selected">' . $row2[title] . '</option>';
} else {
echo '<option value="' . $row2[id] . '">' . $row2[title] . '</option>';
}
}
close();
?>
</select></td>
</tr>
<tr>
<td width="100">Sticky</td>
<td><input type="checkbox" name="sticky" class="box" <?php
示例9: open
<?
return open($argv, $argc);
function open($argv, $argc) {
global $module;
if ($argv[1] == 'fm') {
$argv[1] = 'file-manager';
}
if ($argv[1] == 'dm') {
$argv[1] = 'database-manager';
}
if ($argv[1] == 'pma') {
$argv[1] = 'phpmyadmin';
}
if ($argv[1] == 'te') {
$argv[1] = 'text-editor';
}
if ($argv[1] == 'ce') {
$argv[1] = 'code-editor';
}
// header('Location: ' . $module[ $module['prefer']['file-manager'] ]['url']);
# такая запись не оставляет записи в истории браузера:
// exit('<meta http-equiv="refresh" content="0;URL=' . $module[ $module['prefer']['file-manager'] ]['url'] . '">');
if (!empty($module[ $module['prefer'][ $argv[1] ] ]['url'])) {
// run('cloud ' . $module[ $module['prefer'][ $argv[1] ] ]['url']);
exit('<script>document.location.href = "http://' . $_SERVER['HTTP_HOST'] . $module[ $module['prefer'][ $argv[1] ] ]['url'] . '";</script>');
} else {
if (!empty($module[ $argv[1] ]['url'])) {
# try to open user choose...
// header('Location: '.$module[ $argv[1] ]['url']);
示例10: write
//.........这里部分代码省略.........
$amounts = "";
$invprds = "";
$rages = "";
$setamts = "";
#get settlement accid
$get_setacc = "SELECT accid FROM accounts WHERE accname = 'Debtors Settlement Discount'";
$run_setacc = db_exec($get_setacc) or errDie("Unable to get settlement account information");
$setaccid = pg_fetch_result($run_setacc, 0, 0);
$vatacc = gethook("accnum", "salesacc", "name", "VAT", "VAT");
$amt += $overpay;
/* OPTION 3 : ALLOCATE TO EACH INVOICE (confirm) */
if ($all == 2) {
$sql = "UPDATE cubit.customers SET balance = (balance - '{$amt}'::numeric(16,2)) WHERE cusnum = '{$cus['cusnum']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to update invoice in Cubit.", SELF);
if (isset($invids)) {
foreach ($invids as $key => $value) {
$ii = $invids[$key];
# some logic ...
# because the customer account should be 0 when paid fully, we need
# to also deduct the settlement amount ...
$paidamt[$key] = $paidamt[$key] + $stock_setamt[$key];
# with the amount added to the paid amount, we tract it using a new
# seperate setamt db column
if (!isset($itype[$key]) && !isset($ptype[$key])) {
$sql = "SELECT prd,invnum,odate FROM cubit.invoices WHERE invid ='{$invids[$key]}' AND div = '" . USER_DIV . "'";
$invRslt = db_exec($sql) or errDie("Unable to retrieve invoice details from database.");
if (pg_numrows($invRslt) < 1) {
return "<li class='err'>Invalid Invoice Number.</li>";
}
$inv = pg_fetch_array($invRslt);
// reduce invoice balance
$sql = "\n\t\t\t\t\t\tUPDATE cubit.invoices\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2))\n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "\n\t\t\t\t\t\tUPDATE cubit.open_stmnt\n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2))\n\t\t\t\t\t\tWHERE invid = '{$inv['invnum']}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
# record the payment on the statement
$sql = "\n\t\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\t\tcusnum, invid, \n\t\t\t\t\t\t\tamount, date, type, div, allocation_date, docref, \n\t\t\t\t\t\t\tallocation_balance\n\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t'{$cus['cusnum']}', '{$inv['invnum']}', \n\t\t\t\t\t\t\t'" . ($paidamt[$key] - $stock_setamt[$key] - ($paidamt[$key] - $stock_setamt[$key]) * 2) . "', \n\t\t\t\t\t\t\t'{$sdate}', 'Payment for Invoice No. {$inv['invnum']}', '" . USER_DIV . "', '{$inv['odate']}', '{$reference}', \n\t\t\t\t\t\t\t'" . abs($paidamt[$key] - $stock_setamt[$key] - ($paidamt[$key] - $stock_setamt[$key]) * 2) . "'\n\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
#record the settlement discount on the statement
if ($stock_setamt[$key] > 0) {
$sql = "\n\t\t\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\t\t\tcusnum, invid, amount, \n\t\t\t\t\t\t\t\tdate, type, \n\t\t\t\t\t\t\t\tdiv, allocation_date, docref, allocation_balance\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'{$cus['cusnum']}', '{$inv['invnum']}', '" . ($stock_setamt[$key] - $stock_setamt[$key] * 2) . "', \n\t\t\t\t\t\t\t\t'{$sdate}', 'Settlement Discount for Invoice No.{$inv['invnum']} Ref. {$refnum}', \n\t\t\t\t\t\t\t\t'" . USER_DIV . "', '{$inv['odate']}', '{$reference}', '" . abs($stock_setamt[$key] - $stock_setamt[$key] * 2) . "'\n\t\t\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
}
#deduct setamt for records ...
custledger($cus['cusnum'], $bank_acc, $sdate, $inv['invnum'], "Payment for Invoice No. {$inv['invnum']}", $paidamt[$key] - $stock_setamt[$key], "c");
db_connect();
$rinvids .= "|{$invids[$key]}";
$amounts .= "|{$paidamt[$key]}";
if ($inv['prd'] == "0") {
$inv['prd'] = PRD_DB;
}
$invprds .= "|{$inv['prd']}";
$rages .= "|0";
$invidsers .= " - {$inv['invnum']}";
$setamts .= "|{$stock_setamt[$key]}";
} elseif (!isset($ptype[$key])) {
$sql = "\n\t\t\t\t\t\tSELECT prd,invnum,descrip,age,odate \n\t\t\t\t\t\tFROM cubit.nons_invoices \n\t\t\t\t\t\tWHERE invid ='{$invids[$key]}' AND div = '" . USER_DIV . "'";
$invRslt = db_exec($sql) or errDie("Unable to retrieve invoice details from database.");
if (pg_numrows($invRslt) < 1) {
return "<li class='err'>Invalid Invoice Number.</li>";
}
$inv = pg_fetch_array($invRslt);
// reduce the invoice balance
$sql = "\n\t\t\t\t\t\tUPDATE cubit.nons_invoices \n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2)) \n\t\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "\n\t\t\t\t\t\tUPDATE cubit.open_stmnt \n\t\t\t\t\t\tSET balance = (balance - {$paidamt[$key]}::numeric(16,2)) \n\t\t\t\t\t\tWHERE invid = '{$inv['invnum']}' AND div = '" . USER_DIV . "'";
示例11: head
<?php
require_once 'site/base.inc.php';
head('Download - jMList');
topheading('download');
open('div', array('id' => 'body'));
$_jMList = txttag('span', array('class' => 'jmlist'), 'jMList');
h2('Requirements');
tag('p', array(), "The following libraries are required in order to use or compile " . "{$_jMList}:");
open('ul', array());
tag('li', array(), a('GLib', 'http://www.gtk.org/') . " 2.4.0 or higher (required)");
tag('li', array(), a('LibXML', 'http://xmlsoft.org/') . " 2.6.0 or higher (require)");
tag('li', array(), a('LibXSLT', 'http://xmlsoft.org/XSLT/') . " 1.1.0 or higher (required)");
tag('li', array(), a('ID3Lib', 'http://id3lib.sourceforge.net/') . " 3.8.0 or higher (required)");
tag('li', array(), a('OggVorbis', 'http://www.xiph.org/ogg/vorbis/') . " 1.1.0 or higher (optional, for OggVorbis support)");
close();
h2('Source Packages');
h3('Version 0.1.0 (beta)');
tag('p', array(), a('jmlist-0.1.0.tar.gz', 'http://download.berlios.de/jmlist/jmlist-0.1.0.tar.gz') . " (initial release) - " . a('Release Notes', 'http://developer.berlios.de/project/shownotes.php?release_id=5187'));
h2('Repository Access');
tag('p', array(), "{$_jMList} is hosted on a " . a('Subversion', 'http://subversion.tigris.org/') . " repository. " . "You can checkout it from " . a('svn://svn.berlios.de/jmlist/source/trunk') . " " . "or browse it at " . a('http://svn.berlios.de/viewcvs/jmlist/source/trunk') . ".");
tag('p', array(), "In order to compile from the repository, you will need the following " . "additional software:");
open('ul', array());
tag('li', array(), a('autoconf', 'http://www.gnu.org/software/autoconf/') . " 2.59 or higher");
tag('li', array(), a('automake', 'http://www.gnu.org/software/automake/') . " 1.8 or higher");
close();
tag('p', array(), "After checking-out the trunk tree, run " . txttag('code', array(), './configure.svn') . " on the working copy " . "directory in order to generate support files needed to configure and " . "compile {$_jMList}. After that, proceed as usual with " . txttag('code', array(), './configure --help') . ", " . txttag('code', array(), './configure') . ", " . txttag('code', array(), 'make') . " and " . txttag('code', array(), 'make install') . ".");
示例12: bank
function bank($_POST)
{
# Get vars
extract($_POST);
# validate input
require_lib("validate");
$v = new validate();
$v->isOk($cashid, "num", 1, 20, "Invalid Reference number.");
$v->isOk("{$date_day}{$date_month}{$date_year}", "num", 6, 8, "Invalid date selected.");
if (!checkdate($date_month, $date_day, $date_year)) {
$v->addError("", "Invalid date selected. No such date possible.");
}
# display errors, if any
if ($v->isError()) {
$confirm = "";
$errors = $v->getErrors();
foreach ($errors as $e) {
$confirm .= "<li class='err'>" . $e["msg"] . "</li>";
}
$confirm .= "<p><input type='button' onClick='JavaScript:history.back();' value='« Correct submission'>";
return $confirm;
}
$seldate = "{$date_year}-{$date_month}-{$date_day}";
$salconacc = gethook("accnum", "salacc", "name", "salaries control");
# Get cash book record
Db_Connect();
$sql = "SELECT * FROM cashbook WHERE cashid = '{$cashid}' AND div = '" . USER_DIV . "'";
$accntRslt = db_exec($sql) or errDie("ERROR: Unable to retrieve cashbook entry details from database11.", SELF);
if (pg_numrows($accntRslt) < 1) {
$OUTPUT = "<li clss='err'>The entry with reference number, <b>{$cashid}</b> was not found in Cubit.</li>";
return $OUTPUT;
}
$accnt = pg_fetch_array($accntRslt);
# get hook account number
core_connect();
$sql = "SELECT * FROM bankacc WHERE accid = '{$accnt['bankid']}' AND div = '" . USER_DIV . "'";
$rslt = db_exec($sql) or errDie("Unable to retrieve bank account link from Cubit", SELF);
# check if link exists
if (pg_numrows($rslt) < 1) {
return "<li class='err'> ERROR : The bank account that you selected doesn't appear to have an account linked to it.</li>";
}
$bank = pg_fetch_array($rslt);
# Date
$sdate = date("Y-m-d");
pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF);
# If tis customer payment
if (($accnt['cusnum'] > 0 || $accnt["multicusnum"] != "") && strlen($accnt['rinvids']) > 0) {
db_connect();
# Get invoice Ids and Amounts
$invids = explode("|", $accnt['rinvids']);
$amounts = explode("|", $accnt['amounts']);
$invprds = explode("|", $accnt['invprds']);
$rages = explode("|", $accnt['rages']);
if ($accnt["multicusnum"] != "") {
$cusnums = explode(",", $accnt["multicusnum"]);
$cusamts = explode(",", $accnt["multicusamt"]);
} else {
$cusnums = array($accnt["cusnum"]);
$cusamts = array($accnt["amount"]);
}
$oa = 0;
# Return the amount that was surppose to be paid to invoices
foreach ($invids as $key => $invid) {
if ($invids[$key] <= 0) {
continue;
}
db_connect();
if (ext_ex("invoices", "invid", $invids[$key]) && $invprds[$key] != 0) {
db_connect();
$sql = "\n\t\t\t\t\tUPDATE invoices \n\t\t\t\t\tSET balance = (balance + '{$amounts[$key]}'::numeric(13,2)) \n\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
if (open()) {
$sql = "SELECT invnum FROM invoices WHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$idata = pg_fetch_array($payRslt);
$sql = "\n\t\t\t\t\t\tUPDATE open_stmnt \n\t\t\t\t\t\tSET balance = (balance + '{$amounts[$key]}'::numeric(13,2)) \n\t\t\t\t\t\tWHERE invid = '{$idata['invnum']}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$oa = $oa - $amounts[$key];
}
} else {
if (ext_ex("nons_invoices", "invid", $invids[$key]) && $invprds[$key] == 0) {
db_connect();
$sql = "\n\t\t\t\t\tUPDATE nons_invoices \n\t\t\t\t\tSET balance = (balance + '{$amounts[$key]}'::numeric(13,2)) \n\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
/*$Sll="SELECT sdate FROM nons_invoices WHERE invid = '$invids[$key]' AND div = '".USER_DIV."'";
$Rii=db_exec($Sll) or errDie("Unable to get invoice data.");
$dii=pg_fetch_array($Rii);*/
$cnsql = "SELECT cusid FROM cubit.nons_invoices WHERE invid='{$invids[$key]}'";
$cnrslt = db_exec($cnsql) or errDie("Error reading customer info from nonstock invoice.");
$invcusid = pg_fetch_result($cnrslt, 0, 0);
custDTA($amounts[$key], $invcusid, $rages[$key], $seldate);
} else {
if ($invprds[$key] != 0 && ext_ex("pinvoices", "invid", $invids[$key], $invprds[$key])) {
$sql = "\n\t\t\t\t\tUPDATE \"{$invprds[$key]}\".pinvoices \n\t\t\t\t\tSET balance = (balance + '{$amounts[$key]}'::numeric(13,2)) \n\t\t\t\t\tWHERE invid = '{$invids[$key]}' AND div = '" . USER_DIV . "'";
db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "SELECT cusnum, balance FROM \"{$invprds[$key]}\".pinvoices WHERE invid='{$invids[$key]}'";
$rslt = db_exec($sql) or errDie("Error reading customer info from nonstock invoice.");
$invcusid = pg_fetch_result($rslt, 0, 0);
custDTA($amounts[$key], $invcusid, $rages[$key], $seldate);
} else {
//.........这里部分代码省略.........
示例13: close
echo close("tr");
}
echo "</tbody>";
echo close("table");
echo close("div");
echo open("div", array('class' => 'col-md-12'));
echo "<center><h5><b>EVOLUCIÓN DE LA TERAPIA</b></h5></center><br>";
$fecha_complicacion_field[] = array('name' => 'fechacomplicacion', 'id' => 'fechacomplicacion', 'class' => 'form-control datepicker');
echo get_field_group('FECHA', $fecha_complicacion_field, 'col-md-3 form-group');
$detalle_complicacion_field[] = array('name' => 'detallecomplicacion', 'id' => 'detallecomplicacion', 'class' => 'form-control', 'placeholder' => 'Ingrese texto');
echo get_field_group('Nota Evolucion', $detalle_complicacion_field, 'col-md-8 form-group');
echo "<a onclick='complicacion();' class='btn btn-default'><i class='glyphicon glyphicon-ok'></i></a>";
echo close("div");
echo open("div", array('class' => 'row'));
echo open("table", array('class' => 'table table-bordered', 'style' => 'width:100%; border:1px; margin:auto'));
echo open("thead", array('style' => 'background-color: #FCFFAF; text-align:center'));
echo tagcontent("td", "<b>FECHA</b>");
echo tagcontent("td", "<b>DETALLE</b>");
echo tagcontent("td", "<b>CONTROLES</b>");
echo close("thead");
echo "<tbody id='table_complicacion'></tbody>";
echo close("table");
echo close("div");
echo "<br><br>";
echo Open("div", array('class' => 'form-group'));
echo tagcontent('button', '<span class="glyphicon glyphicon-search"></span> Guardar', array('name' => 'btnreportes', 'class' => 'btn btn-primary col-md-12', 'id' => 'ajaxformbtn', 'type' => 'submit', 'data-target' => 'print'));
echo close("div");
echo close("form");
echo close("div");
echo tagcontent("div", '', array('id' => 'print', 'name' => 'print'));
?>
示例14: translate
$errormessage = '<span class="error">' . translate('no_position_found') . '</span>';
} else {
if (isset($_POST['regaddress'])) {
$password = $_GET['key'];
} else {
$password = sha1($_POST['password']);
}
$db = new MySqlConnection();
$num_rows = mysql_num_rows(mysql_query('SELECT `feed_id` FROM `aeolus`.`egg` WHERE `feed_id`=' . $fid));
// check if there already is one entry with this feed id in the database
if ($num_rows != 0) {
$errormessage = '<span class="error">' . translate('aqe_already_registered') . '</span>';
} else {
mysql_query('INSERT INTO `aeolus`.`egg` (`feed_id`, `password`, `lat`, `lon`) VALUES (' . $fid . ', \'' . $password . '\', \'' . $coordinates[0] . '\', \'' . $coordinates[1] . '\')');
// and call the create_egg.php to get first sensor values for the egg
open('create_egg.php?fid=' . $fid . '&pass=faf01b58a34e26f5ed05a4edc5e5c3ee');
$successmessage = '<span class="success">' . translate('aqe_registered') . '</span>';
}
}
}
}
}
}
// replace error and success messages
$this->registerTemplate->tplReplace('errormessage', $errormessage);
$this->registerTemplate->tplReplace('successmessage', $successmessage);
}
} else {
// replace error and success messages
$this->reg = false;
$this->registerTemplate->tplReplace('errormessage', $errormessage);
示例15: cp2
function cp2($id, $amount, $description, $contra, $refnum, $date, $cheque = 0, $bankid)
{
$cheque += 0;
$sdate = date("Y-m-d");
$accdate = $date;
if ($accdate == 0) {
$accdate = date("Y-m-d");
}
$cus = qryCustomer($id, "cusnum, deptid, cusname, surname");
$dept = qryDepartment($cus["deptid"], "debtacc");
// db_connect();
//
// $Sl = "SELECT cusnum,deptid,cusname,surname FROM customers WHERE cusnum = '$id' AND div = '".USER_DIV."'";
// $Ri = db_exec($Sl) or errDie("Unable to get data.");
// $cus = pg_fetch_array($Ri);
db_conn('core');
$Sl = "SELECT * FROM bankacc WHERE accid='{$bankid}'";
$Rx = db_exec($Sl) or errDie("Uanble to get bank acc.");
if (pg_numrows($Rx) < 1) {
return "Invalid bank acc.";
}
$link = pg_fetch_array($Rx);
#######################################################################################################
########################################### COMPILE ###################################################
#######################################################################################################
$out = $amount;
$invs_arr = array();
// Connect to database
db_connect();
#####################[ GET OUTSTANDING INVOICES ]######################
$sql = "\n\t\tSELECT invnum, invid, balance, terms, odate \n\t\tFROM invoices \n\t\tWHERE cusnum = '{$id}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' ORDER BY odate ASC";
$prnInvRslt = db_exec($sql);
while (($inv = pg_fetch_array($prnInvRslt)) && $out > 0) {
$invs_arr[] = array("s", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
}
#####################[ GET OUTSTANDING NON STOCK INVOICES ]######################
$sql = "\n\t\tSELECT invnum, invid, balance, odate \n\t\tFROM nons_invoices \n\t\tWHERE cusid='{$id}' AND done='y' AND balance>0 AND div='" . USER_DIV . "' ORDER BY odate ASC";
$prnInvRslt = db_exec($sql);
while (($inv = pg_fetch_array($prnInvRslt)) && $out > 0) {
$invs_arr[] = array("n", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
}
$out = sprint($out);
#####################[ GET OUTSTANDING POS INVOICES ]######################
$sqls = array();
for ($i = 1; $i <= 12; ++$i) {
$sqls[] = "\n\t\t\tSELECT invnum, invid, balance, odate \n\t\t\tFROM \"{$i}\".pinvoices \n\t\t\tWHERE cusnum='{$id}' AND done='y' AND balance > 0 AND div='" . USER_DIV . "'";
}
$sql = implode(" UNION ", $sqls);
$prnInvRslt = db_exec($sql);
while ($inv = pg_fetch_array($prnInvRslt)) {
$invs_arr[] = array("p", $inv['odate'], "{$inv['invid']}", "{$inv['balance']}");
}
#compile results into an array we can sort by date
$search_arr = array();
foreach ($invs_arr as $key => $array) {
$search_arr[$key] = $array[1];
}
#sort array by date
asort($search_arr);
#add sorted invoices to payment listing
foreach ($search_arr as $key => $date) {
$arr = $invs_arr[$key];
if ($arr[0] == "s") {
db_connect();
$get_sql = "\n\t\t\t\tSELECT invnum, invid, balance, terms, odate \n\t\t\t\tFROM invoices \n\t\t\t\tWHERE cusnum = '{$id}' AND printed = 'y' AND balance>0 AND div = '" . USER_DIV . "' AND invid = '{$arr['2']}' LIMIT 1";
$run_sql = db_exec($get_sql) or errDie("Unable to get stock invoice information.");
if (pg_numrows($run_sql) > 0) {
$inv = pg_fetch_array($run_sql);
$invid = $inv['invid'];
$val = allocamt($out, $inv["balance"]);
if ($val == 0.0) {
continue;
}
$inv['invnum'] += 0;
// reduce invoice balance
$sql = "\n\t\t\t\t\tUPDATE cubit.invoices \n\t\t\t\t\tSET balance = (balance - {$val}::numeric(13,2)) \n\t\t\t\t\tWHERE invid = '{$invid}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
$sql = "\n\t\t\t\t\tUPDATE cubit.open_stmnt \n\t\t\t\t\tSET balance = (balance - {$val}::numeric(13,2)) \n\t\t\t\t\tWHERE invid = '{$inv['invnum']}' AND div = '" . USER_DIV . "'";
$payRslt = db_exec($sql) or errDie("Unable to update Invoice information in Cubit.", SELF);
# record the payment on the statement
$sql = "\n\t\t\t\t\tINSERT INTO cubit.stmnt (\n\t\t\t\t\t\tcusnum, invid, amount, date, \n\t\t\t\t\t\ttype, div, allocation_date\n\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t'{$id}','{$inv['invnum']}', '" . ($val - $val * 2) . "', '{$accdate}', \n\t\t\t\t\t\t'Payment for Invoice No. {$inv['invnum']}', '" . USER_DIV . "', '{$inv['odate']}'\n\t\t\t\t\t)";
$stmntRslt = db_exec($sql) or errDie("Unable to insert statement record in Cubit.", SELF);
custledger($cus['cusnum'], $link['accnum'], $accdate, $inv['invnum'], "Payment for Invoice No. {$inv['invnum']}", $val, "c");
$rinvids .= "|{$invids[$key]}";
$amounts .= "|{$paidamt[$key]}";
if ($inv['prd'] == "0") {
$inv['prd'] = PRD_DB;
}
$invprds .= "|{$inv['prd']}";
$rages .= "|0";
$invidsers .= " - {$inv['invnum']}";
}
} elseif ($arr[0] == "n") {
db_connect();
$get_sql = "\n\t\t\t\tSELECT invnum, invid, balance, odate \n\t\t\t\tFROM nons_invoices \n\t\t\t\tWHERE cusid='{$id}' AND done='y' AND balance>0 AND div='" . USER_DIV . "' AND invid = '{$arr['2']}' LIMIT 1";
$run_sql = db_exec($get_sql) or errDie("Unable to get non stock information.");
if (pg_numrows($run_sql) > 0) {
$inv = pg_fetch_array($run_sql);
$invid = $inv['invid'];
$val = allocamt($out, $inv["balance"]);
//.........这里部分代码省略.........