diff --git a/ChangeLog b/ChangeLog index f6f3267d5aa..d5247f4c379 100644 --- a/ChangeLog +++ b/ChangeLog @@ -26,6 +26,7 @@ For users: - New: Add hidden option MAIN_DISABLE_PDF_AUTOUPDATE to avoid generating pdf each time data change. - New: Add hidden option PROJECT_HIDE_UNSELECTABLES to hide project you can't select into combo list. - New: Add option INVOICE_POSITIVE_CREDIT_NOTE. +- New: Support zip/town autocompletion into warehouses. - Fix: Can use POS module with several concurrent users. For developers: diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 5046fb47e28..c516101295b 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -133,6 +133,9 @@ class Entrepot extends CommonObject $this->cp=trim($this->cp); $this->ville=$this->db->escape(trim($this->ville)); $this->pays_id=trim($this->pays_id?$this->pays_id:0); + $this->zip=trim($this->cp); + $this->town=$this->db->escape(trim($this->ville)); + $this->country_id=trim($this->pays_id?$this->pays_id:0); $sql = "UPDATE ".MAIN_DB_PREFIX."entrepot "; $sql .= " SET label = '" . $this->libelle ."'"; @@ -140,9 +143,9 @@ class Entrepot extends CommonObject $sql .= ",statut = " . $this->statut ; $sql .= ",lieu = '" . $this->lieu ."'"; $sql .= ",address = '" . $this->address ."'"; - $sql .= ",cp = '" . $this->cp ."'"; - $sql .= ",ville = '" . $this->ville ."'"; - $sql .= ",fk_pays = " . $this->pays_id; + $sql .= ",cp = '" . $this->zip ."'"; + $sql .= ",ville = '" . $this->town ."'"; + $sql .= ",fk_pays = " . $this->country_id; $sql .= " WHERE rowid = " . $id; $this->db->begin(); @@ -221,7 +224,7 @@ class Entrepot extends CommonObject */ function fetch($id) { - $sql = "SELECT rowid, label, description, statut, lieu, address, cp, ville, fk_pays"; + $sql = "SELECT rowid, label, description, statut, lieu, address, cp as zip, ville as town, fk_pays as country_id"; $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; $sql .= " WHERE rowid = ".$id; @@ -238,13 +241,16 @@ class Entrepot extends CommonObject $this->statut = $obj->statut; $this->lieu = $obj->lieu; $this->address = $obj->address; - $this->cp = $obj->cp; - $this->ville = $obj->ville; - $this->pays_id = $obj->fk_pays; + $this->cp = $obj->zip; + $this->ville = $obj->town; + $this->pays_id = $obj->country_id; + $this->zip = $obj->zip; + $this->town = $obj->town; + $this->country_id = $obj->country_id; - if ($this->pays_id) + if ($this->country_id) { - $sqlp = "SELECT code,libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$this->pays_id; + $sqlp = "SELECT code,libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$this->country_id; $resql=$this->db->query($sqlp); if ($resql) { @@ -256,6 +262,8 @@ class Entrepot extends CommonObject } $this->pays=$objp->libelle; $this->pays_code=$objp->code; + $this->country=$objp->libelle; + $this->country_code=$objp->code; } $this->db->free($result); @@ -269,9 +277,10 @@ class Entrepot extends CommonObject } - /* - * \brief Charge les informations d'ordre info dans l'objet entrepot - * \param id id de l'entrepot a charger + /** + * Charge les informations d'ordre info dans l'objet entrepot + * + * @param int $id id de l'entrepot a charger */ function info($id) { diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php index 16cab013f43..f8043f306d8 100644 --- a/htdocs/product/stock/fiche.php +++ b/htdocs/product/stock/fiche.php @@ -29,6 +29,7 @@ require_once(DOL_DOCUMENT_ROOT."/product/stock/class/entrepot.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/stock.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/product.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php"); $langs->load("products"); $langs->load("stocks"); @@ -51,20 +52,23 @@ $mesg = ''; // Ajout entrepot if ($action == 'add' && $user->rights->stock->creer) { - $entrepot = new Entrepot($db); + $object = new Entrepot($db); - $entrepot->ref = $_POST["ref"]; - $entrepot->libelle = $_POST["libelle"]; - $entrepot->description = $_POST["desc"]; - $entrepot->statut = $_POST["statut"]; - $entrepot->lieu = $_POST["lieu"]; - $entrepot->address = $_POST["address"]; - $entrepot->cp = $_POST["cp"]; - $entrepot->ville = $_POST["ville"]; - $entrepot->pays_id = $_POST["pays_id"]; + $object->ref = $_POST["ref"]; + $object->libelle = $_POST["libelle"]; + $object->description = $_POST["desc"]; + $object->statut = $_POST["statut"]; + $object->lieu = $_POST["lieu"]; + $object->address = $_POST["address"]; + $object->cp = $_POST["zipcode"]; + $object->ville = $_POST["town"]; + $object->pays_id = $_POST["pays_id"]; + $object->zip = $_POST["zipcode"]; + $object->town = $_POST["town"]; + $object->country_id = $_POST["pays_id"]; - if ($entrepot->libelle) { - $id = $entrepot->create($user); + if ($object->libelle) { + $id = $object->create($user); if ($id > 0) { header("Location: fiche.php?id=".$id); @@ -72,7 +76,7 @@ if ($action == 'add' && $user->rights->stock->creer) } $action = 'create'; - $mesg='
'.$entrepot->error.'
'; + $mesg='
'.$object->error.'
'; } else { $mesg='
'.$langs->trans("ErrorWarehouseRefRequired").'
'; @@ -83,9 +87,9 @@ if ($action == 'add' && $user->rights->stock->creer) // Delete warehouse if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->stock->supprimer) { - $entrepot = new Entrepot($db); - $entrepot->fetch($_REQUEST["id"]); - $result=$entrepot->delete($user); + $object = new Entrepot($db); + $object->fetch($_REQUEST["id"]); + $result=$object->delete($user); if ($result > 0) { header("Location: ".DOL_URL_ROOT.'/product/stock/liste.php'); @@ -93,7 +97,7 @@ if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->right } else { - $mesg='
'.$entrepot->error.'
'; + $mesg='
'.$object->error.'
'; $action=''; } } @@ -101,19 +105,22 @@ if ($action == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->right // Modification entrepot if ($action == 'update' && $_POST["cancel"] <> $langs->trans("Cancel")) { - $entrepot = new Entrepot($db); - if ($entrepot->fetch($_POST["id"])) + $object = new Entrepot($db); + if ($object->fetch($_POST["id"])) { - $entrepot->libelle = $_POST["libelle"]; - $entrepot->description = $_POST["desc"]; - $entrepot->statut = $_POST["statut"]; - $entrepot->lieu = $_POST["lieu"]; - $entrepot->address = $_POST["address"]; - $entrepot->cp = $_POST["cp"]; - $entrepot->ville = $_POST["ville"]; - $entrepot->pays_id = $_POST["pays_id"]; + $object->libelle = $_POST["libelle"]; + $object->description = $_POST["desc"]; + $object->statut = $_POST["statut"]; + $object->lieu = $_POST["lieu"]; + $object->address = $_POST["address"]; + $object->cp = $_POST["zipcode"]; + $object->ville = $_POST["town"]; + $object->pays_id = $_POST["pays_id"]; + $object->zip = $_POST["zipcode"]; + $object->town = $_POST["town"]; + $object->country_id = $_POST["pays_id"]; - if ( $entrepot->update($_POST["id"], $user) > 0) + if ( $object->update($_POST["id"], $user) > 0) { $action = ''; $_GET["id"] = $_POST["id"]; @@ -123,14 +130,14 @@ if ($action == 'update' && $_POST["cancel"] <> $langs->trans("Cancel")) { $action = 'edit'; $_GET["id"] = $_POST["id"]; - $mesg = '
'.$entrepot->error.'
'; + $mesg = '
'.$object->error.'
'; } } else { $action = 'edit'; $_GET["id"] = $_POST["id"]; - $mesg = '
'.$entrepot->error.'
'; + $mesg = '
'.$object->error.'
'; } } @@ -148,6 +155,7 @@ if ($_POST["cancel"] == $langs->trans("Cancel")) $productstatic=new Product($db); $form=new Form($db); +$formcompany=new FormCompany($db); $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; llxHeader("",$langs->trans("WarehouseCard"),$help_url); @@ -169,25 +177,31 @@ if ($action == 'create') // Ref print ''.$langs->trans("Ref").''; - print ''.$langs->trans("LocationSummary").''; + print ''.$langs->trans("LocationSummary").''; // Description print ''.$langs->trans("Description").''; // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); - $doleditor=new DolEditor('desc',$entrepot->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70); + $doleditor=new DolEditor('desc',$object->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70); $doleditor->Create(); print ''; print ''.$langs->trans('Address').''; - print ''.$langs->trans('Zip').''; - print ''.$langs->trans('Town').''; + // Zip / Town + print ''.$langs->trans('Zip').''; + print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectpays_id','departement_id'),6); + print ''.$langs->trans('Town').''; + print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectpays_id','departement_id')); + print ''; - print ''.$langs->trans('Country').''; - $form->select_pays($entrepot->pays_id?$entrepot->pays_id:$mysoc->pays_code, 'pays_id'); + // Country + print ''.$langs->trans('Country').''; + $form->select_pays($object->country_id?$object->country_id:$mysoc->country_code,'pays_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print ''; print ''.$langs->trans("Status").''; @@ -209,8 +223,8 @@ else { dol_htmloutput_mesg($mesg); - $entrepot = new Entrepot($db); - $result = $entrepot->fetch($_GET["id"]); + $object = new Entrepot($db); + $result = $object->fetch($_GET["id"]); if ($result < 0) { dol_print_error($db); @@ -221,7 +235,7 @@ else */ if ($action <> 'edit' && $action <> 're-edit') { - $head = stock_prepare_head($entrepot); + $head = stock_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock'); @@ -229,7 +243,7 @@ else if ($action == 'delete') { $form = new Form($db); - $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$entrepot->id,$langs->trans("DeleteAWarehouse"),$langs->trans("ConfirmDeleteWarehouse",$entrepot->libelle),"confirm_delete",'',0,2); + $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("DeleteAWarehouse"),$langs->trans("ConfirmDeleteWarehouse",$object->libelle),"confirm_delete",'',0,2); if ($ret == 'html') print '
'; } @@ -237,34 +251,34 @@ else // Ref print ''.$langs->trans("Ref").''; - print $form->showrefnav($entrepot,'id','',1,'rowid','libelle'); + print $form->showrefnav($object,'id','',1,'rowid','libelle'); print ''; - print ''.$langs->trans("LocationSummary").''.$entrepot->lieu.''; + print ''.$langs->trans("LocationSummary").''.$object->lieu.''; // Description - print ''.$langs->trans("Description").''.nl2br($entrepot->description).''; + print ''.$langs->trans("Description").''.nl2br($object->description).''; // Address print ''.$langs->trans('Address').''; - print $entrepot->address; + print $object->address; print ''; // Ville - print ''.$langs->trans('Zip').''.$entrepot->cp.''; - print ''.$langs->trans('Town').''.$entrepot->ville.''; + print ''.$langs->trans('Zip').''.$object->zip.''; + print ''.$langs->trans('Town').''.$object->town.''; // Country print ''.$langs->trans('Country').''; - $img=picto_from_langcode($entrepot->pays_code); + $img=picto_from_langcode($object->country_code); print ($img?$img.' ':''); - print $entrepot->pays; + print $object->country; print ''; // Statut - print ''.$langs->trans("Status").''.$entrepot->getLibStatut(4).''; + print ''.$langs->trans("Status").''.$object->getLibStatut(4).''; - $calcproducts=$entrepot->nb_products(); + $calcproducts=$object->nb_products(); // Nb of products print ''.$langs->trans("NumberOfProducts").''; @@ -279,7 +293,7 @@ else // Last movement $sql = "SELECT max(m.datem) as datem"; $sql .= " FROM llx_stock_mouvement as m"; - $sql .= " WHERE m.fk_entrepot = '".$entrepot->id."'"; + $sql .= " WHERE m.fk_entrepot = '".$object->id."'"; $resqlbis = $db->query($sql); if ($resqlbis) { @@ -294,7 +308,7 @@ else if ($lastmovementdate) { print dol_print_date($lastmovementdate,'dayhour').' '; - print '('.$langs->trans("FullList").')'; + print '('.$langs->trans("FullList").')'; } else { @@ -318,12 +332,12 @@ else if ($action == '') { if ($user->rights->stock->creer) - print "id."\">".$langs->trans("Modify").""; + print "id."\">".$langs->trans("Modify").""; else print "".$langs->trans("Modify").""; if ($user->rights->stock->supprimer) - print "id."\">".$langs->trans("Delete").""; + print "id."\">".$langs->trans("Delete").""; else print "".$langs->trans("Delete").""; } @@ -359,7 +373,7 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."product_stock ps, ".MAIN_DB_PREFIX."product p"; $sql.= " WHERE ps.fk_product = p.rowid"; $sql.= " AND ps.reel <> 0"; // We do not show if stock is 0 (no product in this warehouse) - $sql.= " AND ps.fk_entrepot = ".$entrepot->id; + $sql.= " AND ps.fk_entrepot = ".$object->id; $sql.= $db->order($sortfield,$sortorder); dol_syslog('List products sql='.$sql); @@ -426,14 +440,14 @@ else if ($user->rights->stock->mouvement->creer) { - print ''; + print ''; print img_picto($langs->trans("StockMovement"),'uparrow.png').' '.$langs->trans("StockMovement"); print ""; } if ($user->rights->stock->creer) { - print ''; + print ''; print $langs->trans("StockCorrection"); print ""; } @@ -475,44 +489,52 @@ else print '
'; print ''; print ''; - print ''; + print ''; print ''; // Ref - print ''; + print ''; - print ''; + print ''; // Description print ''; print ''; - print ''; - print ''; + // Zip / Town + print ''; - print ''; print ''; - print ''; print '
'.$langs->trans("Ref").'
'.$langs->trans("Ref").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("LocationSummary").'
'.$langs->trans("Description").''; // Editeur wysiwyg require_once(DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"); - $doleditor=new DolEditor('desc',$entrepot->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70); + $doleditor=new DolEditor('desc',$object->description,'',180,'dolibarr_notes','In',false,true,$conf->fckeditor->enabled,5,70); $doleditor->Create(); print '
'.$langs->trans('Address').'
'.$langs->trans('Zip').''.$langs->trans('Town').'
'.$langs->trans('Zip').''; + print $formcompany->select_ziptown($object->zip,'zipcode',array('town','selectpays_id','departement_id'),6); + print ''.$langs->trans('Town').''; + print $formcompany->select_ziptown($object->town,'town',array('zipcode','selectpays_id','departement_id')); + print '
'.$langs->trans('Country').''; - $form->select_pays($entrepot->pays_id, 'pays_id'); + // Country + print '
'.$langs->trans('Country').''; + $form->select_pays($object->country_id?$object->country_id:$mysoc->country_code,'pays_id'); + if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1); print '
'.$langs->trans("Status").''; print ''; print '
 '; - print '
'; + + print '

 '; + print '
'; + print '
'; }