function write($_POST) { $Out = ""; #get & send vars foreach ($_POST as $key => $value) { ${$key} = $value; $Out .= "<input type=hidden name=\${$key} value='{$value}'>"; } $blength = strlen($barcodes); $start = 0; while ($start < $blength) { $value = substr($barcodes, $start, $clength); $start = $start + $clength; if (strlen($value) == $clength) { $bars[] = $value; } } # validate input require_lib("validate"); $v = new validate(); foreach ($bars as $each) { $v->isOk($each, "num", 1, $clength, "Invalid bar code."); } # display errors, if any if ($v->isError()) { $errors = ""; $Errors = $v->getErrors(); foreach ($Errors as $e) { $errors .= "<li class=err>" . $e["msg"] . "</li>"; } $errors .= "<input type=hidden name=errors value='{$errors}'>"; return read_bars($_POST, $errors); } #we can only add as many barcodes as there is stock, so find the max and reduce the array if it exceeds the max pglib_transaction("begin"); $Sl = "SELECT stkcod,stkdes,units,alloc FROM stock WHERE stkid='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to view stock"); if (pg_numrows($Rs) < 1) { return "Invalid Stock id."; } $St = pg_fetch_array($Rs); $Av = $St['units'] - $St['alloc']; $i = 0; $Sl = "SELECT code FROM ss0 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss1 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss2 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss3 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss4 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss5 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss6 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss7 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss8 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } $Sl = "SELECT code FROM ss9 WHERE stock='{$id}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to retrieve barcodes from db"); while ($Tp = pg_fetch_array($Rs)) { $i++; } pglib_transaction("commit"); $Wob = $Av - $i; if ($Wob > 0) { #doesnt exceed, do nothing foreach ($bars as $each) { $bars2[] = $each; } } else { $bars2 = array(); for ($count = 0; $count <= $Wob; $count++) { $bars2[] = $bars[$count]; } } db_conn("cubit"); foreach ($bars2 as $each) { switch (substr($each, strlen($each) - 1, 1)) { case "0": $tab = "ss0"; break; case "1": $tab = "ss1"; break; case "2": $tab = "ss2"; break; case "3": $tab = "ss3"; break; case "4": $tab = "ss4"; break; case "5": $tab = "ss5"; break; case "6": $tab = "ss6"; break; case "7": $tab = "ss7"; break; case "8": $tab = "ss8"; break; case "9": $tab = "ss9"; break; default: return order($_POST, "The code you selected is invalid"); } if (barext_ex($tab, 'code', $each) or strlen($each) == 0) { return read_bars($_POST, "<li class='err'>The code you selected already exits in the system.</li>"); } else { $getcheck = "SELECT * FROM " . $tab . " WHERE code = '{$me}' AND active = 'no'"; $runcheck = db_exec($getcheck) or errDie("Unable to get serial number check"); if (pg_numrows($runcheck) < 1) { $Sl = "INSERT INTO " . $tab . " (code,stock,div) VALUES ('{$each}','{$id}','" . USER_DIV . "')"; $Rs = db_exec($Sl) or errDie("Unable to update database.", SELF); } else { $arr = pg_fetch_array($runcheck); $Sl = "UPDATE " . $tab . " SET active = 'yes' WHERE code = '{$arr['code']}' AND stock = '{$arr['stock']}' AND div = '{$arr['div']}'"; $Rs = db_exec($Sl) or errDie("Unable to update database.", SELF); } } } #print and reload parent window return "All Possible RFID Barcodes Have Been Imported<br><br\n\t\t<input type='button' onClick='javascript:window.close();' value='Close'>\n\t\t<script>\n\t\t\topener.document.formName.submit()\n\t\t</script>"; }
function write($_POST) { $Out = ""; #get & send vars foreach ($_POST as $key => $value) { ${$key} = $value; $Out .= "<input type=hidden name=\${$key} value='{$value}'>"; } $blength = strlen($barcodes); $start = 0; while ($start < $blength) { $value = substr($barcodes, $start, $clength); $start = $start + $clength; if (strlen($value) == $clength) { $bars[] = $value; } } # validate input require_lib("validate"); $v = new validate(); foreach ($bars as $each) { $v->isOk($each, "num", 1, $clength, "Invalid bar code."); } # display errors, if any if ($v->isError()) { $errors = ""; $Errors = $v->getErrors(); foreach ($Errors as $e) { $errors .= "<li class=err>" . $e["msg"] . "</li>"; } $errors .= "<input type=hidden name=errors value='{$errors}'>"; return read_bars($_POST, $errors); } #we can only add as many barcodes as there is stock, so find the max and reduce the array if it exceeds the max // pglib_transaction("begin"); // // $Sl = "SELECT stkcod,stkdes,units,alloc FROM stock WHERE stkid='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to view stock"); // if(pg_numrows($Rs)<1) {return "Invalid Stock id.";} // $St = pg_fetch_array($Rs); // $Av=$St['units']-$St['alloc']; // // $i=0; // // $Sl = "SELECT code FROM ss0 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss1 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss2 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss3 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss4 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss5 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss6 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss7 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss8 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // $Sl = "SELECT code FROM ss9 WHERE stock='$id' AND div = '".USER_DIV."'"; // $Rs = db_exec ($Sl) or errDie ("Unable to retrieve barcodes from db"); // while($Tp = pg_fetch_array($Rs)){$i++;} // // pglib_transaction("commit"); // // $Wob=$Av-$i; // if ($Wob>0){ // #doesnt exceed, do nothing // foreach($bars as $each){ // $bars2[] = $each; // } // }else { // $bars2 = array (); // for($count = 0; $count <= $Wob; $count++){ // $bars2[] = $bars[$count]; // } // } db_conn("cubit"); foreach ($bars as $each) { $Sl = "SELECT * FROM possets WHERE div = '" . USER_DIV . "'"; $Rs = db_exec($Sl) or errDie("Unable to add supplier to the system.", SELF); if (pg_numrows($Rs) < 1) { return read_bars($_POST, "<li class='err'>Please go set the point of sale settings under the stock settings</li>"); } $Dets = pg_fetch_array($Rs); if ($Dets['opt'] == "No") { switch (substr($each, strlen($each) - 1, 1)) { case "0": $tab = "ss0"; break; case "1": $tab = "ss1"; break; case "2": $tab = "ss2"; break; case "3": $tab = "ss3"; break; case "4": $tab = "ss4"; break; case "5": $tab = "ss5"; break; case "6": $tab = "ss6"; break; case "7": $tab = "ss7"; break; case "8": $tab = "ss8"; break; case "9": $tab = "ss9"; break; default: return read_bars($_POST, "<li class='err'>The code you selected is invalid.</li>"); } db_conn('cubit'); pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); $stid = barext_dbget($tab, 'code', $each, 'stock'); if (!($stid > 0)) { return read_bars($_POST, "<li class='err'>The bar code you selected is not in the system or is not available.</li>"); } $Sl = "SELECT * FROM stock WHERE stkid = '{$stid}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl); $s = pg_fetch_array($Rs); # put scanned-in product into invoice db $sql = "INSERT INTO pinv_items(invid, whid, stkid, qty, unitcost, amt, disc, discp, ss, vatcode, div) VALUES('{$invid}', '{$s['whid']}', '{$stid}', '1','{$s['selamt']}','{$s['selamt']}','0','0','{$each}', '{$s['vatcode']}', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); # update stock(alloc + qty) $sql = "UPDATE stock SET alloc = (alloc + '1') WHERE stkid = '{$stid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF); $Sl = "UPDATE " . $tab . " SET active = 'no' WHERE code = '{$each}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl); pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); } else { db_conn('cubit'); pglib_transaction("BEGIN") or errDie("Unable to start a database transaction.", SELF); $stid = ext_dbget('stock', 'bar', $each, 'stkid'); if (!($stid > 0)) { return read_bars($_POST, "<li class='err'>The bar code you selected is not in the system or is not available.</li>"); } $Sl = "SELECT * FROM stock WHERE stkid = '{$stid}' AND div = '" . USER_DIV . "'"; $Rs = db_exec($Sl); $s = pg_fetch_array($Rs); # put scanned-in product into invoice db $sql = "INSERT INTO pinv_items(invid, whid, stkid, qty, unitcost, amt, disc, discp, ss, vatcode, div) VALUES('{$invid}', '{$s['whid']}', '{$stid}', '1','{$s['selamt']}','{$s['selamt']}','0','0','{$each}', '{$s['vatcode']}', '" . USER_DIV . "')"; $rslt = db_exec($sql) or errDie("Unable to insert invoice items to Cubit.", SELF); # update stock(alloc + qty) $sql = "UPDATE stock SET alloc = (alloc + '1') WHERE stkid = '{$stid}' AND div = '" . USER_DIV . "'"; $rslt = db_exec($sql) or errDie("Unable to update stock to Cubit.", SELF); pglib_transaction("COMMIT") or errDie("Unable to commit a database transaction.", SELF); } } #print and reload parent window //opener.document.form.submit() return "\n\t\t<script>\n\t\t\twindow.close();\n\t\t\topener.document.location='pos-invoice-new.php?invid={$invid}&cont=yes'\n\t\t</script>"; }