Location: PHPKode > projects > NOLA > invporecv.php
<? include('includes/main.php'); ?>
<? include('includes/apfunctions.php'); ?>
<script language="JavaScript">
     var calDateFormat='yyyy-MM-DD';
</script>
<script language="JavaScript" src="js/calendar.js"></script>
<? //invpolist.php
     echo texttitle('Inventory PO Receive');
     if ($submit) {
          if ($vendorid) $vendorstr=' and vendor.id='.sqlprep($vendorid);
          if ($ponumber) $ponumberstr=' and invpo.ponumber='.sqlprep($ponumber);
          if ($requisition) $requisitionstr=' and invpo.requisition='.sqlprep($requisition);
          if ($duedate) $duedatestr=' and invpo.duedate='.sqlprep($duedate);
          if ($ordernumber) $ordernumberstr=' and invpo.ordernumber='.sqlprep($ordernumber);
          if ($locationid) $locationidstr=' and inventorylocation.id='.sqlprep($locationid);
          if ($carrierserviceid) $carrierstr=' and carrierservice.id='.sqlprep($carrierserviceid);
          if ($invpoid) $invpostr=' and invpo.id='.sqlprep($invpoid);
          $recordSet = &$conn->Execute('select count(*) from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where inventorylocation.companyid=icompany.id and invpo.complete=0 and invpo.locationid=inventorylocation.id and invpo.carrierserviceid=carrierservice.id and carrier.id=carrierservice.carrierid and ccompany.id=carrier.companyid and invpo.vendorid=vendor.id and vendor.orderfromcompanyid=vcompany.id'.$vendorstr.$ponumberstr.$requisitionstr.$ordernumberstr.$duedatestr.$locationidstr.$carrierstr.$invpostr);
          if ($recordSet->fields[0]>1) {
               $recordSet = &$conn->Execute('select invpo.ponumber,vcompany.companyname,invpo.duedate,icompany.companyname,ccompany.companyname,carrierservice.description,invpo.requisition,invpo.ordernumber,invpo.id,invpo.complete from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where inventorylocation.companyid=icompany.id and invpo.locationid=inventorylocation.id and invpo.complete=0 and invpo.carrierserviceid=carrierservice.id and carrier.id=carrierservice.carrierid and ccompany.id=carrier.companyid and invpo.vendorid=vendor.id and vendor.orderfromcompanyid=vcompany.id'.$vendorstr.$ponumberstr.$requisitionstr.$ordernumberstr.$duedatestr.$locationidstr.$carrierstr.$invpostr.' and vendor.gencompanyid='.sqlprep($active_company).' order by invpo.duedate desc');
               if ($recordSet->EOF) die(texterror('No matching PO\'s found.'));
               echo '<table border="1"><tr><th>PO Number</th><th>Vendor Name</th><th>Due Date</th><th>Location</th><th>Shipping Method</th><th>Requisition Number</th><th>Order Number</th></tr>';
               while (!$recordSet->EOF) {
                    if (!$recordSet->fields[9]) $link = '<a href="invporecv.php?submit=1&invpoid='.$recordSet->fields[8].'">';
                    echo '<tr><td>'.$link.$recordSet->fields[0].'</a></td><td>'.$recordSet->fields[1].'</td><td><nobr>'.$recordSet->fields[2].'</nobr></td><td>'.$recordSet->fields[3].'</td><td>'.$recordSet->fields[4].' - '.$recordSet->fields[5].'</td><td>'.$recordSet->fields[6].'</td><td>'.$recordSet->fields[7].'</td></tr>';
                    $recordSet->MoveNext();
                    unset($link);
               };
               echo '</table>';
          } elseif ($recordSet->fields[0]==1) {
               if ($submit!="Receive PO") {
                    $recordSet = &$conn->Execute('select invpo.ponumber,vcompany.companyname,invpo.duedate,icompany.companyname,ccompany.companyname,carrierservice.description,invpo.requisition,invpo.ordernumber,invpo.id,invpo.vendorid,invpo.tracknumber,invpo.locationid from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where inventorylocation.companyid=icompany.id and invpo.complete=0 and invpo.locationid=inventorylocation.id and invpo.carrierserviceid=carrierservice.id and carrier.id=carrierservice.carrierid and ccompany.id=carrier.companyid and invpo.vendorid=vendor.id and vendor.orderfromcompanyid=vcompany.id'.$vendorstr.$ponumberstr.$requisitionstr.$ordernumberstr.$duedatestr.$locationidstr.$carrierstr.$invpostr.' and vendor.gencompanyid='.sqlprep($active_company).' order by invpo.duedate desc');
                    if ($recordSet->EOF) die(texterror('No matching PO\'s found.')); //shouldnt ever happen, as the if parent statement checks for this
                    $invpoid=$recordSet->fields[8];
                    $track=$recordSet->fields[10];
                    echo '<form action="invporecv.php" method="post" name="mainform">';
                    echo '<input type="hidden" name="invpoid" value="'.$recordSet->fields[8].'">';
                    echo '<input type="hidden" name="vendorid" value="'.$recordSet->fields[9].'">';
                    echo '<input type="hidden" name="locationid" value="'.$recordSet->fields[11].'">';
                    echo '<table border="1"><tr><th>PO Number</th><th>Vendor Name</th><th>Due Date</th><th>Location</th><th>Shipping Method</th><th>Requisition Number</th><th>Order Number</th></tr>';
                    echo '<tr><td>'.$recordSet->fields[0].'</td><td>'.$recordSet->fields[1].'</td><td><nobr>'.$recordSet->fields[2].'</nobr></td><td>'.$recordSet->fields[3].'</td><td>'.$recordSet->fields[4].' - '.$recordSet->fields[5].'</td><td>'.$recordSet->fields[6].'</td><td>'.$recordSet->fields[7].'</td></tr>';
                    echo '</table>';
                    $recordSet = &$conn->Execute('select invpodetail.id, item.itemcode, item.description, itemvendor.vordernumber, invpodetail.itemqty, invpodetail.itemprice, item.id from item cross join invpodetail left join itemvendor on itemvendor.itemid=item.id and itemvendor.vendorid='.sqlprep($recordSet->fields[9]).' where invpodetail.itemid=item.id and item.companyid='.sqlprep($active_company).' and invpodetail.invpoid='.sqlprep($recordSet->fields[8]));
                    echo '<table border="1"><tr><th>Item Code</th><th>Item Description</th><th>Vendor<br>Item Code</th><th><font size="-1">Quantity<br>Ordered</font></th><th><font size="-1">Quantity<br>Previously<br>Received</font></th><th><font size="-1">Quantity<br>Received</font></th><th>Price</th></tr>';
                    while (!$recordSet->EOF) {
                         $quantity=$recordSet->fields[4];
                         $recordSet2 = &$conn->Execute('select sum(invreceive.itemqty) from invreceive where invreceive.invpoid='.sqlprep($invpoid).' and invreceive.itemid='.sqlprep($recordSet->fields[6]));
                         if (!$recordSet2->EOF&&$recordSet2->fields[0]) $quantity=$quantity-$recordSet2->fields[0];
                         echo '<input type="hidden" name="itemid'.$recordSet->fields[0].'" value='.$recordSet->fields[6].'>';
                         echo '<tr><td>'.$recordSet->fields[1].'</td><td>'.$recordSet->fields[2].'</td><td>'.$recordSet->fields[3].'</td><td align="right">'.checkdec($recordSet->fields[4],PREFERRED_DECIMAL_PLACES).'</td><td align="right">'.checkdec($recordSet2->fields[0],PREFERRED_DECIMAL_PLACES).'</td><td align="right"><input type="text" name="quantity'.$recordSet->fields[0].'" value="'.checkdec($quantity,0).'" size="10" maxlength="10"'.INC_TEXTBOX.'></td><td align="right"><input type="text" name="price'.$recordSet->fields[0].'" value="'.checkdec($recordSet->fields[5],PREFERRED_DECIMAL_PLACES).'" size="10" maxlength="15"'.INC_TEXTBOX.'></td></tr>';
                         $recordSet->MoveNext();
                    };
                    echo '</table>';
                    echo 'Tracking #:&nbsp;&nbsp;<input type="text" name="track" value="'.$track.'"'.INC_TEXTBOX.'><br>';
                    echo 'PO Complete:&nbsp;&nbsp;<input type="checkbox" name="complete" value="1" checked'.INC_TEXTBOX.'><br>';
                    echo '<input type="submit" name="submit" value="Receive PO"></form>';
               } else { //code to mark po as received, and do other stuff
                    $recordSet = &$conn->Execute('select invpodetail.id from invpodetail where invpodetail.invpoid='.sqlprep($invpoid));
                    while (!$recordSet->EOF) {
                         //update receive file
                         if (${"quantity".$recordSet->fields[0]}) {
                             if ($conn->Execute('insert into invreceive (recsource,invpoid,receivedate,itemid,vendorid,locationid,itemqty,itemprice,track,receiveunitnameid,entrydate,entryuserid,lastchangeuserid,gencompanyid) values (1,'.sqlprep($invpoid).', NOW(), '.sqlprep(${"itemid".$recordSet->fields[0]}).', '.sqlprep($vendorid).', '.sqlprep($locationid).', '.sqlprep(${"quantity".$recordSet->fields[0]}).', '.sqlprep(${"price".$recordSet->fields[0]}).', '.sqlprep($track).', 1, NOW(), '.sqlprep($userid).', '.sqlprep($userid).', '.sqlprep($active_company).')') === false) echo die(texterror('Error Updating PO'));
                             if ($conn->Execute('update itemlocation set onhandqty=onhandqty+'.${"quantity".$recordSet->fields[0]}.' where itemid='.sqlprep(${"itemid".$recordSet->fields[0]}).' and inventorylocationid='.sqlprep($locationid)) === false) echo texterror('Error Updating On-hand Quantity');
                         };
                         $recordSet->MoveNext();
                    };
                    if ($complete) if ($conn->Execute("update invpo set complete='1' where id=".sqlprep($invpoid)) === false) echo die(texterror('Error Updating PO'));
                    echo textsuccess('PO received successfully.');
               };
          } else {
               echo texterror('No matching PO\'s found.');
          };
     } else {
          echo '<form action="invporecv.php" method="post" name="mainform"><table>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">PO #:</td><td><input type="text" name="ponumber" size="30" maxlength="20"'.INC_TEXTBOX.'></td></tr>';
          $recordSet = &$conn->Execute('select count(*) from vendor, company where vendor.gencompanyid='.sqlprep($active_company).' and vendor.orderfromcompanyid=company.id and vendor.cancel=0');
          if (!$recordSet->EOF) {
                //echo 'Vendor Count='.$recordSet->fields[0];
                if ($recordSet->fields[0]>1) {
                     formapvendorselect('vendorid');
                } else if ($recordSet->fields[0]>0) {
                  $recordSet = &$conn->Execute('select vendor.id from vendor, company where vendor.gencompanyid='.sqlprep($active_company).' and vendor.orderfromcompanyid=company.id and vendor.cancel=0 order by company.companyname');
                  if (!$recordSet->EOF) {
                        $vendorid=$recordSet->fields[0];
                        $recordSet->MoveNext() ;
                  };
                  echo '<input type="hidden" name="vendorid" value="'.$vendorid.'">';
                } else {
                  die (texterror('No Vendors in File'));
                };
          } else {
                  die (texterror('No Vendors in File'));
          };
          $recordSet = &$conn->Execute('select count(*) from carrierservice,carrier,company where carrierservice.carrierid=carrier.id and carrier.companyid=company.id and company.cancel=0');
          if (!$recordSet->EOF) {
            if ($recordSet->fields[0]>1) {
               echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Carrier Service:</td><td><select name="carrierserviceid"'.INC_TEXTBOX.'><option value="0">';
               $recordSet = &$conn->Execute('select carrierservice.id,company.companyname,carrierservice.description from carrierservice,carrier,company where carrierservice.carrierid=carrier.id and carrier.companyid=company.id and company.cancel=0 order by company.companyname,carrierservice.description');
               while (!$recordSet->EOF) {
                    echo '<option value="'.$recordSet->fields[0].'">'.$recordSet->fields[1].' - '.$recordSet->fields[2]."\n";
                    $recordSet->MoveNext();
               };
               echo '</select></td></tr>';
            } elseif ($recordSet->fields[0]>0) {
               $recordSet = &$conn->Execute('select carrierservice.id,company.companyname,carrierservice.description from carrierservice,carrier,company where carrierservice.carrierid=carrier.id and carrier.companyid=company.id and company.cancel=0 order by company.companyname,carrierservice.description');
                  if (!$recordSet->EOF) {
                        $carrierserviceid=$recordSet->fields[0];
                        $recordSet->MoveNext();
                  };
                  echo '<input type="hidden" name="carrierserviceid" value="'.$carrierserviceid.'">';
            }
          };
          $recordSet = &$conn->Execute('select count(*) from inventorylocation,company where inventorylocation.companyid=company.id and inventorylocation.gencompanyid='.sqlprep($active_company));
          if (!$recordSet->EOF) {
            //echo 'location count='.$recordSet->fields[0];
            if ($recordSet->fields[0]>1) {
               echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Location:</td><td><select name="locationid"'.INC_TEXTBOX.'><option value="0">';
               $recordSet = &$conn->Execute('select inventorylocation.id,company.companyname from inventorylocation,company where inventorylocation.companyid=company.id and inventorylocation.gencompanyid='.sqlprep($active_company).' order by company.companyname');
               while (!$recordSet->EOF) {
                    echo '<option value="'.$recordSet->fields[0].'">'.$recordSet->fields[1]."\n";
                    $recordSet->MoveNext();
               };
               echo '</select></td></tr>';
            } elseif ($recordSet->fields[0]>0) {
                  $recordSet = &$conn->Execute('select inventorylocation.id,company.companyname from inventorylocation,company where inventorylocation.companyid=company.id and inventorylocation.gencompanyid='.sqlprep($active_company).' order by company.companyname');
                  if (!$recordSet->EOF) {
                        $locationid=$recordSet->fields[0];
                        $recordSet->MoveNext();
                  };
                  echo '<input type="hidden" name="locationid" value="'.$locationid.'">';
            } else {
                  die (texterror('No Locations in File'));
            };
          } else {
             die (texterror("No Locations in File"));
          };

          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Due Date:</td><td><input type="text" name="duedate" onchange="formatDate(this)" size="30" maxlength="20"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="setDateField(document.mainform.duedate); 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.'">Requisition #:</td><td><input type="text" name="requisition" size="30" maxlength="20"'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">Vendor Order #:</td><td><input type="text" name="ordernumber" size="30" maxlength="20"'.INC_TEXTBOX.'></td></tr>';
          echo '</table><input type="submit" name="submit" value="Show List"></form>';
     };

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