Location: PHPKode > projects > NOLA > invpoadd.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>
<? //invpoadd.php  - copyright 2001 by Noguska - Fostoria, OH 44830
     echo texttitle('Add Inventory PO');
     if ($vendorid&&$locationid&&$ponumber&&($submit!="Complete PO"&&$submit!="Update PO")) { //if the user has submitted initial info
          $recordSet = &$conn->Execute('select vendor.id,company.companyname from vendor, company where vendor.id='.sqlprep($vendorid).' and vendor.gencompanyid='.sqlprep($active_company).' and vendor.orderfromcompanyid=company.id and vendor.cancel=0');
          if ($recordSet->EOF) die(texterror('Vendor not found.'));
          echo texttitle('<font size="-1">Vendor: '.$recordSet->fields[1].' - PO #'.$ponumber.'</font>');
          echo '<form action="invpoadd.php" method="post" name="mainform"><table border="1">';
          echo '<input type="hidden" name="vendorid" value="'.$vendorid.'">';
          echo '<input type="hidden" name="locationid" value="'.$locationid.'">';
          echo '<input type="hidden" name="duedate" value="'.$duedate.'">';
          echo '<input type="hidden" name="ponumber" value="'.$ponumber.'">';
          echo '<input type="hidden" name="carrierserviceid" value="'.$carrierserviceid.'">';
          echo '<input type="hidden" name="contact" value="'.$contact.'">';
          echo '<input type="hidden" name="requisition" value="'.$requisition.'">';
          echo '<input type="hidden" name="ordernumber" value="'.$ordernumber.'">';
          echo '<input type="hidden" name="tracknumber" value="'.$tracknumber.'">';
          for ($i=1; ${"itemcode".$i}; $i++) { //check fields that should be checked
               $recordSet = &$conn->Execute('select id,priceunitsperstockunit from item where itemcode='.sqlprep(${"itemcode".$i}));
               if (!$recordSet->EOF) {
                    ${"itemid".$i}=$recordSet->fields[0];
                    $ppsu=$recordSet->fields[1];
                    if ($ppsu<=0) $ppsu=1;
                    if (${"itemqtyorder".$i}=="") ${"itemqtyorder".$i}=1;
                    if (${"itempriceach".$i}=="") {
                         $recordSet1 = &$conn->Execute('select markupsetid from itemlocation where itemid='.sqlprep(${"itemid".$i}).' and inventorylocationid='.sqlprep($locationid));
                         if (!$recordSet1->EOF) ${"markupset".$i}=$recordSet1->fields[0];
                         ${"itempriceach".$i}=invitemprice(${"itemid".$i}, ${"markupset".$i}, $pricelevelid, ${"itemqtyorder".$i})*$ppsu;
                    };
               } else {
                    ${"itemqtyorder".$i}=0;
               };
          };
          echo '<tr><th>Item Code</th><th>Quantity</th><th>Price/Unit</th></tr>';
          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.'" size="10" maxlength="10"'.INC_TEXTBOX.'></td><td><input type="text" name="itempriceach'.$i.'" size="10" maxlength="15"'.INC_TEXTBOX.'></td></tr>';
          for ($i=1; ${"itemcode".$i}; $i++) { //pass prev submitted items to next form
               if ($i==1) echo '<tr><td colspan="3">&nbsp;</td></tr>';
               if (${"itemqtyorder".$i}) { //if quantity isn't 0
                    echo '<tr><td><input type="text" name="itemcode'.$i.'" size="15" maxlength="20" value="'.${"itemcode".$i}.'"'.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 = &$conn->Execute("select item.description from item where item.id=".sqlprep(${"itemid".$i}));
                    if (!$recordSet->EOF) echo ' '.$recordSet->fields[0];
                    echo '</td><td><input type="text" name="itemqtyorder'.$i.'" onchange="validatenum(this)" size="10" maxlength="10" value="'.${"itemqtyorder".$i}.'"'.INC_TEXTBOX.'></td><td><input type="text" name="itempriceach'.$i.'" onchange="validatenum(this)" size="10" maxlength="15" value="'.checkdec(${"itempriceach".$i},PREFERRED_DECIMAL_PLACES).'"'.INC_TEXTBOX.'></td></tr>';
                    $total+=${"itemqtyorder".$i}*${"itempriceach".$i};
               };
          };
          echo '<tr><td colspan="2"><div align="right"><b>Total:</b></div></td><td>'.CURRENCY_SYMBOL.checkdec($total,PREFERRED_DECIMAL_PLACES).'</td></tr>';
          echo '</table><input type="submit" name="submit" value="Add Line Item to PO">';
          for ($i=1; ${"itemid".$i}; $i++) {
               if (${"itemid".$i}&&${"itemqtyorder".$i}) $canclose=1;
          };
          if ($canclose) echo '<input type="submit" name="submit" value="Complete PO"></form>';
     } elseif ($vendorid&&$locationid&&$ponumber&&$submit=="Complete PO") { //finish stuff
          checkpermissions('inv');
          if ($conn->Execute('insert into invpo (vendorid,ponumber,duedate,locationid,carrierserviceid,tracknumber,contact,requisition,ordernumber,entrydate,entryuserid,lastchangeuserid,gencompanyid) values ('.sqlprep($vendorid).', '.sqlprep($ponumber).', '.sqlprep($duedate).', '.sqlprep($locationid).', '.sqlprep($carrierserviceid).', '.sqlprep($tracknumber).', '.sqlprep($contact).', '.sqlprep($requisition).', '.sqlprep($ordernumber).', NOW(), '.sqlprep($userid).', '.sqlprep($userid).', '.sqlprep($active_company).')') === false) {
               die(texterror('Error inserting inventory PO'));
          } else {
               $recordSet = &$conn->SelectLimit('select id from invpo where ponumber='.sqlprep($ponumber).' order by entrydate desc',1);
               if (!$recordSet->EOF) $invpoid=$recordSet->fields[0];
               for ($i=1; ${"itemcode".$i}; $i++) {
                    $recordSet2 = &$conn->Execute('select id from item where itemcode='.sqlprep(${"itemcode".$i}).' and item.companyid='.sqlprep($active_company));
                    if (!$recordSet2->EOF) ${"itemid".$i}=$recordSet2->fields[0];
                    if ($conn->Execute('insert into invpodetail (invpoid,itemid,itemqty,itemprice) values ('.sqlprep($invpoid).', '.sqlprep(${"itemid".$i}).', '.sqlprep(${"itemqtyorder".$i}).', '.sqlprep(${"itempriceach".$i}).')') === false) echo texterror('Error inserting INV PO Detail '.$i);
               };
               echo textsuccess('Inventory PO added successfully.');
               echo '<br><a href="invpoview.php?printable=1&invpoid='.$invpoid.'">Print this PO</a>';
          };
          echo texttitle('Update General PO Info');
          echo '<form action="invpoadd.php" method="post" name="mainform"><table>';
          echo '<input type="hidden" name="invpoid" value="'.$invpoid.'">';
          echo '<input type="hidden" name="vendorid" value="'.$vendorid.'">';
          echo '<input type="hidden" name="locationid" value="'.$locationid.'">';
          echo '<input type="hidden" name="duedate" value="'.$duedate.'">';
          echo '<input type="hidden" name="ponumber" value="'.$ponumber.'">';
          echo '<input type="hidden" name="carrierserviceid" value="'.$carrierserviceid.'">';
          echo '<input type="hidden" name="contact" value="'.$contact.'">';
          echo '<input type="hidden" name="requisition" value="'.$requisition.'">';
          echo '<input type="hidden" name="ordernumber" value="'.$ordernumber.'">';
          echo '<input type="hidden" name="tracknumber" value="'.$tracknumber.'">';
          forminvpoupdate($vendorid,$contact,$ordernumber,$ponumber,$duedate,$requisition,$locationid,$carrierserviceid,$tracknumber);
          echo '</table><input type="submit" name="submit" value="Update PO"></form>';
     } elseif ($vendorid&&$locationid&&$ponumber&&$submit=="Update PO") { //finish stuff
          checkpermissions('inv');
          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('PO Updated successfully');
               echo '<br><a href="invpoview.php?printable=1&invpoid='.$invpoid.'">Print this PO</a>';
          };
     } else { //display vendors, let user pick one
          echo '<form action="invpoadd.php" method="post" name="mainform"><table>';
          formapvendorselect('vendorid');
          forminvpoadd();
          echo '</table><input type="submit" value="Continue"></form>';
     };

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