Autoswitch on inventory tab on validation of inventory
Fix disabled button when some data are available.
This commit is contained in:
parent
9b9b63c794
commit
e652b93878
@ -140,6 +140,7 @@ if ($action == 'add' && !empty($permissiontoadd)) {
|
||||
header("Location: ".$urltogo);
|
||||
exit;
|
||||
} else {
|
||||
$error++;
|
||||
// Creation KO
|
||||
if (!empty($object->errors)) {
|
||||
setEventMessages(null, $object->errors, 'errors');
|
||||
@ -255,6 +256,7 @@ if ($action == 'update' && !empty($permissiontoadd)) {
|
||||
if ($result > 0) {
|
||||
$action = 'view';
|
||||
} else {
|
||||
$error++;
|
||||
// Creation KO
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = 'edit';
|
||||
@ -284,6 +286,7 @@ if ($action == "update_extras" && !empty($permissiontoadd)) {
|
||||
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
|
||||
$action = 'view';
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$action = 'edit_extras';
|
||||
}
|
||||
@ -301,9 +304,11 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
|
||||
if ($result > 0) {
|
||||
// Delete OK
|
||||
setEventMessages("RecordDeleted", null, 'mesgs');
|
||||
|
||||
header("Location: ".$backurlforlist);
|
||||
exit;
|
||||
} else {
|
||||
$error++;
|
||||
if (!empty($object->errors)) {
|
||||
setEventMessages(null, $object->errors, 'errors');
|
||||
} else {
|
||||
@ -347,6 +352,7 @@ if ($action == 'confirm_deleteline' && $confirm == 'yes' && !empty($permissionto
|
||||
header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
|
||||
exit;
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
$action = '';
|
||||
@ -383,6 +389,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $permissiontoadd) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
$action = '';
|
||||
@ -414,6 +421,7 @@ if ($action == 'confirm_close' && $confirm == 'yes' && $permissiontoadd) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
$action = '';
|
||||
@ -425,6 +433,7 @@ if ($action == 'confirm_setdraft' && $confirm == 'yes' && $permissiontoadd) {
|
||||
if ($result >= 0) {
|
||||
// Nothing else done
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
$action = '';
|
||||
@ -456,6 +465,7 @@ if ($action == 'confirm_reopen' && $confirm == 'yes' && $permissiontoadd) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
$action = '';
|
||||
@ -481,6 +491,7 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && !empty($permissiontoadd))
|
||||
header("Location: ".$_SERVER['PHP_SELF'].'?id='.$newid); // Open record of new object
|
||||
exit;
|
||||
} else {
|
||||
$error++;
|
||||
setEventMessages($objectutil->error, $objectutil->errors, 'errors');
|
||||
$action = '';
|
||||
}
|
||||
|
||||
@ -8730,7 +8730,11 @@ abstract class CommonObject
|
||||
$res = $this->db->query($sql);
|
||||
if ($res === false) {
|
||||
$error++;
|
||||
$this->errors[] = $this->db->lasterror();
|
||||
if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
||||
$this->errors[] = "ErrorRefAlreadyExists";
|
||||
} else {
|
||||
$this->errors[] = $this->db->lasterror();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -264,3 +264,5 @@ ProductBatchDoesNotExist=Product with batch/serial does not exist
|
||||
ProductBarcodeDoesNotExist=Product with barcode does not exist
|
||||
WarehouseId=Warehouse ID
|
||||
WarehouseRef=Warehouse Ref
|
||||
SaveQtyFirst=Save the real inventoried quantities first, before asking creation of the stock movement.
|
||||
InventoryStartedShort=Started
|
||||
@ -109,6 +109,7 @@ if ($reshook < 0) {
|
||||
}
|
||||
|
||||
if (empty($reshook)) {
|
||||
$savaction = $action;
|
||||
$error = 0;
|
||||
|
||||
$backurlforlist = DOL_URL_ROOT.'/product/inventory/list.php';
|
||||
@ -152,6 +153,12 @@ if (empty($reshook)) {
|
||||
$autocopy = 'MAIN_MAIL_AUTOCOPY_INVENTORY_TO';
|
||||
$trackid = 'stockinv'.$object->id;
|
||||
include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
|
||||
|
||||
if (!$error && $savaction == 'confirm_validate' && $action == '' && $object->id > 0) {
|
||||
// Switch to the tab inventory
|
||||
header("Location: ".DOL_URL_ROOT.'/product/inventory/inventory.php?id='.$object->id);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -59,10 +59,10 @@ class Inventory extends CommonObject
|
||||
*/
|
||||
public $picto = 'inventory';
|
||||
|
||||
const STATUS_DRAFT = 0;
|
||||
const STATUS_VALIDATED = 1;
|
||||
const STATUS_RECORDED = 2;
|
||||
const STATUS_CANCELED = 9;
|
||||
const STATUS_DRAFT = 0; // Draft
|
||||
const STATUS_VALIDATED = 1; // Inventory is in process
|
||||
const STATUS_RECORDED = 2; // Inventory is finisged. Stock movement has been recorded.
|
||||
const STATUS_CANCELED = 9; // Canceled
|
||||
|
||||
/**
|
||||
* 'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'sellist:TableName:LabelFieldName[:KeyFieldName[:KeyFieldParent[:Filter]]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
|
||||
@ -368,7 +368,7 @@ class Inventory extends CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to Recorded
|
||||
* Set to inventory to status "Closed". It means all stock movements were recorded.
|
||||
*
|
||||
* @param User $user User that creates
|
||||
* @param bool $notrigger false=launch triggers after, true=disable triggers
|
||||
@ -616,11 +616,11 @@ class Inventory extends CommonObject
|
||||
|
||||
$labelStatus = array();
|
||||
$labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
|
||||
$labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('Started').')';
|
||||
$labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated').' ('.$langs->transnoentitiesnoconv('InventoryStartedShort').')';
|
||||
$labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
|
||||
$labelStatus[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
|
||||
$labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
|
||||
$labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Started');
|
||||
$labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('InventoryStartedShort');
|
||||
$labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
|
||||
$labelStatusShort[self::STATUS_RECORDED] = $langs->transnoentitiesnoconv('Closed');
|
||||
|
||||
|
||||
@ -310,20 +310,22 @@ $help_url = '';
|
||||
llxHeader('', $langs->trans('Inventory'), $help_url);
|
||||
|
||||
|
||||
// Disable button Generate movement if data were not saved
|
||||
// Disable button Generate movement if data were modified and not saved
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
function disablebuttonmakemovementandclose() {
|
||||
console.log("Disable button idbuttonmakemovementandclose until we save");
|
||||
jQuery("#idbuttonmakemovementandclose").attr(\'disabled\',\'disabled\');
|
||||
jQuery("#idbuttonmakemovementandclose").attr(\'title\',\''.dol_escape_js($langs->trans("SaveQtyFirst")).'\');
|
||||
jQuery("#idbuttonmakemovementandclose").attr(\'class\',\'butActionRefused\');
|
||||
};
|
||||
|
||||
jQuery(document).ready(function() {
|
||||
|
||||
jQuery(".realqty").keyup(function() {
|
||||
console.log("keyup on realqty");
|
||||
disablebuttonmakemovementandclose();
|
||||
});
|
||||
jQuery(".realqty").change(function() {
|
||||
console.log("change on realqty");
|
||||
disablebuttonmakemovementandclose();
|
||||
});
|
||||
});
|
||||
@ -480,7 +482,7 @@ if ($object->id > 0) {
|
||||
// Save
|
||||
if ($object->status == $object::STATUS_VALIDATED) {
|
||||
if ($permissiontoadd) {
|
||||
print '<a class="butAction" id="idbuttonmakemovementandclose" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=record&token='.newToken().'" title="'.dol_escape_htmltag("SaveQtyFirst").'">'.$langs->trans("MakeMovementsAndClose").'</a>'."\n";
|
||||
print '<a class="butAction" id="idbuttonmakemovementandclose" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=record&token='.newToken().'" title="'.dol_escape_htmltag($langs->trans("MakeMovementsAndClose")).'">'.$langs->trans("MakeMovementsAndClose").'</a>'."\n";
|
||||
} else {
|
||||
print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans('MakeMovementsAndClose').'</a>'."\n";
|
||||
}
|
||||
@ -522,10 +524,9 @@ if ($object->id > 0) {
|
||||
var objecttofill = $("#"+object.id+"_input")[0];
|
||||
objecttofill.value = object.innerText;
|
||||
})
|
||||
console.log("Values filled");
|
||||
console.log("Disable button idbuttonmakemovementandclose until we save");
|
||||
jQuery("#idbuttonmakemovementandclose").attr(\'disabled\',\'disabled\');
|
||||
jQuery("#idbuttonmakemovementandclose").attr(\'class\',\'butActionRefused\');
|
||||
console.log("Values filled (after click on fillwithexpected)");
|
||||
disablebuttonmakemovementandclose();
|
||||
return false;
|
||||
});';
|
||||
print '});';
|
||||
print '</script>';
|
||||
@ -639,12 +640,14 @@ if ($object->id > 0) {
|
||||
//Call method to undo changes in real qty
|
||||
print '<script>';
|
||||
print 'jQuery(document).ready(function() {
|
||||
$(".undochangesqty").on("click",function undochangesqty(){
|
||||
$(".undochangesqty").on("click",function undochangesqty() {
|
||||
console.log("Clear value of inventory line");
|
||||
id = this.id;
|
||||
id = id.split("_")[1];
|
||||
tmpvalue = $("#id_"+id+"_input_tmp").val()
|
||||
$("#id_"+id+"_input")[0].value = tmpvalue;
|
||||
document.forms["formrecord"].submit();
|
||||
disablebuttonmakemovementandclose();
|
||||
return false; /* disable submit */
|
||||
});
|
||||
});';
|
||||
print '</script>';
|
||||
@ -667,7 +670,7 @@ if ($object->id > 0) {
|
||||
print '</td>';
|
||||
}
|
||||
print '<td class="right">'.$langs->trans("ExpectedQty").'</td>';
|
||||
print '<td class="center">';
|
||||
print '<td class="right">';
|
||||
print $form->textwithpicto($langs->trans("RealQty"), $langs->trans("InventoryRealQtyHelp"));
|
||||
print '</td>';
|
||||
if ($object->status == $object::STATUS_VALIDATED) {
|
||||
@ -692,7 +695,7 @@ if ($object->id > 0) {
|
||||
print '</td>';
|
||||
}
|
||||
print '<td class="right"></td>';
|
||||
print '<td class="center">';
|
||||
print '<td class="right">';
|
||||
print '<input type="text" name="qtytoadd" class="maxwidth75" value="">';
|
||||
print '</td>';
|
||||
// Actions
|
||||
@ -764,17 +767,22 @@ if ($object->id > 0) {
|
||||
print '</td>';
|
||||
|
||||
// Real quantity
|
||||
print '<td class="center">';
|
||||
print '<td class="right">';
|
||||
if ($object->status == $object::STATUS_VALIDATED) {
|
||||
$qty_view = GETPOST("id_".$obj->rowid) && price2num(GETPOST("id_".$obj->rowid), 'MS') >= 0 ? GETPOST("id_".$obj->rowid) : $obj->qty_view;
|
||||
if (!$hasinput && $qty_view !== null && $obj->qty_stock != $qty_view) {
|
||||
|
||||
//if (!$hasinput && $qty_view !== null && $obj->qty_stock != $qty_view) {
|
||||
if ($qty_view != '') {
|
||||
$hasinput = true;
|
||||
}
|
||||
|
||||
print '<a id="undochangesqty_'.$obj->rowid.'" href="#" class="undochangesqty reposition marginrightonly" title="'.dol_escape_htmltag($langs->trans("Clear")).'">';
|
||||
print img_picto('', 'eraser', 'class="opacitymedium"');
|
||||
print '</a>';
|
||||
print '<input type="text" class="maxwidth75 right realqty" name="id_'.$obj->rowid.'" id="id_'.$obj->rowid.'_input" value="'.$qty_view.'">';
|
||||
print '</td>';
|
||||
|
||||
print '<td class="right">';
|
||||
print '<a id="undochangesqty_'.$obj->rowid.'" href="#" class="undochangesqty"><span class="fas fa-undo pictoundo" ></span></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>';
|
||||
$qty_tmp = price2num(GETPOST("id_".$obj->rowid."_input_tmp", 'MS')) >= 0 ? GETPOST("id_".$obj->rowid."_input_tmp") : $qty_view;
|
||||
@ -801,10 +809,13 @@ if ($object->id > 0) {
|
||||
|
||||
print '</div>';
|
||||
|
||||
|
||||
// Call method to disable the button if no qty entered yet for inventory
|
||||
|
||||
if ($object->status != $object::STATUS_VALIDATED || !$hasinput) {
|
||||
print '<script type="text/javascript" language="javascript">
|
||||
jQuery(document).ready(function() {
|
||||
console.log("Call disablebuttonmakemovementandclose because status = '.((int) $object->status).' or $hasinput = '.((int) $hasinput).'");
|
||||
disablebuttonmakemovementandclose();
|
||||
});
|
||||
</script>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user