$LineItem->SerialItems[$NewSerialNo] = new SerialItem($NewSerialNo, $NewQty);
             }
         } else {
             echo '<br />';
             prnMsg('<a href="' . $rootpath . '/StockSerialItemResearch.php?serialno=' . $NewSerialNo . '" target=_blank>' . $NewSerialNo . '</a> ' . _('not available') . '...', '', 'Notice');
         }
         if (!$valid) {
             $invalid_imports++;
         }
         // of MustExist
     } else {
         //Serialised items can not exist w/ Qty > 0 if we have an $NewQty of 1
         //Serialised items must exist w/ Qty = 1 if we have $NewQty of -1
         $SerialError = false;
         if ($LineItem->Serialised) {
             $ExistingQty = ValidBundleRef($StockID, $LocationOut, $NewSerialNo);
             if ($NewQty == 1 and $ExistingQty != 0) {
                 prnMsg('<a href="' . $rootpath . '/StockSerialItemResearch.php?serialno=' . $NewSerialNo . '" target=_blank>' . $NewSerialNo . '</a>: ' . _('The Serial Number being added exists with a Quantity that is not Zero (0)!'), 'error');
                 $SerialError = true;
             } elseif ($NewQty == -1 and $ExistingQty != 1) {
                 prnMsg('<a href="' . $rootpath . '/StockSerialItemResearch.php?serialno=' . $NewSerialNo . '" target=_blank>' . $NewSerialNo . '</a> : ' . _('The Serial Number being removed exists with a Quantity that is not One (1)!'), 'error');
                 $SerialError = true;
             }
         }
         if (!$SerialError) {
             $LineItem->SerialItems[$NewSerialNo] = new SerialItem($NewSerialNo, $NewQty);
         } else {
             $invalid_imports++;
         }
     }
 }
<?php

/* $Id: Add_SerialItemsOut.php 3242 2009-12-16 22:06:53Z tim_schofield $*/
/*ProcessSerialItems.php takes the posted variables and adds to the SerialItems array
 in either the cartclass->LineItems->SerialItems or the POClass->LineItems->SerialItems */
if (isset($_POST['AddBatches'])) {
    for ($i = 0; $i < 10; $i++) {
        if (strlen($_POST['SerialNo' . $i]) > 0) {
            $ExistingBundleQty = ValidBundleRef($StockID, $LocationOut, $_POST['SerialNo' . $i]);
            if ($ExistingBundleQty > 0) {
                $AddThisBundle = true;
                /*If the user enters a duplicate serial number the later one over-writes
                		the first entered one - no warning given though ? */
                if ($_POST['Qty' . $i] > $ExistingBundleQty) {
                    if ($LineItem->Serialised == 1) {
                        echo "<BR>" . $_POST['SerialNo' . $i] . " " . _('has already been sold');
                        $AddThisBundle = false;
                    } elseif ($ExistingBundleQty == 0) {
                        /* and its a batch */
                        echo "<BR>There is none of " . $_POST['SerialNo' . $i] . " left.";
                        $AddThisBundle = false;
                    } else {
                        echo '<BR>' . _('There is only') . ' ' . $ExistingBundleQty . ' ' . _('of') . ' ' . $_POST['SerialNo' . $i] . ' ' . _('remaining') . '. ' . _('The entered quantity will be reduced to the remaining amount left of this batch/bundle/roll');
                        $_POST['Qty' . $i] = $ExistingBundleQty;
                        $AddThisBundle = true;
                    }
                }
                if ($AddThisBundle == true) {
                    $LineItem->SerialItems[$_POST['SerialNo' . $i]] = new SerialItem($_POST['SerialNo' . $i], $_POST['Qty' . $i]);
                }
            }