add setrecorded and commit to db
This commit is contained in:
parent
cdd777ecc8
commit
966d3a6f30
@ -243,3 +243,4 @@ UpdateByScaning=Update by scaning
|
|||||||
UpdateByScaningProductBarcode=Update by scan (product barcode)
|
UpdateByScaningProductBarcode=Update by scan (product barcode)
|
||||||
UpdateByScaningLot=Update by scan (lot|serial barcode)
|
UpdateByScaningLot=Update by scan (lot|serial barcode)
|
||||||
DisableStockChangeOfSubProduct=Deactivate the stock change for all the subproducts of this Kit during this movement.
|
DisableStockChangeOfSubProduct=Deactivate the stock change for all the subproducts of this Kit during this movement.
|
||||||
|
LabelOfInventoryMovemement=Inventory %s
|
||||||
@ -359,6 +359,27 @@ class Inventory extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to Recorded
|
||||||
|
*
|
||||||
|
* @param User $user User that creates
|
||||||
|
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||||
|
* @return int <0 if KO, Id of created object if OK
|
||||||
|
*/
|
||||||
|
public function setRecorded(User $user, $notrigger = false)
|
||||||
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
$result = $this->setStatut($this::STATUS_RECORDED, null, '', 'INVENTORY_RECORDED');
|
||||||
|
|
||||||
|
if ($result > 0) {
|
||||||
|
$this->db->commit();
|
||||||
|
} else {
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone and object into another one
|
* Clone and object into another one
|
||||||
*
|
*
|
||||||
|
|||||||
@ -27,6 +27,7 @@ include_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
|
|||||||
include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||||
include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
|
include_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php';
|
||||||
include_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php';
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
|
||||||
|
|
||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$langs->loadLangs(array("stocks", "other", "productbatch"));
|
$langs->loadLangs(array("stocks", "other", "productbatch"));
|
||||||
@ -98,6 +99,67 @@ $now = dol_now();
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if ($action == 'update' && $user->rights->stock->mouvement->creer) {
|
||||||
|
$stockmovment = new MouvementStock($db);
|
||||||
|
$stockmovment->origin = $object;
|
||||||
|
|
||||||
|
$sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
|
||||||
|
$sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
|
||||||
|
$sql .= ' WHERE id.fk_inventory = '.$object->id;
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql) {
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
$i = 0;
|
||||||
|
$totalarray = array();
|
||||||
|
while ($i < $num) {
|
||||||
|
$line = $db->fetch_object($resql);
|
||||||
|
$qty_view = $line->qty_view;
|
||||||
|
$qty_stock = $line->qty_stock;
|
||||||
|
$stock_movement_qty = $qty_view - $qty_stock;
|
||||||
|
if ($stock_movement_qty != 0) {
|
||||||
|
if ($stock_movement_qty < 0) {
|
||||||
|
$movement_type = 1;
|
||||||
|
} else {
|
||||||
|
$movement_type = 0;
|
||||||
|
}
|
||||||
|
$idstockmove = $stockmovment->_create($user, $line->fk_product, $line->fk_warehouse, $stock_movement_qty, $movement_type, 0, $langs->trans('LabelOfInventoryMovemement', $object->id), 'INV'.$object->id);
|
||||||
|
if ($idstockmove < 0) {
|
||||||
|
$error++;
|
||||||
|
setEventMessages($stockmovment->error, $stockmovment->errors, 'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
if (!$error) {
|
||||||
|
$object->setRecorded($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action =='updateinventorylines' && $permissiontoadd) {
|
||||||
|
$sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
|
||||||
|
$sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
|
||||||
|
$sql .= ' WHERE id.fk_inventory = '.$object->id;
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if ($resql) {
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
$i = 0;
|
||||||
|
$totalarray = array();
|
||||||
|
while ($i < $num) {
|
||||||
|
$line = $db->fetch_object($resql);
|
||||||
|
$lineid = $line->rowid;
|
||||||
|
$inventoryline = new InventoryLine($db);
|
||||||
|
$inventoryline->fetch($lineid);
|
||||||
|
$inventoryline->qty_view = GETPOST("id_".$inventoryline->id);
|
||||||
|
$inventoryline->update($user);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
|
||||||
if ($reshook < 0) {
|
if ($reshook < 0) {
|
||||||
@ -419,10 +481,12 @@ if ($object->id > 0) {
|
|||||||
print '<td class="center">';
|
print '<td class="center">';
|
||||||
print $form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp"));
|
print $form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp"));
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
if ($object->status == $object::STATUS_VALIDATED) {
|
||||||
// Actions
|
// Actions
|
||||||
print '<td class="center">';
|
print '<td class="center">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
}
|
||||||
|
|
||||||
// Line to add a new line in inventory
|
// Line to add a new line in inventory
|
||||||
if ($object->status == $object::STATUS_VALIDATED) {
|
if ($object->status == $object::STATUS_VALIDATED) {
|
||||||
@ -508,12 +572,17 @@ if ($object->id > 0) {
|
|||||||
print $obj->qty_stock;
|
print $obj->qty_stock;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="center">';
|
print '<td class="center">';
|
||||||
print '<input type="text" class="maxwidth75" name="id_'.$obj->rowid.'" value="'.GETPOST("id_".$obj->rowid).'">';
|
if ($object->status == $object::STATUS_VALIDATED) {
|
||||||
|
$qty_view = GETPOST("id_".$obj->rowid) ? GETPOST("id_".$obj->rowid) : $obj->qty_view;
|
||||||
|
print '<input type="text" class="maxwidth75" name="id_'.$obj->rowid.'" value="'.$qty_view.'">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td class="right">';
|
print '<td class="right">';
|
||||||
print '<a class="reposition" href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&lineid='.$obj->rowid.'&action=deleteline&token='.newToken().'">'.img_delete().'</a>';
|
print '<a class="reposition" href="'.DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id.'&lineid='.$obj->rowid.'&action=deleteline&token='.newToken().'">'.img_delete().'</a>';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
} else {
|
||||||
|
print $obj->qty_view;
|
||||||
|
print '</td>';
|
||||||
|
}
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user