From eae232da50aed63dd6d8942a124bcc9ee06e5a6a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Feb 2021 19:16:26 +0100 Subject: [PATCH 1/4] Fix sql error --- htdocs/fourn/facture/list.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index bfe080c36a0..317def67098 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -412,7 +412,6 @@ if ($search_all || $search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_P if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet"; -$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if ($search_user > 0) From e1af57f540472bac3ccd22fff93ec12b9fb5d406 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Feb 2021 20:46:17 +0100 Subject: [PATCH 2/4] FIX status late on purchase orders --- ChangeLog | 1 + .../class/fournisseur.commande.class.php | 42 ++++++++++--- htdocs/fourn/commande/card.php | 12 ++-- htdocs/fourn/commande/dispatch.php | 2 +- htdocs/fourn/commande/list.php | 62 ++++++++++--------- 5 files changed, 74 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 35dc54979a8..603b5620a92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -51,6 +51,7 @@ FIX: Timeout during import FIX: Trigger on expense report was not fired FIX: User creation of expense report not visible FIX: warning when adding a line if $remise_percent is an empty string +FIX: status late on purchase orders ***** ChangeLog for 13.0.0 compared to 12.0.0 ***** diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index f2b508f665e..598f19ee0a0 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -3069,8 +3069,10 @@ class CommandeFournisseur extends CommonOrder /** * Is the supplier order delayed? + * We suppose a purchase ordered as late if a the purchase order has been sent and the delivery date is set and before the delay. + * If order has not been sent, we use the order date. * - * @return bool + * @return bool True if object is delayed */ public function hasDelay() { @@ -3078,14 +3080,28 @@ class CommandeFournisseur extends CommonOrder if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison; // For backward compatibility - $now = dol_now(); - $date_to_test = empty($this->delivery_date) ? $this->date_commande : $this->delivery_date; + if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) { + $now = dol_now(); + if (!empty($this->delivery_date)) { + $date_to_test = $this->delivery_date; + return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay); + } else { + //$date_to_test = $this->date_commande; + //return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay); + return false; + } + } else { + $now = dol_now(); + $date_to_test = $this->date_commande; - return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay); + return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay); + } } /** - * Show the customer delayed info + * Show the customer delayed info. + * We suppose a purchase ordered as late if a the purchase order has been sent and the delivery date is set and before the delay. + * If order has not been sent, we use the order date. * * @return string Show delayed information */ @@ -3095,12 +3111,20 @@ class CommandeFournisseur extends CommonOrder if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison; // For backward compatibility - if (empty($this->delivery_date)) { - $text = $langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day'); + $text = ''; + + if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) { + if (!empty($this->delivery_date)) { + $text = $langs->trans("DeliveryDate").' '.dol_print_date($this->delivery_date, 'day'); + } else { + $text = $langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day'); + } } else { - $text = $langs->trans("DeliveryDate").' '.dol_print_date($this->delivery_date, 'day'); + $text = $langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day'); + } + if ($text) { + $text .= ' '.($conf->commande->fournisseur->warning_delay > 0 ? '+' : '-').' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).' '.$langs->trans("days").' < '.$langs->trans("Today"); } - $text .= ' '.($conf->commande->fournisseur->warning_delay > 0 ? '+' : '-').' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).' '.$langs->trans("days").' < '.$langs->trans("Today"); return $text; } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index ed8a6f75a1d..ef4e46e0d5a 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2147,6 +2147,12 @@ if ($action == 'create') print ''; } + // Delivery delay (in days) + print ''; + print ''.$langs->trans('NbDaysToDelivery').' '.img_picto($langs->trans('DescNbDaysToDelivery'), 'info', 'style="cursor:help"').''; + print ''.$object->getMaxDeliveryTimeDay($langs).''; + print ''; + // Delivery date planed print ''; print ''; - // Delivery delay (in days) - print ''; - print ''; - print ''; - print ''; - // Incoterms if (!empty($conf->incoterm->enabled)) { diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 4175e5064c6..78db7e85a47 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -724,7 +724,7 @@ if ($id > 0 || !empty($ref)) { if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); $sql .= $hookmanager->resPrint; - $sql .= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent, p.fk_default_warehouse"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product + $sql .= " GROUP BY p.ref, p.label, p.tobatch, p.fk_default_warehouse, l.rowid, l.fk_product, l.subprice, l.remise_percent, l.ref"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product $sql .= " ORDER BY p.ref, p.label"; $resql = $db->query($sql); diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index c5173ccddeb..f06542ab143 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -142,30 +142,30 @@ if (empty($user->socid)) $fieldstosearchall["cf.note_private"] = "NotePrivate"; $checkedtypetiers = 0; $arrayfields = array( - 'cf.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), - 'cf.ref_supplier'=>array('label'=>$langs->trans("RefOrderSupplierShort"), 'checked'=>1, 'enabled'=>1), - 'p.project_ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0, 'enabled'=>1), - 'u.login'=>array('label'=>$langs->trans("AuthorRequest"), 'checked'=>1), - 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1), - 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1), - 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1), - 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0), - 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0), - 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers), - 'cf.date_commande'=>array('label'=>$langs->trans("OrderDateShort"), 'checked'=>1), - 'cf.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)), - 'cf.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), - 'cf.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0), - 'cf.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0), + 'cf.ref'=>array('label'=>"Ref", 'checked'=>1), + 'cf.ref_supplier'=>array('label'=>"RefOrderSupplierShort", 'checked'=>1, 'enabled'=>1), + 'p.project_ref'=>array('label'=>"ProjectRef", 'checked'=>0, 'enabled'=>1), + 'u.login'=>array('label'=>"AuthorRequest", 'checked'=>1), + 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1), + 's.town'=>array('label'=>"Town", 'checked'=>1), + 's.zip'=>array('label'=>"Zip", 'checked'=>1), + 'state.nom'=>array('label'=>"StateShort", 'checked'=>0), + 'country.code_iso'=>array('label'=>"Country", 'checked'=>0), + 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers), + 'cf.date_commande'=>array('label'=>"OrderDateShort", 'checked'=>1), + 'cf.date_livraison'=>array('label'=>"DateDeliveryPlanned", 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)), + 'cf.total_ht'=>array('label'=>"AmountHT", 'checked'=>1), + 'cf.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0), + 'cf.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0), 'cf.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'cf.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'cf.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'cf.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 'cf.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), - 'cf.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), - 'cf.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), - 'cf.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), - 'cf.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>1) + 'cf.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500), + 'cf.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), + 'cf.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), + 'cf.billed'=>array('label'=>"Billed", 'checked'=>1, 'position'=>1000, 'enabled'=>1) ); // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; @@ -525,7 +525,7 @@ if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DI $sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.email,'; $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; -$sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.tva as total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_delivery,"; +$sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.tva as total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_livraison,"; $sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva as multicurrency_total_vat, cf.multicurrency_total_ttc,'; $sql .= ' cf.date_creation as date_creation, cf.tms as date_update,'; $sql .= ' cf.note_public, cf.note_private,'; @@ -874,7 +874,7 @@ if ($resql) print ''; } // Date delivery - if (!empty($arrayfields['cf.date_delivery']['checked'])) + if (!empty($arrayfields['cf.date_livraison']['checked'])) { print ''; if (!$i) $totalarray['nbfield']++; } // Plannned date of delivery - if (!empty($arrayfields['cf.date_delivery']['checked'])) + if (!empty($arrayfields['cf.date_livraison']['checked'])) { print ''; if (!$i) $totalarray['nbfield']++; From 0e2c27d7954e3ff3a83c43cd6f069be45f5e584d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 9 Feb 2021 21:06:11 +0100 Subject: [PATCH 3/4] Fix javascript error --- htdocs/main.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 84c695d9978..7136e48b06d 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -1448,7 +1448,8 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr { $pathckeditor = constant('JS_CKEDITOR'); } - print '
'; @@ -2175,12 +2181,6 @@ if ($action == 'create') } print '
'.$langs->trans('NbDaysToDelivery').' '.img_picto($langs->trans('DescNbDaysToDelivery'), 'info', 'style="cursor:help"').''.$object->getMaxDeliveryTimeDay($langs).'
'; if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; @@ -993,7 +993,7 @@ if ($resql) if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['cf.fk_author']['checked'])) print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder); if (!empty($arrayfields['cf.date_commande']['checked'])) print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['cf.date_delivery']['checked'])) print_liste_field_titre($arrayfields['cf.date_delivery']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['cf.date_livraison']['checked'])) print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center '); if (!empty($arrayfields['cf.total_ht']['checked'])) print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['cf.total_vat']['checked'])) print_liste_field_titre($arrayfields['cf.total_vat']['label'], $_SERVER["PHP_SELF"], "cf.tva", "", $param, '', $sortfield, $sortorder, 'right '); if (!empty($arrayfields['cf.total_ttc']['checked'])) print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right '); @@ -1043,7 +1043,7 @@ if ($resql) $objectstatic->total_tva = $obj->total_tva; $objectstatic->total_ttc = $obj->total_ttc; $objectstatic->date_commande = $db->jdate($obj->date_commande); - $objectstatic->date_delivery = $db->jdate($obj->date_delivery); + $objectstatic->delivery_date = $db->jdate($obj->date_livraison); $objectstatic->note_public = $obj->note_public; $objectstatic->note_private = $obj->note_private; $objectstatic->statut = $obj->fk_statut; @@ -1153,19 +1153,23 @@ if ($resql) { print ''; print dol_print_date($db->jdate($obj->date_commande), 'day'); - if ($objectstatic->hasDelay() && !empty($objectstatic->date_delivery)) { - print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning"); + if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) { + if ($objectstatic->hasDelay()) { + print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning"); + } } print ''; - print dol_print_date($db->jdate($obj->date_delivery), 'day'); - if ($objectstatic->hasDelay() && !empty($objectstatic->date_delivery)) { - print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning"); + print dol_print_date($db->jdate($obj->date_livraison), 'day'); + if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) { + if ($objectstatic->hasDelay()) { + print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning"); + } } print '