From ed6bf372cd1c989f84bdee602c98d258394d414c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Cendrier?= <81741011+altairis-noe@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:23:22 +0100 Subject: [PATCH] NEW: use Expedition::$date_shipping property in card and list (#31701) * NEW: use Expedition::$date_shipping property in card and list * FIX: translation * FIX: PHPStan rebutal * FIX: not a great idea to copy and not edit comment * FIX: on create, expected delivery date should precede sending date * Update card.php * Update list.php * Update list.php * Update list.php --------- Co-authored-by: Laurent Destailleur --- htdocs/expedition/card.php | 36 ++++++++++++- htdocs/expedition/class/expedition.class.php | 5 +- htdocs/expedition/list.php | 57 ++++++++++++++++++-- htdocs/langs/en_US/deliveries.lang | 3 +- htdocs/langs/en_US/sendings.lang | 1 + htdocs/langs/fr_FR/deliveries.lang | 3 +- htdocs/langs/fr_FR/sendings.lang | 1 + 7 files changed, 97 insertions(+), 9 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index daef9ea49f1..8ee36319c1b 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -120,6 +120,8 @@ $hookmanager->initHooks(array('expeditioncard', 'globalcard')); $date_delivery = dol_mktime(GETPOSTINT('date_deliveryhour'), GETPOSTINT('date_deliverymin'), 0, GETPOSTINT('date_deliverymonth'), GETPOSTINT('date_deliveryday'), GETPOSTINT('date_deliveryyear')); +$date_shipping = dol_mktime(GETPOSTINT('date_shippinghour'), GETPOSTINT('date_shippingmin'), 0, GETPOSTINT('date_shippingmonth'), GETPOSTINT('date_shippingday'), GETPOSTINT('date_shippingyear')); + if ($id > 0 || !empty($ref)) { $object->fetch($id, $ref); $object->fetch_thirdparty(); @@ -266,6 +268,7 @@ if (empty($reshook)) { $object->ref_customer = GETPOST('ref_customer', 'alpha'); $object->model_pdf = GETPOST('model'); $object->date_delivery = $date_delivery; // Date delivery planned + $object->date_shipping = $date_shipping; // Sending date $object->fk_delivery_address = $objectsrc->fk_delivery_address; $object->shipping_method_id = GETPOSTINT('shipping_method_id'); $object->tracking_number = GETPOST('tracking_number', 'alpha'); @@ -1037,6 +1040,15 @@ if ($action == 'create') { print "\n"; print ''; + // Date sending + print ''.$langs->trans("DateShipping").''; + print ''; + print img_picto('', 'action', 'class="pictofixedwidth"'); + $date_shipping = ($date_shipping ? $date_shipping : $object->date_shipping); // $date_shipping comes from GETPOST + print $form->selectDate($date_shipping ? $date_shipping : -1, 'date_shipping', 1, 1, 1); + print "\n"; + print ''; + // Note Public print ''.$langs->trans("NotePublic").''; print ''; @@ -2018,7 +2030,6 @@ if ($action == 'create') { print ''; - if ($action != 'editdate_livraison') { print ''; } @@ -2037,6 +2048,29 @@ if ($action == 'create') { print ''; print ''; + // Delivery sending date + print ''; + print ''; + // Weight print ''; } +// Date shipping +if (!empty($arrayfields['e.date_expedition']['checked'])) { + print ''; +} if (!empty($arrayfields['e.fk_shipping_method']['checked'])) { // Delivery method print ''; } if (!empty($arrayfields['l.date_delivery']['checked'])) { - // Date received + // Date reception print '\n"; + if (!$i) { + $totalarray['nbfield']++; + } + } if (!empty($arrayfields['e.fk_shipping_method']['checked'])) { // Get code using getLabelFromKey $code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code'); diff --git a/htdocs/langs/en_US/deliveries.lang b/htdocs/langs/en_US/deliveries.lang index 5eac14c4958..49bb1e31481 100644 --- a/htdocs/langs/en_US/deliveries.lang +++ b/htdocs/langs/en_US/deliveries.lang @@ -6,7 +6,8 @@ DeliveryOrder=Delivery receipt DeliveryDate=Delivery date CreateDeliveryOrder=Generate delivery receipt DeliveryStateSaved=Delivery state saved -SetDeliveryDate=Set shipping date +SetDeliveryDate=Set estimated delivery date +SetShippingDate=Set shipping date ValidateDeliveryReceipt=Validate delivery receipt ValidateDeliveryReceiptConfirm=Are you sure you want to validate this delivery receipt? DeleteDeliveryReceipt=Delete delivery receipt diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 9f648d5f706..eb9c16239cc 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -44,6 +44,7 @@ ConfirmCancelSending=Are you sure you want to cancel this shipment? DocumentModelMerou=Merou A5 model WarningNoQtyLeftToSend=Warning, no products waiting to be shipped. StatsOnShipmentsOnlyValidated=Statistics are only for validated shipments. Date used is the date of validation of shipment (planned delivery date is not always known) +DateShipping=Sending date DateDeliveryPlanned=Planned date of delivery RefDeliveryReceipt=Ref delivery receipt StatusReceipt=Status delivery receipt diff --git a/htdocs/langs/fr_FR/deliveries.lang b/htdocs/langs/fr_FR/deliveries.lang index 79b0a5d7735..3353abe7cb4 100644 --- a/htdocs/langs/fr_FR/deliveries.lang +++ b/htdocs/langs/fr_FR/deliveries.lang @@ -6,7 +6,8 @@ DeliveryOrder=Bon de réception DeliveryDate=Date de livraison CreateDeliveryOrder=Générer bon de réception DeliveryStateSaved=Le statut de livraison est enregistré -SetDeliveryDate=Définir la date d'expédition +SetDeliveryDate=Définir la date prévue de livraison +SetShippingDate=Définir la date d'expédition ValidateDeliveryReceipt=Valider le bon de livraison ValidateDeliveryReceiptConfirm=Êtes-vous sûr de vouloir valider ce bon de livraison ? DeleteDeliveryReceipt=Supprimer le bon de livraison diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index b3d5ae247ef..88fcfdbceff 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -44,6 +44,7 @@ ConfirmCancelSending=Êtes-vous sûr de vouloir annuler cette expédition ? DocumentModelMerou=Modèle Merou A5 WarningNoQtyLeftToSend=Alerte, aucun produit en attente d'expédition. StatsOnShipmentsOnlyValidated=Les statistiques ne prennent en compte que les envois validés. La date utilisée est celle qui est la date de validation de l'envoi (la date de réception prévue n'est pas nécessairement connue) +DateShipping=Date d’expédition DateDeliveryPlanned=Date prévue de livraison RefDeliveryReceipt=Ref bon de réception StatusReceipt=Status du bon de réception
'; print $langs->trans('DateDeliveryPlanned'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'
'; + print ''; + if ($action != 'editdate_shipping') { + print ''; + } + print '
'; + print $langs->trans('DateShipping'); + print 'id.'">'.img_edit($langs->trans('SetShippingDate'), 1).'
'; + print '
'; + if ($action == 'editdate_shipping') { + print '
'; + print ''; + print ''; + print $form->selectDate($object->date_shipping ? $object->date_shipping : -1, 'liv_', 1, 1, 0, "setdate_shipping", 1, 0); + print ''; + print '
'; + } else { + print $object->date_shipping ? dol_print_date($object->date_shipping, 'dayhour') : ' '; + } + print '
'; print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->hasRight('expedition', 'creer')); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 7ce4800e093..8a49d6139a6 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1206,6 +1206,9 @@ class Expedition extends CommonObject if (isset($this->model_pdf)) { $this->model_pdf = trim($this->model_pdf); } + if (!empty($this->date_expedition)) { + $this->date_shipping = $this->date_expedition; + } // Check parameters // Put here code to add control on parameters values @@ -1220,7 +1223,7 @@ class Expedition extends CommonObject $sql .= " fk_user_author = ".(isset($this->fk_user_author) ? $this->fk_user_author : "null").","; $sql .= " date_valid = ".(dol_strlen($this->date_valid) != 0 ? "'".$this->db->idate($this->date_valid)."'" : 'null').","; $sql .= " fk_user_valid = ".(isset($this->fk_user_valid) ? $this->fk_user_valid : "null").","; - $sql .= " date_expedition = ".(dol_strlen($this->date_expedition) != 0 ? "'".$this->db->idate($this->date_expedition)."'" : 'null').","; + $sql .= " date_expedition = ".(dol_strlen($this->date_shipping) != 0 ? "'".$this->db->idate($this->date_shipping)."'" : 'null').","; $sql .= " date_delivery = ".(dol_strlen($this->date_delivery) != 0 ? "'".$this->db->idate($this->date_delivery)."'" : 'null').","; $sql .= " fk_address = ".(isset($this->fk_delivery_address) ? $this->fk_delivery_address : "null").","; $sql .= " fk_shipping_method = ".((isset($this->shipping_method_id) && $this->shipping_method_id > 0) ? $this->shipping_method_id : "null").","; diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 141c0ff6161..e2cbfed00c5 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -77,6 +77,8 @@ $search_state = GETPOST("search_state", 'alpha'); $search_country = GETPOST("search_country", 'aZ09'); $search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma'); $search_billed = GETPOST("search_billed", 'intcomma'); +$search_dateshipping_start = dol_mktime(0, 0, 0, GETPOSTINT('search_dateshipping_startmonth'), GETPOSTINT('search_dateshipping_startday'), GETPOSTINT('search_dateshipping_startyear')); +$search_dateshipping_end = dol_mktime(23, 59, 59, GETPOSTINT('search_dateshipping_endmonth'), GETPOSTINT('search_dateshipping_endday'), GETPOSTINT('search_dateshipping_endyear')); $search_datedelivery_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datedelivery_startmonth'), GETPOSTINT('search_datedelivery_startday'), GETPOSTINT('search_datedelivery_startyear')); $search_datedelivery_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datedelivery_endmonth'), GETPOSTINT('search_datedelivery_endday'), GETPOSTINT('search_datedelivery_endyear')); $search_datereceipt_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datereceipt_startmonth'), GETPOSTINT('search_datereceipt_startday'), GETPOSTINT('search_datereceipt_startyear')); @@ -144,9 +146,10 @@ $arrayfields = array( 'country.code_iso' => array('label' => $langs->trans("Country"), 'checked' => 0, 'position' => 7), 'typent.code' => array('label' => $langs->trans("ThirdPartyType"), 'checked' => $checkedtypetiers, 'position' => 8), 'e.date_delivery' => array('label' => $langs->trans("DateDeliveryPlanned"), 'checked' => 1, 'position' => 9), - 'e.fk_shipping_method' => array('label' => $langs->trans('SendingMethod'), 'checked' => 1, 'position' => 10), - 'e.tracking_number' => array('label' => $langs->trans("TrackingNumber"), 'checked' => 1, 'position' => 11), - 'e.weight' => array('label' => $langs->trans("Weight"), 'checked' => 0, 'position' => 12), + 'e.date_expedition' => array('label' => $langs->trans("DateShipping"), 'checked' => 1, 'position' => 10), + 'e.fk_shipping_method' => array('label' => $langs->trans('SendingMethod'), 'checked' => 1, 'position' => 11), + 'e.tracking_number' => array('label' => $langs->trans("TrackingNumber"), 'checked' => 1, 'position' => 12), + 'e.weight' => array('label' => $langs->trans("Weight"), 'checked' => 0, 'position' => 13), 'e.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => 0, 'position' => 500), 'e.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => 0, 'position' => 500), 'e.fk_statut' => array('label' => $langs->trans("Status"), 'checked' => 1, 'position' => 1000), @@ -213,6 +216,8 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_shipping_method_ids = []; $search_type_thirdparty = ''; $search_billed = ''; + $search_dateshipping_start = ''; + $search_dateshipping_end = ''; $search_datedelivery_start = ''; $search_datedelivery_end = ''; $search_datereceipt_start = ''; @@ -567,6 +572,12 @@ if (empty($reshook)) { if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); } + if ($search_dateshipping_start) { + $param .= '&search_dateshipping_startday='.urlencode(dol_print_date($search_dateshipping_start, '%d')).'&search_dateshipping_startmonth='.urlencode(dol_print_date($search_dateshipping_start, '%m')).'&search_dateshipping_startyear='.urlencode(dol_print_date($search_dateshipping_start, '%Y')); + } + if ($search_dateshipping_end) { + $param .= '&search_dateshipping_endday='.urlencode(dol_print_date($search_dateshipping_end, '%d')).'&search_dateshipping_endmonth='.urlencode(dol_print_date($search_dateshipping_end, '%m')).'&search_dateshipping_endyear='.urlencode(dol_print_date($search_dateshipping_end, '%Y')); + } if ($search_datedelivery_start) { $param .= '&search_datedelivery_startday='.urlencode(dol_print_date($search_datedelivery_start, '%d')).'&search_datedelivery_startmonth='.urlencode(dol_print_date($search_datedelivery_start, '%m')).'&search_datedelivery_startyear='.urlencode(dol_print_date($search_datedelivery_start, '%Y')); } @@ -667,7 +678,7 @@ $sql = 'SELECT'; if ($search_all || $search_user > 0) { $sql = 'SELECT DISTINCT'; } -$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.signed_status, e.billed, e.tracking_number, e.fk_shipping_method,"; +$sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_expedition, e.date_delivery as delivery_date, e.fk_statut, e.signed_status, e.billed, e.tracking_number, e.fk_shipping_method,"; if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) { // Link for delivery fields ref and date. Does not duplicate the line because we should always have only 1 link or 0 per shipment $sql .= " l.date_delivery as date_reception,"; @@ -771,6 +782,12 @@ if ($search_company) { if ($search_ref_exp) { $sql .= natural_search('e.ref', $search_ref_exp); } +if ($search_dateshipping_start) { + $sql .= " AND e.date_expedition >= '".$db->idate($search_dateshipping_start)."'"; +} +if ($search_dateshipping_end) { + $sql .= " AND e.date_expedition <= '".$db->idate($search_dateshipping_end)."'"; +} if ($search_datedelivery_start) { $sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'"; } @@ -978,6 +995,12 @@ if ($search_zip) { if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty)); } +if ($search_dateshipping_start) { + $param .= '&search_dateshipping_startday='.urlencode(dol_print_date($search_dateshipping_start, '%d')).'&search_dateshipping_startmonth='.urlencode(dol_print_date($search_dateshipping_start, '%m')).'&search_dateshipping_startyear='.urlencode(dol_print_date($search_dateshipping_start, '%Y')); +} +if ($search_dateshipping_end) { + $param .= '&search_dateshipping_endday='.urlencode(dol_print_date($search_dateshipping_end, '%d')).'&search_dateshipping_endmonth='.urlencode(dol_print_date($search_dateshipping_end, '%m')).'&search_dateshipping_endyear='.urlencode(dol_print_date($search_dateshipping_end, '%Y')); +} if ($search_datedelivery_start) { $param .= '&search_datedelivery_startday='.urlencode(dol_print_date($search_datedelivery_start, '%d')).'&search_datedelivery_startmonth='.urlencode(dol_print_date($search_datedelivery_start, '%m')).'&search_datedelivery_startyear='.urlencode(dol_print_date($search_datedelivery_start, '%Y')); } @@ -1248,6 +1271,17 @@ if (!empty($arrayfields['e.date_delivery']['checked'])) { print ''; print ''; + print '
'; + print $form->selectDate($search_dateshipping_start ? $search_dateshipping_start : -1, 'search_dateshipping_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); + print '
'; + print '
'; + print $form->selectDate($search_dateshipping_end ? $search_dateshipping_end : -1, 'search_dateshipping_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); + print '
'; + print '
'; @@ -1268,7 +1302,7 @@ if (!empty($arrayfields['l.ref']['checked'])) { print ''; print '
'; print $form->selectDate($search_datereceipt_start ? $search_datereceipt_start : -1, 'search_datereceipt_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); @@ -1385,6 +1419,10 @@ if (!empty($arrayfields['e.date_delivery']['checked'])) { print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; } +if (!empty($arrayfields['e.date_expedition']['checked'])) { + print_liste_field_titre($arrayfields['e.date_expedition']['label'], $_SERVER["PHP_SELF"], "e.date_expedition", "", $param, '', $sortfield, $sortorder, 'center '); + $totalarray['nbfield']++; +} if (!empty($arrayfields['e.fk_shipping_method']['checked'])) { print_liste_field_titre($arrayfields['e.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "e.fk_shipping_method", "", $param, '', $sortfield, $sortorder, 'center '); $totalarray['nbfield']++; @@ -1602,6 +1640,15 @@ while ($i < $imaxinloop) { $totalarray['nbfield']++; } } + // Date shipping + if (!empty($arrayfields['e.date_expedition']['checked'])) { + print '
'; + print dol_print_date($db->jdate($obj->date_expedition), "dayhour"); + print "