diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 532b7ae411ebb..38e18e2302c97 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -560,6 +560,14 @@ if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } + } elseif ($action == 'setdate_shipping' && $user->hasRight('expedition', 'creer')) { + $dateshipping = dol_mktime(GETPOSTINT('ship_hour'), GETPOSTINT('ship_min'), 0, GETPOSTINT('ship_month'), GETPOSTINT('ship_day'), GETPOSTINT('ship_year')); + + $object->fetch($id); + $result = $object->setShippingDate($user, $dateshipping); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } elseif (in_array($action, array('settracking_number', 'settracking_url', 'settrueWeight', 'settrueWidth', 'settrueHeight', 'settrueDepth', 'setshipping_method_id')) && $user->hasRight('expedition', 'creer')) { // Action update $error = 0; @@ -2061,10 +2069,10 @@ print ''; print ''; if ($action == 'editdate_shipping') { - print '
'; + print ''; print ''; - print ''; - print $form->selectDate($object->date_shipping ? $object->date_shipping : -1, 'liv_', 1, 1, 0, "setdate_shipping", 1, 0); + print ''; + print $form->selectDate($object->date_shipping ? $object->date_shipping : -1, 'ship_', 1, 1, 0, "setdate_shipping", 1, 0); print ''; print '
'; } else { diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 8a49d6139a6b8..5193c3cde90d7 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2223,6 +2223,34 @@ public function setDeliveryDate($user, $delivery_date) } } + /** + * Set the shipping date + * + * @param User $user Object user that modify + * @param integer $shipping_date Date of shipping + * @return int Return integer <0 if KO, >0 if OK + */ + public function setShippingDate($user, $shipping_date) + { + if ($user->hasRight('expedition', 'creer')) { + $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; + $sql .= " SET date_expedition = ".($shipping_date ? "'".$this->db->idate($shipping_date)."'" : 'null'); + $sql .= " WHERE rowid = ".((int) $this->id); + + dol_syslog(get_class($this)."::setShippingDate", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $this->date_shipping = $shipping_date; + return 1; + } else { + $this->error = $this->db->error(); + return -1; + } + } else { + return -2; + } + } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch deliveries method and return an array. Load array this->meths(rowid=>label).