NEW add state origin for product

usefull for food, fruits or vegetables  or regional product

soon in other PR i will push filter by state or country in product list
This commit is contained in:
ptibogxiv 2020-09-14 10:57:51 +02:00 committed by GitHub
parent cde58c6908
commit de31920f28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
@ -291,6 +292,7 @@ if (empty($reshook))
$object->note = $object->note_private; // deprecated $object->note = $object->note_private; // deprecated
$object->customcode = GETPOST('customcode', 'alphanohtml'); $object->customcode = GETPOST('customcode', 'alphanohtml');
$object->country_id = GETPOST('country_id', 'int'); $object->country_id = GETPOST('country_id', 'int');
$object->state_id = GETPOST('state_id', 'int');
$object->duration_value = $duration_value; $object->duration_value = $duration_value;
$object->duration_unit = $duration_unit; $object->duration_unit = $duration_unit;
$object->fk_default_warehouse = GETPOST('fk_default_warehouse'); $object->fk_default_warehouse = GETPOST('fk_default_warehouse');
@ -396,6 +398,7 @@ if (empty($reshook))
} }
$object->customcode = GETPOST('customcode', 'alpha'); $object->customcode = GETPOST('customcode', 'alpha');
$object->country_id = GETPOST('country_id', 'int'); $object->country_id = GETPOST('country_id', 'int');
$object->state_id = GETPOST('state_id', 'int');
$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');
@ -866,6 +869,7 @@ llxHeader('', $title, $helpurl);
$form = new Form($db); $form = new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$formproduct = new FormProduct($db); $formproduct = new FormProduct($db);
$formcompany = new FormCompany($db);
if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db); if (!empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
// Load object modBarCodeProduct // Load object modBarCodeProduct
@ -900,14 +904,25 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates
$objcanvas->display_canvas($action); // Show template $objcanvas->display_canvas($action); // Show template
} else { } else {
// ----------------------------------------- // -----------------------------------------
// When used in standard mode // When used in standard mode
// ----------------------------------------- // -----------------------------------------
if ($action == 'create' && $usercancreate) if ($action == 'create' && $usercancreate)
{ {
//WYSIWYG Editor //WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
print '<script type="text/javascript">';
print '$(document).ready(function () {
$("#selectcountry_id").change(function() {
document.formprod.action.value="create";
document.formprod.submit();
});
});';
print '</script>'."\n";
// Load object modCodeProduct // Load object modCodeProduct
$module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard');
if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php') if (substr($module, 0, 16) == 'mod_codeproduct_' && substr($module, -3) == 'php')
@ -922,7 +937,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
dol_set_focus('input[name="ref"]'); dol_set_focus('input[name="ref"]');
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formprod">';
print '<input type="hidden" name="token" value="'.newToken().'">'; print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="type" value="'.$type.'">'."\n"; print '<input type="hidden" name="type" value="'.$type.'">'."\n";
@ -942,6 +957,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$linkback = ""; $linkback = "";
print load_fiche_titre($title, $linkback, $picto); print load_fiche_titre($title, $linkback, $picto);
// We set country_id, country_code and country for the selected country
$object->country_id = GETPOST('country_id') ?GETPOST('country_id') : null;
if ($object->country_id)
{
$tmparray = getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
}
dol_fiche_head(''); dol_fiche_head('');
print '<table class="border centpercent">'; print '<table class="border centpercent">';
@ -1114,14 +1138,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Custom code // Custom code
if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type)) if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type))
{ {
print '<tr><td>'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.GETPOST('customcode').'"></td>'; print '<tr><td>'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.GETPOST('customcode').'"></td></tr>';
if ($conf->browser->layout == 'phone') print '</tr><tr>';
// Origin country // Origin country
print '<td>'.$langs->trans("CountryOrigin").'</td>'; print '<td>'.$langs->trans("CountryOrigin").'</td>';
print '<td>'; print '<td>';
print $form->select_country(GETPOST('country_id', 'int'), 'country_id'); print img_picto('', 'globe-americas', 'class="paddingrightonly"');
print $form->select_country((GETPOSTISSET('country_id') ? GETPOST('country_id') : $object->country_id), 'country_id', '', 0, 'minwidth300 widthcentpercentminusx');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
print '</td></tr>'; print '</td>';
// State
if (empty($conf->global->PRODUCT_DISABLE_STATE))
{
if ($conf->browser->layout == 'phone') print '</tr><tr>';
if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
{
print '<td>'.$form->editfieldkey('Region-StateOrigine', 'state_id', '', $object, 0).'</td><td colspan="3">';
} else {
print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td colspan="3">';
}
print $formcompany->select_state($object->state_id, $object->country_code);
print '</tr>';
}
print '</tr>';
} }
// Other attributes // Other attributes
@ -1324,6 +1365,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '</form>'; print '</form>';
} elseif ($object->id > 0) { } elseif ($object->id > 0) {
/* /*
* Product card * Product card
*/ */
@ -1333,12 +1377,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
//WYSIWYG Editor //WYSIWYG Editor
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
print '<script type="text/javascript">';
print '$(document).ready(function () {
$("#selectcountry_id").change(function() {
document.formprod.action.value="edit";
document.formprod.submit();
});
});';
print '</script>'."\n";
// We set country_id, country_code and country for the selected country
$object->country_id = GETPOST('country_id') ? GETPOST('country_id') : $object->country_id;
if ($object->country_id)
{
$tmparray = getCountry($object->country_id, 'all');
$object->country_code = $tmparray['code'];
$object->country = $tmparray['label'];
}
$type = $langs->trans('Product'); $type = $langs->trans('Product');
if ($object->isService()) $type = $langs->trans('Service'); if ($object->isService()) $type = $langs->trans('Service');
//print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), ""); //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
// Main official, simple, and not duplicated code // Main official, simple, and not duplicated code
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">'."\n"; print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="formprod">'."\n";
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">';
print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">';
@ -1349,6 +1412,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
$picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
dol_fiche_head($head, 'card', $titre, 0, $picto); dol_fiche_head($head, 'card', $titre, 0, $picto);
print '<table class="border allwidth">'; print '<table class="border allwidth">';
// Ref // Ref
@ -1529,12 +1593,29 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
// Custom code // Custom code
if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO))
{ {
print '<tr><td>'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.$object->customcode.'"></td>'; print '<tr><td>'.$langs->trans("CustomCode").'</td><td><input name="customcode" class="maxwidth100onsmartphone" value="'.$object->customcode.'"></td></tr>';
// Origin country // Origin country
print '<td>'.$langs->trans("CountryOrigin").'</td><td>'; print '<td>'.$langs->trans("CountryOrigin").'</td>';
print '<td>';
print img_picto('', 'globe-americas', 'class="paddingrightonly"');
print $form->select_country($object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone'); print $form->select_country($object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
print '</td></tr>'; print '</td>';
// State
if (empty($conf->global->PRODUCT_DISABLE_STATE))
{
if ($conf->browser->layout == 'phone') print '</tr><tr>';
if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && ($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 || $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 2))
{
print '<td>'.$form->editfieldkey('Region-StateOrigine', 'state_id', '', $object, 0).'</td><td colspan="3">';
} else {
print '<td>'.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).'</td><td colspan="3">';
}
print $formcompany->select_state($object->state_id, $object->country_code);
print '</td>';
}
print '</tr>';
} }
// Other attributes // Other attributes
@ -2031,7 +2112,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
print '<tr><td>'.$langs->trans("CustomCode").'</td><td colspan="2">'.$object->customcode.'</td>'; print '<tr><td>'.$langs->trans("CustomCode").'</td><td colspan="2">'.$object->customcode.'</td>';
// Origin country code // Origin country code
print '<tr><td>'.$langs->trans("CountryOrigin").'</td><td colspan="2">'.getCountry($object->country_id, 0, $db).'</td>'; print '<tr><td>'.$langs->trans("Origin").'</td><td colspan="2">'.getCountry($object->country_id, 0, $db);
if (!empty($object->state_id)) print ' - '.getState($object->state_id, 0, $db);
print '</td>';
} }
// Other attributes // Other attributes