Location: PHPKode > projects > NOLA > invpoupd.php
<? include('includes/main.php'); ?>
<? include('includes/apfunctions.php'); ?>
<? include('includes/invfunctions.php'); ?>
<script language="JavaScript">
     var calDateFormat='yyyy-MM-DD';
</script>
<script language="JavaScript" src="js/calendar.js"></script>
<script language="JavaScript">
     function checkprice(cost1,cost2,cost3,cost4,qty1,qty2,qty3) {
          document.mainform.itemprice.value=cost1;
          if  (document.mainform.itemqty.value>qty1&&cost2>0) {
               document.mainform.itemprice.value=cost2;
          }
          if (document.mainform.itemqty.value>qty2&&cost3>0) {
              document.mainform.itemprice.value=cost3;
          }
          if (document.mainform.itemqty.value>qty3&&cost4>0) {
              document.mainform.itemprice.value=cost4;
          }
     }
</script>
<? //invpoupd.php
     echo texttitle('Update Inventory PO');
     if ($invpoid&&$delete) { //delete po
               if ($conn->Execute('update invpo set cancel=1, canceldate=NOW(), canceluserid='.sqlprep($userid).' where id='.sqlprep($invpoid)) === false) {
                    die(texterror('Error deleting inventory PO'));
               } else {
                    echo textsuccess('Inventory PO updated successfully');
                    unset($invpoid);
               };
     };
     if ($first) { //test to see if our search only pulled back one po, and if so, go ahead and select it
          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);
          $recordSet = &$conn->Execute('select count(*) from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where invpo.complete=0 and inventorylocation.companyid=icompany.id 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 invpo.cancel=0 and vendor.orderfromcompanyid=vcompany.id'.$vendorstr.$ponumberstr.$requisitionstr.$ordernumberstr.$duedatestr.$locationidstr.$carrierstr);
          if (!$recordSet->EOF) if ($recordSet->fields[0]==1) {
               $recordSet = &$conn->Execute('select inventorylocation.id,vendor.id,carrierservice.id,invpo.id from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where invpo.complete=0 and inventorylocation.companyid=icompany.id 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 invpo.cancel=0 and vendor.orderfromcompanyid=vcompany.id'.$vendorstr.$ponumberstr.$requisitionstr.$ordernumberstr.$duedatestr.$locationidstr.$carrierstr.' order by invpo.duedate desc');
               if (!$recordSet->EOF) {
                    unset($submit);
               };
          };
     };
     if ($invpoid&&($submit=="Update PO"||$submit=="Update PO Details")) { //finish stuff
          checkpermissions('inv');
          if ($submit=="Update PO") {
               if ($conn->Execute('update invpo set vendorid='.sqlprep($vendorid).',ponumber='.sqlprep($ponumber).',duedate='.sqlprep($duedate).',locationid='.sqlprep($locationid).',carrierserviceid='.sqlprep($carrierserviceid).',tracknumber='.sqlprep($tracknumber).',contact='.sqlprep($contact).',requisition='.sqlprep($requisition).',ordernumber='.sqlprep($ordernumber).' where id='.sqlprep($invpoid)) === false) {
                    die(texterror('Error updating inventory PO'));
               } else {
                    echo textsuccess('General PO Info Updated successfully');
               };
          } elseif ($submit=="Update PO Details") {
               $conn->Execute('delete from invpodetail where invpoid='.sqlprep($invpoid));
               for ($i=1;${"itemqtyorder".$i};$i++) {
                    $recordSet = &$conn->Execute("select item.id from item where item.itemcode=".sqlprep(${"itemcode".$i}).' and item.companyid='.sqlprep($active_company));
                    if (!$recordSet->EOF) {
                         if ($conn->Execute('insert into invpodetail (invpoid,itemid,itemqty,itemprice) values ('.sqlprep($invpoid).', '.sqlprep($recordSet->fields[0]).', '.sqlprep(${"itemqtyorder".$i}).', '.sqlprep(${"itempriceach".$i}).')') === false) {
                              die(texterror('Error updating inventory PO details'));
                         } else {
                              echo textsuccess('PO Details Updated successfully');
                         };
                    };
               };
               echo '<br><a href="invpoview.php?printable=1&invpoid='.$invpoid.'">Print this PO</a>';
          };
          echo '<form action="invpoupd.php" method="post" name="mainform"><table border="1">';
          echo '<tr><th>Item Code</th><th>Quantity</th><th>Price/Unit</th></tr>';
          $i=1;
          $recordSet = &$conn->Execute('select invpodetail.itemqty, invpodetail.itemprice, item.itemcode, item.description, invpodetail.itemid from invpodetail,item where item.id=invpodetail.itemid and invpodetail.invpoid='.sqlprep($invpoid).' and item.companyid='.sqlprep($active_company).' order by invpodetail.id');
          while (!$recordSet->EOF) {
               echo '<tr><td><input type="text" name="itemcode'.$i.'" size="15" maxlength="20" value="'.$recordSet->fields[2].'"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="top.newWin = window.open(\'lookupitem.php?name=itemcode'.$i.'\',\'cal\',\'dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes\')"><img src="'.IMAGE_ITEM_LOOKUP.'" border="0" alt="Item Lookup"></a>'.$recordSet->fields[3];
               echo '</td><td><input type="text" name="itemqtyorder'.$i.'" onchange="validatenum(this)" size="10" maxlength="10" value="'.checkdec($recordSet->fields[0],0).'"'.INC_TEXTBOX.'></td><td><input type="text" name="itempriceach'.$i.'" onchange="validatenum(this)" size="10" maxlength="15" value="'.checkdec($recordSet->fields[1],PREFERRED_DECIMAL_PLACES).'"'.INC_TEXTBOX.'></td></tr>';
               $total+=$recordSet->fields[0]*$recordSet->fields[1];
               $i++;
               $recordSet->MoveNext();
          };
          echo '<tr><td><input type="text" name="itemcode'.$i.'" size="15" maxlength="20"'.INC_TEXTBOX.'><a href="javascript:doNothing()" onclick="top.newWin = window.open(\'lookupitem.php?name=itemcode'.$i.'\',\'cal\',\'dependent=yes,width=210,height=230,screenX=200,screenY=300,titlebar=yes\')"><img src="'.IMAGE_ITEM_LOOKUP.'" border="0" alt="Item Lookup"></a></td><td><input type="text" name="itemqtyorder'.$i.'" onchange="validatenum(this)" size="10" maxlength="10"'.INC_TEXTBOX.'></td><td><input type="text" name="itempriceach'.$i.'" onchange="validatenum(this)" size="10" maxlength="15"'.INC_TEXTBOX.'></td></tr>';
          echo '<tr><td colspan="2"><div align="right"><b>Total:</b></div></td><td>'.CURRENCY_SYMBOL.num_format($total,2).'</td></tr>';
          echo '</table><input type="hidden" name="invpoid" value="'.$invpoid.'"><input type="submit" name="submit" value="Update PO Details">';
     } elseif ($invpoid&&!$submit=="Update PO"&&!$submit=="Update PO Details") {
          $recordSet = &$conn->Execute('select invpo.id,invpo.ponumber,invpo.contact,vcompany.companyname,invpo.duedate,icompany.companyname,ccompany.companyname,carrierservice.description,invpo.requisition,invpo.ordernumber,invpo.tracknumber,invpo.vendorid from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where inventorylocation.companyid=icompany.id and invpo.cancel=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 and invpo.id='.sqlprep($invpoid).' order by invpo.duedate desc');
          if ($recordSet->EOF) die(texterror('No matching PO found.'));
          echo texttitle('Update General PO #'.$recordSet->fields[1].' Info');
          echo '<form action="invpoupd.php" method="post" name="mainform"><table>';
          echo '<input type="hidden" name="invpoid" value="'.$invpoid.'">';
          forminvpoupdate($recordSet->fields[11],$recordSet->fields[2],$recordSet->fields[9],$recordSet->fields[1],$recordSet->fields[4],$recordSet->fields[8],$recordSet->fields[5],$recordSet->fields[7],$recordSet->fields[10]);
          echo '</table><input type="submit" name="submit" value="Update PO"></form>';
          $recordSet = &$conn->Execute('select count(*) from invreceive where invpoid='.sqlprep($invpoid));
          if (!$recordSet->fields[0]) echo '<a href="javascript:confirmdelete(\'invpoupd.php?delete=1&invpoid='.$invpoid.'\')">Delete this PO</a>';
     } elseif ($first) {
          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);
          $recordSet = &$conn->Execute('select invpo.ponumber,vcompany.companyname,invpo.duedate,icompany.companyname,ccompany.companyname,carrierservice.description,invpo.requisition,invpo.ordernumber,invpo.id from invpo,vendor,company as vcompany,company as icompany,inventorylocation,company as ccompany,carrier,carrierservice where invpo.complete=0 and inventorylocation.companyid=icompany.id and invpo.locationid=inventorylocation.id and invpo.carrierserviceid=carrierservice.id and invpo.cancel=0 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.' order by invpo.duedate desc');
          if ($recordSet->EOF) die(texterror('No Entries Found.'));
          echo '<table border=1><tr><th>PO Number</th><th>Vendor Name</th><th>Due Date</th><th>Location</th><th>Carrier</th><th>Carrier Service</th><th>Requisition Number</th><th>Order Number</th></tr>';
          while (!$recordSet->EOF) {
               echo '<tr><td><a href="invpoupd.php?invpoid='.$recordSet->fields[8].'">'.$recordSet->fields[0].'</a></td><td>'.$recordSet->fields[1].'</td><td>'.$recordSet->fields[2].'</td><td>'.$recordSet->fields[3].'</td><td>'.$recordSet->fields[4].'</td><td>'.$recordSet->fields[5].'</td><td>'.$recordSet->fields[6].'</td><td>'.$recordSet->fields[7].'</td>';
               $recordSet->MoveNext();
          };
          echo '</table>';
     } else {
          echo '<form action="invpoupd.php" method="post" name="mainform"><table>';
          echo '<input type="hidden" name="first" value="1">';
          echo '<tr><td align="'.TABLE_LEFT_SIDE_ALIGN.'">PO #:</td><td><input type="text" name="ponumber" size="30" maxlength="20"'.INC_TEXTBOX.'></td></tr>';
          formapvendorselect('vendorid');
          $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>';
          };
          $recordSet = &$conn->Execute('select count(*) from inventorylocation,company where inventorylocation.companyid=company.id and inventorylocation.gencompanyid='.sqlprep($active_company));
          if (!$recordSet->EOF) 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>';
          };
          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">';
     };
?>
<? include('includes/footer.php'); ?>
Return current item: NOLA