Location: PHPKode > projects > NOLA > glpostadd.php
<? include('includes/main.php'); ?>
<script language="JavaScript">
     var calDateFormat='yyyy-MM-DD';
</script>
<script language="JavaScript" src="js/calendar.js"></script>
<?
     echo texttitle('GL Post');
     if ($postedyear) {
          if ($postap) $where.="gltransvoucher.wherefrom=1 or ";
          if ($postar) $where.="gltransvoucher.wherefrom=2 or ";
          if ($postgl) $where.="gltransvoucher.wherefrom=3 or ";
          if ($postin) $where.="gltransvoucher.wherefrom=4 or ";
          if ($postfa) $where.="gltransvoucher.wherefrom=5 or ";
          if ($postpr) $where.="gltransvoucher.wherefrom=6 or ";
          $where=substr($where,0,strlen($where)-4);
          $recordSet = &$conn->Execute("select sum(gltransaction.amount), gltransaction.voucherid, gltransvoucher.voucher from gltransaction inner join gltransvoucher on gltransaction.voucherid=gltransvoucher.id where (".$where.") and gltransvoucher.status='0' and gltransvoucher.cancel='0' and gltransvoucher.standardset='0' and substring(gltransvoucher.entrydate,1,10) >= ".sqlprep($begindate)." and substring(gltransvoucher.entrydate,1,10) <= ".sqlprep($enddate)." group by gltransaction.voucherid,gltransvoucher.voucher order by gltransaction.voucherid");
          if (!$recordSet||$recordSet->EOF) die(texterror('No vouchers match the specified criteria to post.'));
          while (!$recordSet->EOF) {
               if (checkzero($recordSet->fields[0])) { //transactions balanced to 0
                    if ($conn->Execute("update gltransvoucher set status='1', postuserid=".sqlprep($userid).", posteddate = NOW(), post2date='".$postedyear.'-'.$postedmonth."-01' where id=".sqlprep($recordSet->fields[1])) === false) {
                        echo texterror("Error posting voucher ".$recordSet->fields[2].".");
                    } else {
                        $vouchcount++;
                    };
               } else {
                    echo texterror("Voucher ".$recordSet->fields[2]." failed to balance (".CURRENCY_SYMBOL.checkdec($amount,PREFERRED_DECIMAL_PLACES).")");
               };
               $recordSet->MoveNext();
          };
          echo textsuccess($vouchcount." vouchers posted OK.");
     } 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"];
          if ($day<=5) { //set default dates to previous month
              $timestamp =  mktime($hour, $minute, $second, $month, 0, $year);
              $postyear=date("Y", $timestamp);
              $postmonth=date("m", $timestamp);
              $timestamp =  mktime($hour, $minute, $second, $month-1, 1, $year);
              $bgdate=date("Y-m-d", $timestamp);
              $timestamp =  mktime($hour, $minute, $second, $month, 0, $year);
              $eddate=date("Y-m-d", $timestamp);
          } else { //set dates to current month
              $timestamp =  mktime($hour, $minute, $second, $month, $day, $year);
              $postyear=date("Y", $timestamp);
              $postmonth=date("m", $timestamp);
              $timestamp =  mktime($hour, $minute, $second, $month, 1, $year);
              $bgdate=date("Y-m-d", $timestamp);
              $timestamp =  mktime($hour, $minute, $second, $month, $day, $year);
              $eddate=date("Y-m-d", $timestamp);
          };
          echo '<form action="glpostadd.php" method="post" name="mainform"><table><tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Year/Month Post Into:</td><td><input type="text" name="postedyear" value="'.$postyear.'" size="14" maxlength="4"'.INC_TEXTBOX.'><input type="text" name="postedmonth" value="'.$postmonth.'" size="14" maxlength="4"'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Begin Period:</td><td><input type="text" name="begindate" onchange="formatDate(this)" value="'.$bgdate.'" size="30"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="setDateField(document.mainform.begindate); 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="enddate" onchange="formatDate(this)" value="'.$eddate.'" size="30"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="setDateField(document.mainform.enddate); 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 '</td></tr></table><br><table border="1"><tr><th colspan="2">Post From:</th></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Accounts Payable:</td><td><input type="checkbox" name="postap" value="1" checked'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Accounts Receivable:</td><td><input type="checkbox" name="postar" value="1" checked'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">General Ledger:</td><td><input type="checkbox" name="postgl" value="1" checked'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Inventory:</td><td><input type="checkbox" name="postin" value="1" checked'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Fixed Assets:</td><td><input type="checkbox" name="postfa" value="1" checked'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Payroll:</td><td><input type="checkbox" name="postpr" value="1" checked'.INC_TEXTBOX.'></td></tr>';
          echo '</table><input type="submit" value="Post Now"></form>';
     };
?>
<? include('includes/footer.php'); ?>
Return current item: NOLA