Merge pull request #3 from altairis-noe/batch_mask_product

create custom masks in product cards
This commit is contained in:
Christophe Battarel 2021-04-13 09:41:13 +02:00 committed by GitHub
commit fe4552c3fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 7 deletions

View File

@ -27,4 +27,5 @@ StockDetailPerBatch=Stock detail per lot
SerialNumberAlreadyInUse=Serial number %s is already used for product %s SerialNumberAlreadyInUse=Serial number %s is already used for product %s
TooManyQtyForSerialNumber=You can only have one product %s for serial number %s TooManyQtyForSerialNumber=You can only have one product %s for serial number %s
BatchLotNumberingModules=Options for automatic generation of batch products managed by lots BatchLotNumberingModules=Options for automatic generation of batch products managed by lots
BatchSerialNumberingModules=Options for automatic generation of batch products managed by serial numbers BatchSerialNumberingModules=Options for automatic generation of batch products managed by serial numbers
ManageLotMask=Custom mask

View File

@ -27,4 +27,5 @@ StockDetailPerBatch=Stock détaillé par lot
SerialNumberAlreadyInUse=Le numéro de série %s est déjà utilisé pour le produit %s SerialNumberAlreadyInUse=Le numéro de série %s est déjà utilisé pour le produit %s
TooManyQtyForSerialNumber=Vous ne pouvez avoir qu'un produit %s avec le numéro de série %s TooManyQtyForSerialNumber=Vous ne pouvez avoir qu'un produit %s avec le numéro de série %s
BatchLotNumberingModules=Modèle de génération et contrôle des numéros de lot BatchLotNumberingModules=Modèle de génération et contrôle des numéros de lot
BatchSerialNumberingModules=Modèle de génération et contrôle des numéros de série BatchSerialNumberingModules=Modèle de génération et contrôle des numéros de série
ManageLotMask=Masque personnalisé

View File

