Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW shipment kits with dispatcher v2 #716

Open
wants to merge 12 commits into
base: 2024_rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions htdocs/admin/expedition.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,19 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="set_param">';

print "<table class=\"noborder\" width=\"100%\">";
print "<tr class=\"liste_titre\">";
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print "<td>".$langs->trans("Parameter")."</td>\n";
print "<td></td>\n";
print "</tr>";

print '<tr class="oddeven">';
print '<td>'.$langs->trans('SHIPPING_SELL_EAT_BY_DATE_PRE_SELECT_EARLIEST');
print '</td>';
print '<td>';
print ajax_constantonoff('SHIPPING_SELL_EAT_BY_DATE_PRE_SELECT_EARLIEST');
print '</td></tr>';

$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
Expand All @@ -438,7 +446,7 @@
}
$htmltext .= '</i>';

print '<tr><td>';
print '<tr><td colspan="2">';
print $form->textwithpicto($langs->trans("FreeLegalTextOnShippings"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
$variablename = 'SHIPPING_FREE_TEXT';
if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) {
Expand All @@ -451,7 +459,8 @@
print "</td></tr>\n";

print '<tr><td>';
print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
print $form->textwithpicto($langs->trans("WatermarkOnDraftContractCards"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip');
print '</td><td>';
print '<input class="flat minwidth200" type="text" name="SHIPPING_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('SHIPPING_DRAFT_WATERMARK')).'">';
print "</td></tr>\n";

Expand Down
51 changes: 39 additions & 12 deletions htdocs/admin/stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,19 @@
$formproduct = new FormProduct($db);



$disabled = '';
$disableStockCalculateOn = array();
if (getDolGlobalInt('PRODUIT_SOUSPRODUITS')) {
$langs->load('products');
print info_admin($langs->trans('WhenProductVirtualOnOptionAreForced'));
$disableStockCalculateOn[] = 'BILL';
$disableStockCalculateOn[] = 'VALIDATE_ORDER';
$disableStockCalculateOn[] = 'SHIPMENT_CLOSE';
}
if (isModEnabled('productbatch')) {
// If module lot/serial enabled, we force the inc/dec mode to STOCK_CALCULATE_ON_SHIPMENT_CLOSE and STOCK_CALCULATE_ON_RECEPTION_CLOSE
$langs->load("productbatch");
$disabled = ' disabled';
$disableStockCalculateOn[] = 'BILL';
$disableStockCalculateOn[] = 'VALIDATE_ORDER';

// STOCK_CALCULATE_ON_SHIPMENT_CLOSE
$descmode = $langs->trans('DeStockOnShipmentOnClosing');
Expand Down Expand Up @@ -222,7 +229,7 @@
print '<td class="right">';
if (isModEnabled('facture')) {
if ($conf->use_javascript_ajax) {
if ($disabled) {
if (in_array('BILL', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_BILL', array(), null, 0, 0, 0, 2, 1, 0, '', '', 'reposition');
Expand All @@ -244,7 +251,7 @@
print '<td class="right">';
if (isModEnabled('commande')) {
if ($conf->use_javascript_ajax) {
if ($disabled) {
if (in_array('VALIDATE_ORDER', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
Expand All @@ -268,7 +275,11 @@
print '<td class="right">';
if (isModEnabled("expedition")) {
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
if (in_array('SHIPMENT', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
}
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT);
Expand All @@ -285,7 +296,11 @@
print '<td class="right">';
if (isModEnabled("expedition")) {
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
if (in_array('SHIPMENT_CLOSE', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_SHIPMENT_CLOSE', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
}
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("STOCK_CALCULATE_ON_SHIPMENT_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE);
Expand Down Expand Up @@ -318,7 +333,7 @@
print '<td class="right">';
if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
if ($conf->use_javascript_ajax) {
if ($disabled) {
if (in_array('BILL', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_BILL', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
Expand All @@ -340,7 +355,7 @@
print '<td class="right">';
if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice")) {
if ($conf->use_javascript_ajax) {
if ($disabled) {
if (in_array('VALIDATE_ORDER', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
Expand All @@ -362,7 +377,11 @@
print '<td class="right">';

if ($conf->use_javascript_ajax) {
print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
if (in_array('RECEPTION', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
}
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION);
Expand All @@ -377,7 +396,11 @@
print '<td class="right">';

if ($conf->use_javascript_ajax) {
print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION_CLOSE', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
if (in_array('RECEPTION_CLOSE', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_RECEPTION_CLOSE', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
}
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("STOCK_CALCULATE_ON_RECEPTION_CLOSE", $arrval, $conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE);
Expand All @@ -391,7 +414,11 @@
print '<td class="right">';
if (isModEnabled("supplier_order")) {
if ($conf->use_javascript_ajax) {
print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
if (in_array('SUPPLIER_DISPATCH_ORDER', $disableStockCalculateOn)) {
print img_picto($langs->trans("Disabled"), 'off', 'class="opacitymedium"');
} else {
print ajax_constantonoff('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER', array(), null, 0, 0, 0, 2, 1, '', '', 'reposition');
}
} else {
$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
print $form->selectarray("STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $arrval, $conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/html.formother.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getHTMLScannerForm($jstoexecuteonadd = 'barcodescannerjs', $mode
$stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
$htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
$stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
$out .= $stringaddbarcode.' <input type="text" name="barcodeproductqty" class="width50 right" value="1"><br>';
$out .= $stringaddbarcode.': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>';
$out .= '<br>';
$out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';

Expand Down
149 changes: 149 additions & 0 deletions htdocs/expedition/ajax/interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<?php
/* Copyright (C) 2024 Laurent Destailleur (eldy) <[email protected]>
* Copyright (C) 2024 Lionel Vessiller <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* \file htdocs/expedition/ajax/interface.php
* \brief Ajax search component for Shipment.
*/

if (!defined('NOREQUIRESOC')) {
define('NOREQUIRESOC', '1');
}
if (!defined('NOCSRFCHECK')) {
define('NOCSRFCHECK', '1');
}
if (!defined('NOTOKENRENEWAL')) {
define('NOTOKENRENEWAL', '1');
}
if (!defined('NOREQUIREMENU')) {
define('NOREQUIREMENU', '1');
}
if (!defined('NOREQUIREHTML')) {
define('NOREQUIREHTML', '1');
}
if (!defined('NOREQUIREAJAX')) {
define('NOREQUIREAJAX', '1');
}

require '../../main.inc.php'; // Load $user and permissions
/**
* @var DoliDB $db
* @var Translate $langs
* @var User $user
*/

$warehouse_id = GETPOSTINT('warehouse_id');
$batch = GETPOST('batch', 'alphanohtml');
$product_id = GETPOSTINT('product_id');
$action = GETPOST('action', 'alphanohtml');

$result = restrictedArea($user, 'expedition');

$permissiontowrite = $user->hasRight('expedition', 'write');

$is_eat_by_enabled = !getDolGlobalInt('PRODUCT_DISABLE_EATBY');
$is_sell_by_enabled = !getDolGlobalInt('PRODUCT_DISABLE_SELLBY');


/*
* View
*/

top_httphead("application/json");

if ($action == 'updateselectbatchbywarehouse' && $permissiontowrite) {
$resArr = array();

$sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, pb.qty, e.ref as label, ps.fk_product";
if ($is_eat_by_enabled) {
$sql .= ", pl.eatby";
}
if ($is_sell_by_enabled) {
$sql .= ", pl.sellby";
}
$sql .= " FROM ".$db->prefix()."product_batch as pb";
$sql .= " LEFT JOIN ".$db->prefix()."product_stock as ps on ps.rowid = pb.fk_product_stock";
$sql .= " LEFT JOIN ".$db->prefix()."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")";
if ($is_eat_by_enabled || $is_sell_by_enabled) {
$sql .= " LEFT JOIN ".$db->prefix()."product_lot as pl on ps.fk_product = pl.fk_product AND pb.batch = pl.batch";
}
$sql .= " WHERE ps.fk_product = ".((int) $product_id);
if ($warehouse_id > 0) {
$sql .= " AND fk_entrepot = '".((int) $warehouse_id)."'";
}
$sql .= " ORDER BY e.ref, pb.batch";

$resql = $db->query($sql);

if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$eat_by_date_formatted = '';
if ($is_eat_by_enabled && !empty($obj->eatby)) {
$eat_by_date_formatted = dol_print_date($db->jdate($obj->eatby), 'day');
}
$sell_by_date_formatted = '';
if ($is_sell_by_enabled && !empty($obj->sellby)) {
$sell_by_date_formatted = dol_print_date($db->jdate($obj->sellby), 'day');
}

// set qty
if (!isset($resArr[$obj->batch])) {
$resArr[$obj->batch] = array(
'qty' => (float) $obj->qty,
);
} else {
$resArr[$obj->batch]['qty'] += $obj->qty;
}

// set eat-by date
if (!isset($resArr[$obj->batch]['eatbydate'])) {
$resArr[$obj->batch]['eatbydate'] = $eat_by_date_formatted;
}

// set sell-by date
if (!isset($resArr[$obj->batch]['sellbydate'])) {
$resArr[$obj->batch]['sellbydate'] = $sell_by_date_formatted;
}
}
}

echo json_encode($resArr);
} elseif ($action == 'updateselectwarehousebybatch' && $permissiontowrite) {
$res = 0;

$sql = "SELECT pb.batch, pb.rowid, ps.fk_entrepot, e.ref, pb.qty";
$sql .= " FROM ".$db->prefix()."product_batch as pb";
$sql .= " JOIN ".$db->prefix()."product_stock as ps on ps.rowid = pb.fk_product_stock";
$sql .= " JOIN ".$db->prefix()."entrepot as e on e.rowid = ps.fk_entrepot AND e.entity IN (".getEntity('stock').")";
$sql .= " WHERE ps.fk_product = ".((int) $product_id);
if ($batch) {
$sql .= " AND pb.batch = '".$db->escape($batch)."'";
}
$sql .= " ORDER BY e.ref, pb.batch";

$resql = $db->query($sql);

if ($resql) {
if ($db->num_rows($resql) == 1) {
$obj = $db->fetch_object($resql);
$res = $obj->fk_entrepot;
}
}

echo json_encode($res);
}
Loading