Example #1
0
             $batch = $pdluo->batch;
             $eatby = $pdluo->eatby;
             $sellby = $pdluo->sellby;
         } else {
             setEventMessages($pdluo->error, $pdluo->errors, 'errors');
             $error++;
         }
     } else {
         $srcwarehouseid = GETPOST('id_entrepot_source', 'int');
         $batch = GETPOST('batch_number');
         $eatby = $d_eatby;
         $sellby = $d_sellby;
     }
     if (!$error) {
         // Remove stock
         $result1 = $product->correct_stock_batch($user, $srcwarehouseid, GETPOST("nbpiece", 'int'), 1, GETPOST("label", 'san_alpha'), $pricesrc, $eatby, $sellby, $batch, GETPOST('inventorycode'));
         // Add stock
         $result2 = $product->correct_stock_batch($user, GETPOST("id_entrepot_destination", 'int'), GETPOST("nbpiece", 'int'), 0, GETPOST("label", 'san_alpha'), $pricedest, $eatby, $sellby, $batch, GETPOST('inventorycode'));
     }
 } else {
     // Remove stock
     $result1 = $product->correct_stock($user, GETPOST("id_entrepot_source"), GETPOST("nbpiece"), 1, GETPOST("label"), $pricesrc, GETPOST('inventorycode'));
     // Add stock
     $result2 = $product->correct_stock($user, GETPOST("id_entrepot_destination"), GETPOST("nbpiece"), 0, GETPOST("label"), $pricedest, GETPOST('inventorycode'));
 }
 if (!$error && $result1 >= 0 && $result2 >= 0) {
     $db->commit();
     if ($backtopage) {
         header("Location: " . $backtopage);
         exit;
     } else {
            setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("atleast1batchfield")), 'errors');
            $error++;
            $action = 'correction';
        }
    }
    if (!$error) {
        $priceunit = price2num(GETPOST("price"));
        if (is_numeric(GETPOST("nbpiece")) && $id) {
            if (empty($product)) {
                $product = new Product($db);
                $result = $product->fetch($id);
            }
            if ($product->hasbatch()) {
                $d_eatby = dol_mktime(12, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']);
                $d_sellby = dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']);
                $result = $product->correct_stock_batch($user, GETPOST("id_entrepot"), GETPOST("nbpiece"), GETPOST("mouvement"), GETPOST("label"), $priceunit, $d_eatby, $d_sellby, GETPOST('batch_number'));
                // We do not change value of stock for a correction
            } else {
                $result = $product->correct_stock($user, GETPOST("id_entrepot"), GETPOST("nbpiece"), GETPOST("mouvement"), GETPOST("label"), $priceunit);
                // We do not change value of stock for a correction
            }
            if ($result > 0) {
                header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $product->id);
                exit;
            }
        }
    }
}
// Transfer stock from a warehouse to another warehouse
if ($action == "transfert_stock" && !$cancel) {
    if (!(GETPOST("id_entrepot_source") > 0) || !(GETPOST("id_entrepot_destination") > 0)) {
 $product->load_stock();
 // Load array product->stock_warehouse
 // Define value of products moved
 $pricesrc = 0;
 if (isset($product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp)) {
     $pricesrc = $product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp;
 }
 $pricedest = $pricesrc;
 //print 'price src='.$pricesrc.', price dest='.$pricedest;exit;
 $pdluoid = GETPOST('pdluoid', 'int');
 if ($pdluoid > 0) {
     $pdluo = new Productbatch($db);
     $result = $pdluo->fetch($pdluoid);
     if ($result > 0 && $pdluo->id) {
         // Remove stock
         $result1 = $product->correct_stock_batch($user, $pdluo->warehouseid, GETPOST("nbpiece", 'int'), 1, GETPOST("label", 'san_alpha'), $pricesrc, $pdluo->eatby, $pdluo->sellby, $pdluo->batch);
         // Add stock
         $result2 = $product->correct_stock_batch($user, GETPOST("id_entrepot_destination", 'int'), GETPOST("nbpiece", 'int'), 0, GETPOST("label", 'san_alpha'), $pricedest, $pdluo->eatby, $pdluo->sellby, $pdluo->batch);
     }
 } else {
     // Remove stock
     $result1 = $product->correct_stock($user, GETPOST("id_entrepot_source"), GETPOST("nbpiece"), 1, GETPOST("label"), $pricesrc);
     // Add stock
     $result2 = $product->correct_stock($user, GETPOST("id_entrepot_destination"), GETPOST("nbpiece"), 0, GETPOST("label"), $pricedest);
 }
 if ($result1 >= 0 && $result2 >= 0) {
     $db->commit();
     header("Location: product.php?id=" . $product->id);
     exit;
 } else {
     setEventMessage($product->error, 'errors');
Example #4
0
 if (empty($product_id)) {
     $error++;
     setEventMessage($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")), 'errors');
     $action = 'correction';
 }
 if (!is_numeric($_POST["nbpiece"])) {
     $error++;
     setEventMessage($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentitiesnoconv("NumberOfUnit")), 'errors');
     $action = 'correction';
 }
 if (!$error) {
     if ($product->hasbatch()) {
         $batch = GETPOST('batch_number');
         $eatby = GETPOST('eatby');
         $sellby = GETPOST('sellby');
         $result = $product->correct_stock_batch($user, $id, GETPOST("nbpiece", 'int'), GETPOST("mouvement"), GETPOST("label", 'san_alpha'), GETPOST('unitprice'), $eatby, $sellby, $batch, GETPOST('inventorycode'));
         // We do not change value of stock for a correction
     } else {
         $result = $product->correct_stock($user, $id, GETPOST("nbpiece", 'int'), GETPOST("mouvement"), GETPOST("label", 'san_alpha'), GETPOST('unitprice'), GETPOST('inventorycode'));
         // We do not change value of stock for a correction
     }
     if ($result > 0) {
         header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
         exit;
     } else {
         $error++;
         setEventMessages($product->error, $product->errors, 'errors');
         $action = 'correction';
     }
 }
 if (!$error) {
             $error++;
             setEventMessage($product->errors, 'errors');
         }
     } else {
         $arraybatchinfo = $product->loadBatchInfo($batch);
         if (count($arraybatchinfo) > 0) {
             $firstrecord = array_shift($arraybatchinfo);
             $dlc = $firstrecord['eatby'];
             $dluo = $firstrecord['sellby'];
             //var_dump($batch); var_dump($arraybatchinfo); var_dump($firstrecord); var_dump($dlc); var_dump($dluo); exit;
         } else {
             $dlc = '';
             $dluo = '';
         }
         // Remove stock
         $result1 = $product->correct_stock_batch($user, $id_sw, $qty, 1, GETPOST("label"), $pricesrc, $dlc, $dluo, $batch, GETPOST("codemove"));
         if ($result1 < 0) {
             $error++;
             setEventMessage($product->errors, 'errors');
         }
         // Add stock
         $result2 = $product->correct_stock_batch($user, $id_tw, $qty, 0, GETPOST("label"), $pricedest, $dlc, $dluo, $batch, GETPOST("codemove"));
         if ($result2 < 0) {
             $error++;
             setEventMessage($product->errors, 'errors');
         }
     }
 } else {
     dol_print_error('', "Bad value saved into sessions");
     $error++;
 }