@ -307,6 +307,10 @@ if (empty($reshook)) {
$object->status = GETPOST('statut'); $object->status = GETPOST('statut');
$object->status_buy = GETPOST('statut_buy'); $object->status_buy = GETPOST('statut_buy');
$object->status_batch = GETPOST('status_batch'); $object->status_batch = GETPOST('status_batch');
if ($object->status_batch !== 0) {
$object->batch_mask = GETPOST('batch_mask');
}
else $object->batch_mask = '';
$object->barcode_type = GETPOST('fk_barcode_type'); $object->barcode_type = GETPOST('fk_barcode_type');
$object->barcode = GETPOST('barcode'); $object->barcode = GETPOST('barcode');
@ -475,6 +479,10 @@ if (empty($reshook)) {
$object->status = GETPOST('statut', 'int'); $object->status = GETPOST('statut', 'int');
$object->status_buy = GETPOST('statut_buy', 'int'); $object->status_buy = GETPOST('statut_buy', 'int');
$object->status_batch = GETPOST('status_batch', 'aZ09'); $object->status_batch = GETPOST('status_batch', 'aZ09');
if ($object->status_batch !== 0) {
$object->batch_mask = GETPOST('batch_mask', 'alpha');
}
else $object->batch_mask = '';
$object->fk_default_warehouse = GETPOST('fk_default_warehouse'); $object->fk_default_warehouse = GETPOST('fk_default_warehouse');
// removed from update view so GETPOST always empty // removed from update view so GETPOST always empty
/* /*
@ -1083,10 +1091,48 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Batch number management // Batch number management
if (!empty($conf->productbatch->enabled)) { if (!empty($conf->productbatch->enabled)) {
print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
$statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial")); $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
print $form->selectarray('status_batch', $statutarray, GETPOST('status_batch')); print $form->selectarray('status_batch', $statutarray, GETPOST('status_batch'));
print '</td></tr>'; print '</td>';
// Product specific batch number management
$status_batch = GETPOST('status_batch');
if ($status_batch !== '0') {
$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
$tooltip .= $langs->trans("GenericMaskCodes2");
$tooltip .= $langs->trans("GenericMaskCodes3");
$tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
$tooltip .= $langs->trans("GenericMaskCodes5");
print '<td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
if (($conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced') || ($conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced')) {
$inherited_mask_lot = $conf->global->LOT_ADVANCED_MASK;
$inherited_mask_sn = $conf->global->SN_ADVANCED_MASK;
print '<td id="field_mask">';
print $form->textwithpicto('<input type="text" class="flat" size="24" name="batch_mask" id="batch_mask_input">', $tooltip, 1, 1);
print '</td>';
}
print '<script type="text/javascript">
$(document).ready(function() {
$("#field_mask, #mask_option").addClass("hideobject");
$("#status_batch").on("change", function () {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
$("#field_mask, #mask_option").addClass("hideobject");
if (this.value == 1) {
$("#field_mask, #mask_option").toggleClass("hideobject");
$("#batch_mask_input").val("'.$inherited_mask_lot.'");
}
if (this.value == 2) {
$("#field_mask, #mask_option").toggleClass("hideobject");
$("#batch_mask_input").val("'.$inherited_mask_sn.'");
}
})
})
</script>';
}
print '</tr>';
} }
$showbarcode = empty($conf->barcode->enabled) ? 0 : 1; $showbarcode = empty($conf->barcode->enabled) ? 0 : 1;
@ -1545,10 +1591,53 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
// Batch number managment // Batch number managment
if ($conf->productbatch->enabled) { if ($conf->productbatch->enabled) {
if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if ($object->isProduct() || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td>';
$statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial")); $statutarray = array('0' => $langs->trans("ProductStatusNotOnBatch"), '1' => $langs->trans("ProductStatusOnBatch"), '2' => $langs->trans("ProductStatusOnSerial"));
print $form->selectarray('status_batch', $statutarray, $object->status_batch); print $form->selectarray('status_batch', $statutarray, $object->status_batch);
print '</td></tr>'; print '</td>';
if ($object->status_batch !== '0') {
$tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
$tooltip .= $langs->trans("GenericMaskCodes2");
$tooltip .= $langs->trans("GenericMaskCodes3");
$tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Batch"), $langs->transnoentities("Batch"));
$tooltip .= $langs->trans("GenericMaskCodes5");
print '<td id="mask_option">'.$langs->trans("ManageLotMask").'</td>';
if ($object->status_batch == '1' && $conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced') {
$mask = !is_empty($object->batch_mask) ? $object->batch_mask : $conf->global->LOT_ADVANCED_MASK;
}
if ($object->status_batch == '2' && $conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced') {
$mask = !is_empty($object->batch_mask) ? $object->batch_mask : $conf->global->SN_ADVANCED_MASK;
}
$inherited_mask_lot = $conf->global->LOT_ADVANCED_MASK;
$inherited_mask_sn = $conf->global->SN_ADVANCED_MASK;
print '<td id="field_mask">';
print $form->textwithpicto('<input type="text" class="flat" size="24" name="batch_mask" id="batch_mask_input" value="'.$mask.'">', $tooltip, 1, 1);
print '</td>';
print '<script type="text/javascript">
$(document).ready(function() {
$("#field_mask, #mask_option").addClass("hideobject");
var preselect = $("#status_batch option:selected");
if (preselect !== "0") {
$("#field_mask, #mask_option").toggleClass("hideobject");
}
$("#status_batch").on("change", function () {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
$("#field_mask, #mask_option").addClass("hideobject");
if (this.value == 1) {
$("#field_mask, #mask_option").toggleClass("hideobject");
$("#batch_mask_input").val("'.$inherited_mask_lot.'");
}
if (this.value == 2) {
$("#field_mask, #mask_option").toggleClass("hideobject");
$("#batch_mask_input").val("'.$inherited_mask_sn.'");
}
})
})
</script>';
}
print '</tr>';
} }
} }
@ -2036,6 +2125,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) {
print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="2">'; print '<tr><td>'.$langs->trans("ManageLotSerial").'</td><td colspan="2">';
print $object->getLibStatut(0, 2); print $object->getLibStatut(0, 2);
print '</td></tr>'; print '</td></tr>';
if ((($object->status_batch == '1' && $conf->global->PRODUCTBATCH_LOT_USE_PRODUCT_MASKS && $conf->global->PRODUCTBATCH_LOT_ADDON == 'mod_lot_advanced')
|| ($object->status_batch == '2' && $conf->global->PRODUCTBATCH_SN_ADDON == 'mod_sn_advanced' && $conf->global->PRODUCTBATCH_SN_USE_PRODUCT_MASKS))) {
print '<tr><td>'.$langs->trans("ManageLotMask").'</td><td colspan="2">';
print $object->batch_mask;
print '</td></tr>';
}
} }
} }

View File

@ -264,6 +264,13 @@ class Product extends CommonObject
*/ */
public $status_batch = 0; public $status_batch = 0;
/**
* If allowed, we can edit batch or serial number mask for each product
*
* @var string
*/
public $batch_mask = '';
/** /**
* Customs code * Customs code
* *
@ -671,6 +678,7 @@ class Product extends CommonObject
$sql .= ", canvas"; $sql .= ", canvas";
$sql .= ", finished"; $sql .= ", finished";
$sql .= ", tobatch"; $sql .= ", tobatch";
$sql .= ", batch_mask";
$sql .= ", fk_unit"; $sql .= ", fk_unit";
$sql .= ") VALUES ("; $sql .= ") VALUES (";
$sql .= "'".$this->db->idate($now)."'"; $sql .= "'".$this->db->idate($now)."'";
@ -698,6 +706,7 @@ class Product extends CommonObject
$sql .= ", '".$this->db->escape($this->canvas)."'"; $sql .= ", '".$this->db->escape($this->canvas)."'";
$sql .= ", ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : (int) $this->finished); $sql .= ", ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? 'null' : (int) $this->finished);
$sql .= ", ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : $this->status_batch); $sql .= ", ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : $this->status_batch);
$sql .= ", '".$this->db->escape($this->batch_mask)."'";
$sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit); $sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit);
$sql .= ")"; $sql .= ")";
@ -1059,6 +1068,8 @@ class Product extends CommonObject
$sql .= ", tosell = ".(int) $this->status; $sql .= ", tosell = ".(int) $this->status;
$sql .= ", tobuy = ".(int) $this->status_buy; $sql .= ", tobuy = ".(int) $this->status_buy;
$sql .= ", tobatch = ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : (int) $this->status_batch); $sql .= ", tobatch = ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : (int) $this->status_batch);
$sql .= ", batch_mask = '".$this->db->escape($this->batch_mask)."'";
$sql .= ", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? "null" : (int) $this->finished); $sql .= ", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? "null" : (int) $this->finished);
$sql .= ", net_measure = ".($this->net_measure != '' ? "'".$this->db->escape($this->net_measure)."'" : 'null'); $sql .= ", net_measure = ".($this->net_measure != '' ? "'".$this->db->escape($this->net_measure)."'" : 'null');
$sql .= ", net_measure_units = ".($this->net_measure_units != '' ? "'".$this->db->escape($this->net_measure_units)."'" : 'null'); $sql .= ", net_measure_units = ".($this->net_measure_units != '' ? "'".$this->db->escape($this->net_measure_units)."'" : 'null');
@ -2170,7 +2181,7 @@ class Product extends CommonObject
} else { } else {
$sql .= " pa.accountancy_code_buy, pa.accountancy_code_buy_intra, pa.accountancy_code_buy_export, pa.accountancy_code_sell, pa.accountancy_code_sell_intra, pa.accountancy_code_sell_export,"; $sql .= " pa.accountancy_code_buy, pa.accountancy_code_buy_intra, pa.accountancy_code_buy_export, pa.accountancy_code_sell, pa.accountancy_code_sell_intra, pa.accountancy_code_sell_export,";
} }
$sql .= " p.stock,p.pmp, p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.fk_unit,"; $sql .= " p.stock,p.pmp, p.datec, p.tms, p.import_key, p.entity, p.desiredstock, p.tobatch, p.batch_mask, p.fk_unit,";
$sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf"; $sql .= " p.fk_price_expression, p.price_autogen, p.model_pdf";
$sql .= " FROM ".MAIN_DB_PREFIX."product as p"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
@ -2210,6 +2221,7 @@ class Product extends CommonObject
$this->status = $obj->tosell; $this->status = $obj->tosell;
$this->status_buy = $obj->tobuy; $this->status_buy = $obj->tobuy;
$this->status_batch = $obj->tobatch; $this->status_batch = $obj->tobatch;
$this->batch_mask = $obj->batch_mask;
$this->customcode = $obj->customcode; $this->customcode = $obj->customcode;
$this->country_id = $obj->fk_country; $this->country_id = $obj->fk_country;