Location: PHPKode > projects > NOLA > arorderckout.php
<? include('includes/main.php'); ?>
<? include('includes/invfunctions.php'); ?>
<? //arorderckout.php - April 2001 copyright by Noguska, Fostoria, OH 44830
   // For user to check out order after it is received (so who has it at
   //     any time can be tracked.

     echo texttitle('Order Checkout/Checkin');
     if ($savedata) {
       //insert into file
           $today=createtime("Y-m-d h:m");
           checkpermissions('ar');
           if ($conn->Execute('insert into arordertrack (orderid,action,trackdate,trackuserid,lastchangeuserid) values ('.sqlprep($orderid).', '.sqlprep($action).', NOW(), '.sqlprep($cuser).', '.sqlprep($userid).')') === false) {
                    echo texterror("Error adding check out/in info.");
           } else {
                    echo textsuccess('Order successfully checked in or out.');
           };
           unset($ordernumber);
     };
     if ($savedata||(!$gordernumber&&!$gponumber&&!$gcustomerid)) {
          echo '<form action="arorderckout.php" method="post" name="mainform"><table>';
          if ($usersupervisor) { //only let user pick user to checkout if they are a supervisor
              echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Operator:</td><td><select name="cuser"'.INC_TEXTBOX.'>';
              $recordSet = &$conn->Execute('select id, name from genuser order by name');
              while (!$recordSet->EOF) {
                   echo '<option value="'.$recordSet->fields[0].'"'.checkequal($recordSet->fields[0],$userid," selected").'>'.$recordSet->fields[1]."\n";
                   $recordSet->MoveNext();
              };
              echo '</select></td></tr>';
          } else {
              echo '<input type="hidden" name="cuser" value="'.$userid.'">';
          };
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Order #:</td><td><input type="text" name="gordernumber" value="'.$gordernumber.'" onchange="validateint(this)" size="30"'.INC_TEXTBOX.'>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Purchase Order:</td><td><input type="text" name="gponumber" value="'.$gponumber.'" size="30"'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Customer #:</td><td><input type="text" name="gcustomerid" value="'.$gcustomerid.'" onchange="validateint(this)" size="30"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="top.newWin = window.open(\'lookupcustomer.php?name=gcustomerid\',\'cal\',\'dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes\')"><img src="'.IMAGE_CUSTOMER_LOOKUP.'" border="0" alt="Customer Lookup"></a></td></tr>';
          unset($savedata);
          echo '</table><input type="submit" value="Search"></form>';
     } else {
       if ($gcustomerid||$gponumber||$gordernumber) { //if the user has submitted initial info
          if ($ordernumber) {
             $orderstr=' and arorder.ordernumber='.sqlprep($ordernumber);
          } else {
             if ($gordernumber) $orderstr=' and arorder.ordernumber='.sqlprep($gordernumber);
             if ($gponumber) $ponumberstr=' and arorder.ponumber='.sqlprep($gponumber);
             if ($gcustomerid) $customeridstr=' and customer.id='.sqlprep($gcustomerid);
          };
          $recordSet = &$conn->Execute("select count(distinct arorder.id) from arorder,customer, company as ordercompany, company as shiptocompany where (customer.companyid=ordercompany.id or customer.companyid=shiptocompany.id) and ordercompany.id=arorder.orderbycompanyid and shiptocompany.id=arorder.shiptocompanyid".$orderstr.$ponumberstr.$customeridstr." and arorder.status=0 and arorder.companyid=".sqlprep($active_company));
          if (!$recordSet->EOF) if ($recordSet->fields[0]>1) { //if there is more than one order matching criteria
               echo '<table border="1"><tr><th>Order #</th><th>     Last Action     </th><th>PO Number</th><th>Order Company</th><th>Ship To Company</th></tr>';
               $recordSet = &$conn->Execute("select arorder.ordernumber, arorder.ponumber, arorder.orderbycompanyid, ordercompany.companyname, arorder.shiptocompanyid, shiptocompany.companyname,arorder.id from arorder,customer, company as ordercompany, company as shiptocompany where (customer.companyid=ordercompany.id or customer.companyid=shiptocompany.id) and ordercompany.id=arorder.orderbycompanyid and shiptocompany.id=arorder.shiptocompanyid".$orderstr.$ponumberstr.$customeridstr." and arorder.companyid=".sqlprep($active_company)." order by arorder.entrydate desc");
               while (!$recordSet->EOF) {
                    $recordSet2=&$conn->Execute('select arordertrack.action,arordertrack.trackdate,genuser.name from arordertrack,genuser where genuser.id=arordertrack.trackuserid and arordertrack.trackuserid='.sqlprep($cuser).' and (arordertrack.action=0 or arordertrack.action=10) and arordertrack.orderid='.sqlprep($recordSet->fields[6]).' order by arordertrack.trackdate desc' );
                    echo '<tr><td><center><a href="arorderckout.php?ordernumber='.$recordSet->fields[0].'&&gordernumber='.$gorgernumber.'&&gponumber='.$gponumber.'&&gcustomerid='.$gcustomerid.'&&cuser='.$cuser.'">'.$recordSet->fields[0].'</a></center></td>';
                    if (!$recordSet2->EOF) {
                        if ($recordSet2->fields[0]==10) {
                              $action='<font color="red">'.$recordSet2->fields[2]." Returned-".$recordSet2->fields[1];
                        } else {
                               $action='<font color="green">'.$recordSet2->fields[2]." Checked Out-".$recordSet2->fields[1];
                        };
                        echo '<td><center>'.$action.'</center></td>';
                    } else {
                        echo '<td><center>------</center></td>';
                    };
                    echo '<td>'.$recordSet->fields[1].'</td><td>'.$recordSet->fields[3].'</td><td>'.$recordSet->fields[5].'<td>';
                    echo '</tr>';
                    $recordSet->MoveNext();
               };
               echo '</table>';
          } else {
               $recordSet = &$conn->Execute("select arorder.ordernumber, arorder.ponumber, arorder.orderbycompanyid, ordercompany.companyname, arorder.shiptocompanyid, shiptocompany.companyname, arorder.id from arorder,customer, company as ordercompany, company as shiptocompany where (customer.companyid=ordercompany.id or customer.companyid=shiptocompany.id) and ordercompany.id=arorder.orderbycompanyid and shiptocompany.id=arorder.shiptocompanyid".$orderstr.$ponumberstr.$customeridstr." and arorder.status=0 and arorder.companyid=".sqlprep($active_company)." order by arorder.entrydate desc");
               if (!$recordSet->EOF) {
                    echo '<form action="arorderckout.php" method="post" name="mainform"><table border="1">';
                    echo '<tr><th colspan="2">Check Out/In Order Number: '.$recordSet->fields[0].'<br> for '.rtrim($recordSet->fields[3]).'</th></tr>';
                    echo '<input type="hidden" name="ordernumber" value="'.$recordSet->fields[0].'">';
                    echo '<input type="hidden" name="orderid" value="'.$recordSet->fields[6].'">';
                    echo '<input type="hidden" name="cuser" value="'.$cuser.'">';
                    echo '<input type="hidden" name="gponumber" value="'.$gponumber.'">';
                    echo '<input type="hidden" name="gcustomerid" value="'.$gcustomerid.'">';
                    echo '<input type="hidden" name="gordernumber" value="'.$gordernumber.'">';
                    $recordSet2=&$conn->Execute('select action from arordertrack where trackuserid='.sqlprep($cuser).' and (action=0 or action=10) and orderid='.sqlprep($recordSet->fields[6]).' order by trackdate desc' );
                    if (!$recordSet2->EOF) {
                        $checked=$recordSet2->fields[0];
                    } else {
                        $checked=10;
                    };
                    if ($checked==10) {
                         echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Check Out Order</td><td><input type="radio" checked name="action" value="0"></td></tr>';
                         echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Return from Checkout</td><td><input type="radio" name="action" value="10"></td></tr>';
                    } else {
                         echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Check Out Order</td><td><input type="radio" name="action" value="0"></td></tr>';
                         echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Return from Checkout</td><td><input type="radio" checked name="action" value="10"></td></tr>';
                    };
                    echo '</td></tr></table>';
                    echo '</table>';
                    if (!$recordSet->fields[21]) echo '<input type="submit" name="savedata" value="Save">';
               } else {
                    die(texterror('No matching orders found.'));
               };
          };

       };
     };

?>
<? include('includes/footer.php'); ?>
Return current item: NOLA