/** * Converts date to string, using Culture and global timezone settings * * @param Context\Culture $culture Culture contains datetime format * @return string */ public function toString(Context\Culture $culture = null) { if (\CTimeZone::Enabled()) { $userTime = clone $this; $userTime->toUserTime(); $format = static::getFormat($culture); return $userTime->format($format); } else { return parent::toString($culture); } }
/** * @param bool $error * @param bool $needRecalculate * @return mixed */ protected static function prepareData($error = false, $needRecalculate = true) { global $USER; static $users = array(); $result['SHIPMENT'] = array(); if ($error) { $fields = self::$defaultFields; } else { $fields = self::$shipment->getFieldValues(); $fields['DELIVERY_STORE_ID'] = self::$shipment->getStoreId(); $fields["EXTRA_SERVICES"] = self::$shipment->getExtraServices(); $fields["STORE"] = self::$shipment->getStoreId(); } $date = new Date($fields['DELIVERY_DOC_DATE']); $fields['DELIVERY_DOC_DATE'] = $date->toString(); $empDeductedId = $fields['EMP_DEDUCTED_ID']; if ($empDeductedId > 0) { if (!array_key_exists($empDeductedId, $users)) { $users[$empDeductedId] = $USER->GetByID($empDeductedId)->Fetch(); } $fields['EMP_DEDUCTED_ID_NAME'] = $users[$empDeductedId]['NAME']; $fields['EMP_DEDUCTED_ID_LAST_NAME'] = $users[$empDeductedId]['LAST_NAME']; } $empAllowDeliveryId = $fields['EMP_ALLOW_DELIVERY_ID']; if ($empAllowDeliveryId > 0) { if (!array_key_exists($empAllowDeliveryId, $users)) { $users[$empAllowDeliveryId] = $USER->GetByID($empAllowDeliveryId)->Fetch(); } $fields['EMP_ALLOW_DELIVERY_ID_NAME'] = $users[$empAllowDeliveryId]['NAME']; $fields['EMP_ALLOW_DELIVERY_ID_LAST_NAME'] = $users[$empAllowDeliveryId]['LAST_NAME']; } $empCanceledId = $fields['EMP_CANCELED_ID']; if ($empCanceledId > 0) { if (!array_key_exists($empCanceledId, $users)) { $users[$empCanceledId] = $USER->GetByID($empCanceledId)->Fetch(); } $fields['EMP_CANCELLED_ID_NAME'] = $users[$empCanceledId]['NAME']; $fields['EMP_CANCELLED_ID_LAST_NAME'] = $users[$empCanceledId]['LAST_NAME']; } $empMarkedId = $fields['EMP_MARKED_ID']; if ($empMarkedId > 0) { if (!array_key_exists($empMarkedId, $users)) { $users[$empMarkedId] = $USER->GetByID($empMarkedId)->Fetch(); } $fields['EMP_MARKED_ID_NAME'] = $users[$empMarkedId]['NAME']; $fields['EMP_MARKED_ID_LAST_NAME'] = $users[$empMarkedId]['LAST_NAME']; } /** @var \Bitrix\Sale\Order $order */ $order = self::$shipment->getCollection()->getOrder(); $fields['CURRENCY'] = $order->getCurrency(); $fields['CUSTOM_PRICE'] = self::getDeliveryPrice(self::$shipment); if ($fields['CUSTOM_PRICE_DELIVERY'] == 'Y' && $fields['ID'] <= 0) { $fields['BASE_PRICE_DELIVERY'] = self::$shipment->getField('BASE_PRICE_DELIVERY'); } $discounts = OrderEdit::getDiscountsApplyResult($order, $needRecalculate); $shipmentIds = $order->getDiscount()->getShipmentsIds(); foreach ($shipmentIds as $shipmentId) { if ($shipmentId == self::$shipment->getId()) { $fields['DISCOUNTS'] = $discounts; } } $result['SHIPMENT'][] = $fields; return $result; }
public static function getMissedPeriods(array $stats, $dateStart, $dateFinish) { $missedPeriods = array(); $datePrevoius = false; $checkDate = new Date($dateStart); $dateCurrent = new Date($dateStart); $dateFinish = new Date($dateFinish); while ($dateCurrent->getTimestamp() <= $dateFinish->getTimestamp()) { if (!array_key_exists($dateCurrent->toString(), $stats)) { if (!$datePrevoius || $dateCurrent->getTimestamp() >= $checkDate->getTimestamp()) { $missedPeriods[] = array($dateCurrent->toString(), $dateCurrent->toString()); $checkDate = new Date($dateCurrent->toString()); $checkDate->add("+" . YandexDirectLive::MAX_STAT_DAYS_DELTA . " days"); $datePrevoius = true; } else { $missedPeriods[count($missedPeriods) - 1][1] = $dateCurrent->toString(); } } else { $datePrevoius = false; } $dateCurrent->add("+1 days"); } return $missedPeriods; }