From a6b60857723fbaad7cb371d7b41047189bcaa7e9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Wed, 28 Nov 2012 18:13:02 +0100 Subject: [PATCH 1/5] Qual : remove multi fetch --- htdocs/fourn/commande/fiche.php | 45 +++++++++------------------------ 1 file changed, 12 insertions(+), 33 deletions(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 1bdc263c05f..097b35c2f92 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -81,8 +81,8 @@ $object = new CommandeFournisseur($db); // Load object if ($id > 0 || ! empty($ref)) { - $object->fetch($id, $ref); - $object->fetch_thirdparty(); + $resObj = $object->fetch($id, $ref); + $resTP = $object->fetch_thirdparty(); } /* @@ -111,7 +111,6 @@ if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->cree { $datelivraison=dol_mktime(0, 0, 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'),GETPOST('liv_year','int')); - $object->fetch($id); $result=$object->set_date_livraison($user,$datelivraison); if ($result < 0) { @@ -132,21 +131,18 @@ else if ($action == 'setremisepercent' && $user->rights->fournisseur->commande-> else if ($action == 'setnote_public' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); if ($result < 0) dol_print_error($db,$object->error); } else if ($action == 'setnote' && $user->rights->fournisseur->commande->creer) { - $object->fetch($id); $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); if ($result < 0) dol_print_error($db,$object->error); } else if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver) { - $result = $object->fetch($id); if (in_array($object->statut, array(1, 5, 6, 7, 9))) { if ($object->statut == 1) $newstatus=0; // Validated->Draft @@ -205,8 +201,8 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer) if (! $error && (($_POST['qty'] || $_POST['pqty']) && (($_POST['pu'] && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprodfournprice']))) { - if ($object->fetch($id) < 0) dol_print_error($db,$object->error); - if ($object->fetch_thirdparty() < 0) dol_print_error($db,$object->error); + if ($resObj < 0) dol_print_error($db,$object->error); + if ($resTP < 0) dol_print_error($db,$object->error); // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit @@ -339,8 +335,8 @@ else if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer if ($product->fetch($_POST["elrowid"]) < 0) dol_print_error($db); } - if ($object->fetch($id) < 0) dol_print_error($db,$object->error); - if ($object->fetch_thirdparty() < 0) dol_print_error($db,$object->error); + if ($resObj < 0) dol_print_error($db,$object->error); + if ($resTP < 0) dol_print_error($db,$object->error); $localtax1_tx=get_localtax($_POST['tva_tx'],1,$object->thirdparty); $localtax2_tx=get_localtax($_POST['tva_tx'],2,$object->thirdparty); @@ -413,8 +409,6 @@ else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->r else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->commande->valider) { - $object->fetch_thirdparty(); - $object->date_commande=dol_now(); $result = $object->valid($user); if ($result >= 0) @@ -447,8 +441,6 @@ else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fou { $idwarehouse=GETPOST('idwarehouse', 'int'); - $object->fetch_thirdparty(); - // Check parameters if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)) { @@ -506,7 +498,6 @@ else if ($action == 'confirm_commande' && $confirm == 'yes' && $user->rights->fo else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer) { - $object->fetch_thirdparty(); $result=$object->delete($user); if ($result > 0) { @@ -624,7 +615,6 @@ else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer) / // Build document // Sauvegarde le dernier module choisi pour generer un document - $object->fetch_thirdparty(); if ($_REQUEST['model']) { @@ -655,10 +645,8 @@ else if ($action == 'remove_file' && $user->rights->fournisseur->commande->creer { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - if ($object->fetch($id)) + if ($resObj) { - $object->fetch_thirdparty(); - $langs->load("other"); $upload_dir = $conf->fournisseur->commande->dir_output; $file = $upload_dir . '/' . GETPOST('file'); @@ -744,10 +732,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G { $langs->load('mails'); - $result=$object->fetch($_POST['orderid']); - $result=$object->fetch_thirdparty(); - - if ($result > 0) + if ($resObj > 0) { // $ref = dol_sanitizeFileName($object->ref); // $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; @@ -896,12 +881,10 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss { if ($action == 'addcontact') { - $result = $object->fetch($id); - - if ($result > 0 && $id > 0) + if ($resObj) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); } if ($result >= 0) @@ -926,7 +909,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss // bascule du statut d'un contact else if ($action == 'swapstatut') { - if ($object->fetch($id)) + if ($resObj) { $result=$object->swapContactStatus(GETPOST('ligne')); } @@ -939,7 +922,6 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss // Efface un contact else if ($action == 'deletecontact') { - $object->fetch($id); $result = $object->delete_contact($_GET["lineid"]); if ($result >= 0) @@ -977,12 +959,9 @@ $now=dol_now(); if ($id > 0 || ! empty($ref)) { //if ($mesg) print $mesg.'
'; - - $result=$object->fetch($id,$ref); if ($result >= 0) { - $soc = new Societe($db); - $soc->fetch($object->socid); + $soc = &$object->thirdparty; $author = new User($db); $author->fetch($object->user_author_id); From 0587b06cf42d02c9e76d1bb51244c81a19483dbe Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 29 Nov 2012 00:20:24 +0100 Subject: [PATCH 2/5] Fix : global error print + no use of & for affectation --- htdocs/fourn/commande/fiche.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 097b35c2f92..bdd14490d64 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -83,6 +83,8 @@ if ($id > 0 || ! empty($ref)) { $resObj = $object->fetch($id, $ref); $resTP = $object->fetch_thirdparty(); + if ($resObj < 0) dol_print_error($db,$object->error); + if ($resTP < 0) dol_print_error($db,$object->error); } /* @@ -201,9 +203,6 @@ else if ($action == 'addline' && $user->rights->fournisseur->commande->creer) if (! $error && (($_POST['qty'] || $_POST['pqty']) && (($_POST['pu'] && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprodfournprice']))) { - if ($resObj < 0) dol_print_error($db,$object->error); - if ($resTP < 0) dol_print_error($db,$object->error); - // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $txtva par celui du produit @@ -732,7 +731,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G { $langs->load('mails'); - if ($resObj > 0) + if ($resObj) { // $ref = dol_sanitizeFileName($object->ref); // $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; @@ -961,8 +960,6 @@ if ($id > 0 || ! empty($ref)) //if ($mesg) print $mesg.'
'; if ($result >= 0) { - $soc = &$object->thirdparty; - $author = new User($db); $author->fetch($object->user_author_id); @@ -1000,7 +997,7 @@ if ($id > 0 || ! empty($ref)) $object->date_commande=dol_now(); // We check if number is temporary number - if (preg_match('/^[\(]?PROV/i',$object->ref)) $newref = $object->getNextNumRef($soc); + if (preg_match('/^[\(]?PROV/i',$object->ref)) $newref = $object->getNextNumRef($object->thirdparty); else $newref = $object->ref; $text=$langs->trans('ConfirmValidateOrder',$newref); @@ -1106,7 +1103,7 @@ if ($id > 0 || ! empty($ref)) // Fournisseur print ''.$langs->trans("Supplier").""; - print ''.$soc->getNomUrl(1,'supplier').''; + print ''.$object->thirdparty->getNomUrl(1,'supplier').''; print ''; // Statut @@ -1437,7 +1434,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - print $form->load_tva('tva_tx',$line->tva_tx,$soc,$mysoc); + print $form->load_tva('tva_tx',$line->tva_tx,$object->thirdparty,$mysoc); print ''; print ''; print ''; @@ -1497,11 +1494,11 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - print $form->load_tva('tva_tx',(GETPOST('tva_tx')?GETPOST('tva_tx'):-1),$soc,$mysoc); + print $form->load_tva('tva_tx',(GETPOST('tva_tx')?GETPOST('tva_tx'):-1),$object->thirdparty,$mysoc); print ''; print ''; print ''; - print '%'; + print '%'; print ''; print ''; @@ -1558,7 +1555,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; - print '%'; + print '%'; print ''; print ''; @@ -1685,7 +1682,7 @@ if ($id > 0 || ! empty($ref)) $genallowed=$user->rights->fournisseur->commande->creer; $delallowed=$user->rights->fournisseur->commande->supprimer; - print $formfile->showdocuments('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,0,0,'','','',$soc->default_lang); + print $formfile->showdocuments('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,0,0,'','','',$object->thirdparty->default_lang); $somethingshown=$formfile->numoffiles; $object=$object; @@ -1816,7 +1813,7 @@ if ($id > 0 || ! empty($ref)) $formmail->frommail = $user->email; $formmail->withfrom=1; $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; - $formmail->withtosocid=$soc->id; + $formmail->withtosocid=$object->thirdparty->id; $formmail->withtocc=1; $formmail->withtoccsocid=0; $formmail->withtoccc=(! empty($conf->global->MAIN_EMAIL_USECCC)?$conf->global->MAIN_EMAIL_USECCC:false); From 1fc35d7d42a1e265a81dc3f33c44812b03809fe9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 29 Nov 2012 00:38:39 +0100 Subject: [PATCH 3/5] Fix : value returned after order confirm was 0 if update OK, and order page wasn't reloaded --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index d2e93906bf4..3d5c7e6fb69 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -889,7 +889,7 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::commande sql=".$sql, LOG_DEBUG); if ($this->db->query($sql)) { - $result = 0; + $result = 1; $this->log($user, 3, $date, $comment); } else From 19f3866b054603f86eb29faf09688143b62e2d78 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 29 Nov 2012 01:05:45 +0100 Subject: [PATCH 4/5] Fix : have to fetch object after create to reload values + thirdparty must be loaded if mode = create --- htdocs/fourn/commande/fiche.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index bdd14490d64..4b21dc14ce6 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -83,8 +83,13 @@ if ($id > 0 || ! empty($ref)) { $resObj = $object->fetch($id, $ref); $resTP = $object->fetch_thirdparty(); + print_r($object->thirdparty); if ($resObj < 0) dol_print_error($db,$object->error); if ($resTP < 0) dol_print_error($db,$object->error); +} else if($socid) { + $object->socid = $socid; + $resTP = $object->fetch_thirdparty(); + if ($resTP < 0) dol_print_error($db,$object->error); } /* @@ -334,9 +339,6 @@ else if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer if ($product->fetch($_POST["elrowid"]) < 0) dol_print_error($db); } - if ($resObj < 0) dol_print_error($db,$object->error); - if ($resTP < 0) dol_print_error($db,$object->error); - $localtax1_tx=get_localtax($_POST['tva_tx'],1,$object->thirdparty); $localtax2_tx=get_localtax($_POST['tva_tx'],2,$object->thirdparty); @@ -684,6 +686,7 @@ else if ($action == 'create' && $user->rights->fournisseur->commande->creer) } $id=$orderid; + $ret=$object->fetch($id); // Reload to get new records $db->commit(); } From e3d6b0dd9e5a5588d91f0fd6d1c656fab000d81d Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 29 Nov 2012 09:52:20 +0100 Subject: [PATCH 5/5] Fix : remove print_r... --- htdocs/fourn/commande/fiche.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 4b21dc14ce6..2296219bcb2 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -83,7 +83,6 @@ if ($id > 0 || ! empty($ref)) { $resObj = $object->fetch($id, $ref); $resTP = $object->fetch_thirdparty(); - print_r($object->thirdparty); if ($resObj < 0) dol_print_error($db,$object->error); if ($resTP < 0) dol_print_error($db,$object->error); } else if($socid) {