From de31920f28093e3845f3dceb6f1a2783e2f191aa Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Mon, 14 Sep 2020 10:57:51 +0200 Subject: [PATCH] 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 --- htdocs/product/card.php | 121 +++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 19 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index df3f21a453a..748eb4414ab 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -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.'/product/class/product.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/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; @@ -290,7 +291,8 @@ if (empty($reshook)) $object->note_private = dol_htmlcleanlastbr(GETPOST('note_private', 'none')); $object->note = $object->note_private; // deprecated $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_unit = $duration_unit; $object->fk_default_warehouse = GETPOST('fk_default_warehouse'); @@ -395,7 +397,8 @@ if (empty($reshook)) $object->note = $object->note_private; } $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_buy = GETPOST('statut_buy', 'int'); $object->status_batch = GETPOST('status_batch', 'aZ09'); @@ -865,7 +868,8 @@ llxHeader('', $title, $helpurl); $form = new Form($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); // Load object modBarCodeProduct @@ -899,14 +903,25 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } $objcanvas->assign_values($action, $object->id, $object->ref); // Set value for templates $objcanvas->display_canvas($action); // Show template -} else { +} else { + // ----------------------------------------- // When used in standard mode // ----------------------------------------- if ($action == 'create' && $usercancreate) { + //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + +print ''."\n"; // Load object modCodeProduct $module = (!empty($conf->global->PRODUCT_CODEPRODUCT_ADDON) ? $conf->global->PRODUCT_CODEPRODUCT_ADDON : 'mod_codeproduct_leopard'); @@ -919,10 +934,10 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $modCodeProduct = new $module(); } - + dol_set_focus('input[name="ref"]'); - print '
'; + print ''; print ''; print ''; print ''."\n"; @@ -941,6 +956,15 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) } $linkback = ""; 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(''); @@ -1114,14 +1138,31 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Custom code if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO) && empty($type)) { - print ''.$langs->trans("CustomCode").''; - if ($conf->browser->layout == 'phone') print ''; + print ''.$langs->trans("CustomCode").''; + // Origin country print ''.$langs->trans("CountryOrigin").''; print ''; - print $form->select_country(GETPOST('country_id', 'int'), 'country_id'); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print ''; + 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); + print ''; + + // State + if (empty($conf->global->PRODUCT_DISABLE_STATE)) + { + if ($conf->browser->layout == 'phone') print ''; + 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 ''.$form->editfieldkey('Region-StateOrigine', 'state_id', '', $object, 0).''; + } else { + print ''.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).''; + } + + print $formcompany->select_state($object->state_id, $object->country_code); + print ''; + } + print ''; } // Other attributes @@ -1324,6 +1365,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print '
'; } elseif ($object->id > 0) { + + + /* * Product card */ @@ -1332,13 +1376,32 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - + +print ''."\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'); if ($object->isService()) $type = $langs->trans('Service'); //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), ""); // Main official, simple, and not duplicated code - print '
'."\n"; + print ''."\n"; print ''; print ''; print ''; @@ -1348,6 +1411,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) $titre = $langs->trans("CardProduct".$object->type); $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product'); dol_fiche_head($head, 'card', $titre, 0, $picto); + print ''; @@ -1529,13 +1593,30 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) // Custom code if (!$object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) { - print ''; - // Origin country - print ''; + // Origin country + print ''; + print ''; - } + print ''; + // State + if (empty($conf->global->PRODUCT_DISABLE_STATE)) + { + if ($conf->browser->layout == 'phone') print ''; + 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 ''; + } + print ''; + } // Other attributes $parameters = array('colspan' => ' colspan="3"', 'cols' => 3); @@ -2031,7 +2112,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print ''; // Origin country code - print ''; + print ''; } // Other attributes
'.$langs->trans("CustomCode").''.$langs->trans("CountryOrigin").''; + print '
'.$langs->trans("CustomCode").'
'.$langs->trans("CountryOrigin").''; + print img_picto('', 'globe-americas', 'class="paddingrightonly"'); print $form->select_country($object->country_id, 'country_id', '', 0, 'minwidth100 maxwidthonsmartphone'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); - print '
'.$form->editfieldkey('Region-StateOrigine', 'state_id', '', $object, 0).''; + } else { + print ''.$form->editfieldkey('StateOrigin', 'state_id', '', $object, 0).''; + } + + print $formcompany->select_state($object->state_id, $object->country_code); + print '
'.$langs->trans("CustomCode").''.$object->customcode.'
'.$langs->trans("CountryOrigin").''.getCountry($object->country_id, 0, $db).'
'.$langs->trans("Origin").''.getCountry($object->country_id, 0, $db); + if (!empty($object->state_id)) print ' - '.getState($object->state_id, 0, $db); + print '