Work on inventory
This commit is contained in:
parent
201c3f87ca
commit
1f02b33195
@ -285,18 +285,20 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd)
|
|||||||
// Define output language
|
// Define output language
|
||||||
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
|
||||||
{
|
{
|
||||||
$outputlangs = $langs;
|
if (method_exists($object, 'generateDocument')) {
|
||||||
$newlang = '';
|
$outputlangs = $langs;
|
||||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
|
$newlang = '';
|
||||||
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
|
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
|
||||||
if (!empty($newlang)) {
|
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
|
||||||
$outputlangs = new Translate("", $conf);
|
if (!empty($newlang)) {
|
||||||
$outputlangs->setDefaultLang($newlang);
|
$outputlangs = new Translate("", $conf);
|
||||||
}
|
$outputlangs->setDefaultLang($newlang);
|
||||||
$model = $object->modelpdf;
|
}
|
||||||
$ret = $object->fetch($id); // Reload to get new records
|
$model = $object->modelpdf;
|
||||||
|
$ret = $object->fetch($id); // Reload to get new records
|
||||||
|
|
||||||
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setEventMessages($object->error, $object->errors, 'errors');
|
setEventMessages($object->error, $object->errors, 'errors');
|
||||||
|
|||||||
@ -50,6 +50,16 @@ abstract class CommonObjectLine extends CommonObject
|
|||||||
public $fk_unit;
|
public $fk_unit;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param DoliDB $db Database handler
|
||||||
|
*/
|
||||||
|
public function __construct($db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the translation key from units dictionary.
|
* Returns the translation key from units dictionary.
|
||||||
* A langs->trans() must be called on result to get translated value.
|
* A langs->trans() must be called on result to get translated value.
|
||||||
|
|||||||
@ -688,6 +688,7 @@ Method=Method
|
|||||||
Receive=Receive
|
Receive=Receive
|
||||||
CompleteOrNoMoreReceptionExpected=Complete or nothing more expected
|
CompleteOrNoMoreReceptionExpected=Complete or nothing more expected
|
||||||
ExpectedValue=Expected Value
|
ExpectedValue=Expected Value
|
||||||
|
ExpectedQty=Expected Qty
|
||||||
PartialWoman=Partial
|
PartialWoman=Partial
|
||||||
TotalWoman=Total
|
TotalWoman=Total
|
||||||
NeverReceived=Never received
|
NeverReceived=Never received
|
||||||
|
|||||||
@ -237,3 +237,4 @@ AlwaysShowFullArbo=Display full tree of warehouse on popup of warehouse links (W
|
|||||||
StockAtDatePastDesc=You can view here the stock (real stock) at a given date in the past
|
StockAtDatePastDesc=You can view here the stock (real stock) at a given date in the past
|
||||||
StockAtDateFutureDesc=You can view here the stock (virtual stock) at a given date in future
|
StockAtDateFutureDesc=You can view here the stock (virtual stock) at a given date in future
|
||||||
CurrentStock=Current stock
|
CurrentStock=Current stock
|
||||||
|
InventoryRealQtyHelp=Set value to 0 to reset qty<br>Keep field empty, or remove line, to keep unchanged
|
||||||
@ -397,11 +397,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Modify
|
// Modify
|
||||||
if ($permissiontoadd)
|
if ($object->status == $object::STATUS_DRAFT)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
|
if ($permissiontoadd)
|
||||||
} else {
|
{
|
||||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Modify").'</a>'."\n";
|
||||||
|
} else {
|
||||||
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Modify').'</a>'."\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
@ -409,13 +412,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
{
|
{
|
||||||
if ($permissiontoadd)
|
if ($permissiontoadd)
|
||||||
{
|
{
|
||||||
if (empty($object->table_element_line) || (is_array($object->lines) && count($object->lines) > 0))
|
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>';
|
||||||
{
|
|
||||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes">'.$langs->trans("Validate").'</a>';
|
|
||||||
} else {
|
|
||||||
$langs->load("errors");
|
|
||||||
print '<a class="butActionRefused" href="" title="'.$langs->trans("ErrorAddAtLeastOneLineFirst").'">'.$langs->trans("Validate").'</a>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -228,7 +228,101 @@ class Inventory extends CommonObject
|
|||||||
*/
|
*/
|
||||||
public function create(User $user, $notrigger = false)
|
public function create(User $user, $notrigger = false)
|
||||||
{
|
{
|
||||||
return $this->createCommon($user, $notrigger);
|
$result = $this->createCommon($user, $notrigger);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate inventory (start it)
|
||||||
|
*
|
||||||
|
* @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 validate(User $user, $notrigger = false)
|
||||||
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
|
||||||
|
if ($result >= 0) {
|
||||||
|
// Scan existing stock to prefill the inventory
|
||||||
|
$sql = 'SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product, ps.reel,';
|
||||||
|
$sql .= ' pb.batch, pb.qty';
|
||||||
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'product_stock as ps';
|
||||||
|
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb ON pb.fk_product_stock = ps.rowid,';
|
||||||
|
$sql .= ' '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'entrepot as e';
|
||||||
|
$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
|
||||||
|
$sql .= ' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid';
|
||||||
|
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0";
|
||||||
|
if ($object->fk_product > 0) $sql .= ' AND ps.fk_product = '.$object->fk_product;
|
||||||
|
if ($object->fk_warehouse > 0) $sql .= ' AND ps.fk_entrepot = '.$object->fk_warehouse;
|
||||||
|
|
||||||
|
$inventoryline = new InventoryLine($this->db);
|
||||||
|
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if ($resql)
|
||||||
|
{
|
||||||
|
$num = $this->db->num_rows($resql);
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
while ($i < $num)
|
||||||
|
{
|
||||||
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
|
$inventoryline->fk_inventory = $this->id;
|
||||||
|
$inventoryline->fk_warehouse = $obj->fk_warehouse;
|
||||||
|
$inventoryline->fk_product = $obj->fk_product;
|
||||||
|
$inventoryline->batch = $obj->batch;
|
||||||
|
$inventoryline->qty_stock = ($obj->batch ? $obj->qty : $obj->reel); // If there is batch detail, we take qty for batch, else global qty
|
||||||
|
$inventoryline->datec = dol_now();
|
||||||
|
|
||||||
|
$resultline = $inventoryline->create($user);
|
||||||
|
if ($resultline <= 0) {
|
||||||
|
$this->error = $inventoryline->error;
|
||||||
|
$this->errors = $inventoryline->errors;
|
||||||
|
$result = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$result = -1;
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result >= 0) {
|
||||||
|
$result = $this->setStatut($this::STATUS_VALIDATED, null, '', 'INVENTORY_VALIDATED');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result > 0) {
|
||||||
|
$this->db->commit();
|
||||||
|
} else {
|
||||||
|
$this->db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go back to draft
|
||||||
|
*
|
||||||
|
* @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 setDraft(User $user, $notrigger = false)
|
||||||
|
{
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
$result = $this->setStatut($this::STATUS_DRAFT, null, '', 'INVENTORY_DRAFT');
|
||||||
|
|
||||||
|
if ($result > 0) {
|
||||||
|
$this->db->commit();
|
||||||
|
} else {
|
||||||
|
$this->db->rollback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -412,10 +506,13 @@ class Inventory extends CommonObject
|
|||||||
|
|
||||||
$labelStatus = array();
|
$labelStatus = array();
|
||||||
$labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
|
$labelStatus[self::STATUS_DRAFT] = $langs->trans('Draft');
|
||||||
$labelStatus[self::STATUS_VALIDATED] = $langs->trans('Enabled');
|
$labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated').' ('.$langs->trans('Started').')';
|
||||||
$labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled');
|
$labelStatus[self::STATUS_CANCELED] = $langs->trans('Canceled');
|
||||||
|
$labelStatusShort[self::STATUS_DRAFT] = $langs->trans('Draft');
|
||||||
|
$labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Started');
|
||||||
|
$labelStatusShort[self::STATUS_CANCELED] = $langs->trans('Canceled');
|
||||||
|
|
||||||
return dolGetStatus($labelStatus[$status], $labelStatus[$status], '', 'status'.$status, $mode);
|
return dolGetStatus($labelStatus[$status], $labelStatusShort[$status], '', 'status'.$status, $mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -506,7 +603,6 @@ class InventoryLine extends CommonObjectLine
|
|||||||
*/
|
*/
|
||||||
public $picto = 'stock';
|
public $picto = 'stock';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 'type' if the field format.
|
* 'type' if the field format.
|
||||||
* 'label' the translation key.
|
* 'label' the translation key.
|
||||||
@ -546,6 +642,28 @@ class InventoryLine extends CommonObjectLine
|
|||||||
*/
|
*/
|
||||||
public $rowid;
|
public $rowid;
|
||||||
|
|
||||||
|
public $fk_inventory;
|
||||||
|
public $fk_warehouse;
|
||||||
|
public $fk_product;
|
||||||
|
public $batch;
|
||||||
|
public $datec;
|
||||||
|
public $tms;
|
||||||
|
public $qty_stock;
|
||||||
|
public $qty_view;
|
||||||
|
public $qty_regulated;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create object in database
|
||||||
|
*
|
||||||
|
* @param User $user User that creates
|
||||||
|
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||||
|
* @return int <0 if KO, >0 if OK
|
||||||
|
*/
|
||||||
|
public function create(User $user, $notrigger = false)
|
||||||
|
{
|
||||||
|
return $this->createCommon($user, $notrigger);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load object in memory from the database
|
* Load object in memory from the database
|
||||||
|
|||||||
@ -250,7 +250,7 @@ if ($object->id > 0)
|
|||||||
|
|
||||||
|
|
||||||
// Buttons for actions
|
// Buttons for actions
|
||||||
if ($action == 'edit') {
|
if ($action == 'record') {
|
||||||
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
|
||||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||||
print '<input type="hidden" name="action" value="update">';
|
print '<input type="hidden" name="action" value="update">';
|
||||||
@ -276,19 +276,36 @@ if ($object->id > 0)
|
|||||||
{
|
{
|
||||||
if ($permissiontoadd)
|
if ($permissiontoadd)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit">'.$langs->trans("Edit").'</a>'."\n";
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=confirm_validate&confirm=yes">'.$langs->trans("Validate").' ('.$langs->trans("Start").')</a>'."\n";
|
||||||
} else {
|
} else {
|
||||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Edit').'</a>'."\n";
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Validate').' ('.$langs->trans("Start").')</a>'."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($object->status == Inventory::STATUS_DRAFT)
|
if ($object->status == Inventory::STATUS_VALIDATED)
|
||||||
|
{
|
||||||
|
if ($permissiontoadd)
|
||||||
|
{
|
||||||
|
if ($conf->barcode->enabled) {
|
||||||
|
print '<a href="#" class="butAction">'.$langs->trans("UpdateByScanningProductBarcode").'</a>';
|
||||||
|
}
|
||||||
|
if ($conf->productbatch->enabled) {
|
||||||
|
print '<a href="#" class="butAction">'.$langs->trans('UpdateByScaningLot').'</a>';
|
||||||
|
}
|
||||||
|
|
||||||
|
//print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=savecurrent">'.$langs->trans("Save").'</a>'."\n";
|
||||||
|
} else {
|
||||||
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Save').'</a>'."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($object->status == Inventory::STATUS_VALIDATED)
|
||||||
{
|
{
|
||||||
if ($permissiontoadd)
|
if ($permissiontoadd)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>'."\n";
|
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=record">'.$langs->trans("Finish").'</a>'."\n";
|
||||||
} else {
|
} else {
|
||||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Validate').'</a>'."\n";
|
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('Finish').'</a>'."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,24 +342,25 @@ if ($object->id > 0)
|
|||||||
print $langs->trans("Batch");
|
print $langs->trans("Batch");
|
||||||
print '</td>';
|
print '</td>';
|
||||||
}
|
}
|
||||||
print '<td class="right">'.$langs->trans("RecordedQty").'</td>';
|
print '<td class="right">'.$langs->trans("ExpectedQty").'</td>';
|
||||||
print '<td class="right">'.$langs->trans("RealQty").'</td>';
|
print '<td class="center">';
|
||||||
print '<td>';
|
print $form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp"));
|
||||||
|
print '</td>';
|
||||||
|
// Actions
|
||||||
|
print '<td class="center">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
|
// Request to show lines of inventory (prefilled during creation)
|
||||||
$sql = 'SELECT ps.rowid, ps.fk_entrepot as fk_warehouse, ps.fk_product';
|
$sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,';
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'product_stock as ps, '.MAIN_DB_PREFIX.'product as p, '.MAIN_DB_PREFIX.'entrepot as e';
|
$sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated';
|
||||||
$sql .= ' WHERE p.entity IN ('.getEntity('product').')';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id';
|
||||||
$sql .= ' AND ps.fk_product = p.rowid AND ps.fk_entrepot = e.rowid';
|
$sql .= ' WHERE id.fk_inventory = '.$object->id;
|
||||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql .= " AND p.fk_product_type = 0";
|
|
||||||
if ($object->fk_product > 0) $sql .= ' AND ps.fk_product = '.$object->fk_product;
|
|
||||||
if ($object->fk_warehouse > 0) $sql .= ' AND ps.fk_entrepot = '.$object->fk_warehouse;
|
|
||||||
|
|
||||||
$cacheOfProducts = array();
|
$cacheOfProducts = array();
|
||||||
$cacheOfWarehouses = array();
|
$cacheOfWarehouses = array();
|
||||||
|
|
||||||
|
//$sql = '';
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
@ -386,18 +404,18 @@ if ($object->id > 0)
|
|||||||
|
|
||||||
if ($conf->productbatch->enabled) {
|
if ($conf->productbatch->enabled) {
|
||||||
print '<td>';
|
print '<td>';
|
||||||
print '';
|
print $obj->batch;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<td>';
|
print '<td class="right">';
|
||||||
print '';
|
print 'TODO';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td>';
|
print '<td class="center">';
|
||||||
print '';
|
print '<input type="text" class="maxwidth75" name="id_'.$obj->rowid.' value="'.GETPOST("id_".$obj->rowid).'">';
|
||||||
print '</td>';
|
print '</td>';
|
||||||
print '<td>';
|
print '<td class="right">';
|
||||||
print '';
|
print img_delete();
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user