public function displayAjaxshowCalendar() { if ($this->errors) { $this->ajaxDie(Tools::jsonEncode(array('hasError' => true, 'errors' => $this->errors))); } if ($this->ajax_refresh) { $this->ajaxDie(Tools::jsonEncode(array('refresh' => true))); } $this->setTemplate('available_calendar.tpl'); $id_shop = Tools::getValue('ids'); $shop = new AphStore($id_shop, Context::getContext()->language->id); $shop->hours = json_decode($shop->hours, true); $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT'); $dates = array(); $date = $dday = Tools::getValue('date'); for ($i = 2; $i > 0; $i--) { if (date('Y-m-d', strtotime('-' . $i . ' day')) >= date('Y-m-d')) { $dates[] = date('Y-m-d', strtotime('-' . $i . ' day')); } } $dates = array($date); for ($d = sizeof($dates), $i = 1; $d < 5; $d++, $i++) { $dates[] = date('Y-m-d', strtotime('+' . $i . ' day')); } $id_product = Tools::getValue('id_product'); $product = new Product($id_product, true, Context::getContext()->language->id, $id_shop); $days = array(); foreach ($dates as $day) { $days[$day] = array('date' => $day, 'date_ts' => strtotime($day), 'date_lang' => date('d/m/Y', strtotime($day)), 'class' => 'store_opened', 'status' => 'closed'); $hour = $shop->hours[strtolower(date('D', $days[$day]['date_ts']))]; $time_start = $hour['op']; $time_end = $hour['cl']; if ($hour['op'] == 'CLOSE' || $hour['cl'] == 'CLOSE') { $days[$day]['status'] = 'closed'; } if ($days[$day]['status'] == 'closed') { $shop_availability = AphAvailability::getByDate($id_shop, 0, $day, 1); if (!empty($shop_availability)) { $days[$day]['status'] = 'opened'; } } else { $shop_availability = AphAvailability::getByDate($id_shop, 0, $day, -1); if (!empty($shop_availability)) { $days[$day]['status'] = 'closed'; } } if ($days[$day]['status'] == 'closed') { $days[$day]['class'] = 'store_closed'; break; } $shop_offers = AphOffer::getByDate($id_shop, $id_product, $day, 1); if (!empty($shop_offers)) { $days[$day]['status'] = 'promoted'; $days[$day]['class'] = 'store_promoted'; } $specific_prices = AphSpecificPrice::getByDate($id_shop, $id_currency, $shop->id_country, 0, $day, 0, $id_product, date('w', $day)); if (!empty($specific_prices)) { $specific_price = new AphSpecificPrice($specific_prices[0]['id_specific_price']); } $price = $product->getPrice(true, null, $decimals = 6, null, false, true, 1, true, null, null, null, $specific_price, false, false, null, true); $days[$day]['price'] = $price; $days[$day]['price_from'] = $price; } $this->context->smarty->assign(array('days' => $days, 'dday' => $dday)); //$this->ajaxDie($this->context->smarty->fetch()); $this->ajaxDie($this->createTemplate('availability_calendar.tpl')->fetch()); }
public function ajaxshowCalendar() { $id_lang = Context::getContext()->language->id; $id_shop = Tools::getValue('ids'); $shop = new AphStore($id_shop, Context::getContext()->language->id); $shop->hours = json_decode($shop->hours, true); $id_currency = Validate::isLoadedObject(Context::getContext()->currency) ? (int) Context::getContext()->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT'); $context = Context::getContext(); $context->shop->id = $id_shop; $dates = array(); $dday = Tools::getValue('date'); for ($i = 2; $i > 0; $i--) { if (date('Y-m-d', strtotime('-' . $i . ' day', strtotime($dday))) >= date('Y-m-d')) { $dates[] = date('Y-m-d', strtotime('-' . $i . ' day', strtotime($dday))); } } $dates[] = $dday; for ($d = sizeof($dates), $i = 1; $d < 5; $d++, $i++) { $dates[] = date('Y-m-d', strtotime('+' . $i . ' day', strtotime($dday))); } $id_product = Tools::getValue('id_product'); $product = new Product($id_product, true, $id_lang, $id_shop); $product_need_tools = false; $product_need_employees = true; $service_duration = 0; $_features = Product::getFrontFeaturesStatic($id_lang, $id_product); foreach ($_features as &$feature) { if ($product->id_service_duration > 0 && $feature['id_feature'] == $product->id_service_duration) { $service_duration = (int) substr($feature['value'], 0, -1); } if ($product->id_service_duration < 1 && $feature['id_feature'] == Configuration::get('APH_FEATURE_DURATION')) { $service_duration = (int) substr($feature['value'], 0, -1); } if ($feature['id_feature'] == Configuration::get('APH_FEATURE_SERVICE_BY')) { if ((int) $feature['value'] == (int) Configuration::get('APH_FEATURE_SERVICE_BY_NO_EMPLOYEE')) { $product_need_employees = false; } } $service_duration = (int) substr($feature['value'], 0, -1); } $id_tool = 0; $necessary_quantity_of_tool = 0; $products_use_this_tool = array(); $tool = AphTool::getByShopAndProduct($id_shop, $id_product); if (!empty($tool)) { $id_tool = $tool[0]['id_tool']; $necessary_quantity_of_tool = $tool[0]['quantity']; $product_need_tools = true; $_products = AphTool::getProducts($id_tool); if (!empty($_products)) { foreach ($_products as &$_product) { $products_use_this_tool[] = $_product['id_product']; } } } $employees = array(); if ($product_need_employees) { $_employees = AphEmployeeProduct::getEmployeesByShopAndProduct($id_shop, $id_product); foreach ($_employees as &$employee) { $employees[] = $employee['id_employee']; } } $time_slice = (int) Configuration::get('APH_CALENDAR_TIME_SLICE_ONLINE'); if ($service_duration > $time_slice) { for ($t = 1; $t <= 4; $t++) { if ($time_slice * $t >= $service_duration) { $time_slice = $time_slice * $t; break; } } } /*$attributues_by_value = array(); $attributues = $product->getAttributesResume($id_lang, ': ', ', '); foreach ($attributues as &$attribute) { list($giorno, $orario) = explode(', ', $attribute['attribute_designation']); list(, $giorno) = explode(': ', $giorno); list(, $giorno) = explode(' ', $giorno); list(, $orario) = explode(': ', $orario); list(, $orario) = explode(' ', $orario); if (!array_key_exists($giorno, $attributues_by_value)) $attributues_by_value[$giorno] = array(); $attributues_by_value[$giorno][strval($orario)] = $attribute['id_product_attribute']; }*/ $first_day = $last_day = NULL; $days = array(); foreach ($dates as $day) { if (empty($first_day)) { $first_day = $day; } $last_day = $day; $days[$day] = array('date' => $day, 'date_ts' => strtotime($day), 'class' => 'store_opened', 'status' => 'opened', 'available' => true, 'price_from' => $product->price, 'times_tot' => 0, 'times_not_available' => 0, 'times_full' => 0, 'times' => array()); $days[$day]['date_lang'] = date('d/m/Y', $days[$day]['date_ts']); $days[$day]['week_day'] = date('w', $days[$day]['date_ts']); $days[$day]['week_day_lang'] = $this->week_days[(int) date('w', $days[$day]['date_ts'])]; $days[$day]['month_lang'] = $this->months[(int) date('w', $days[$day]['date_ts'])]; if (!empty($shop->hours[date('w', $days[$day]['date_ts'])])) { $hour_1 = $shop->hours[date('w', $days[$day]['date_ts'])][1]; $hour_2 = $shop->hours[date('w', $days[$day]['date_ts'])][2]; if ($hour_1['o'] == 'X' && $hour_1['c'] == 'X' && $hour_2['o'] == 'X' && $hour_2['c'] == 'X') { $days[$day]['status'] = 'closed'; $days[$day]['available'] = false; } else { $time_start = $hour_1['o'] == 'X' ? $hour_2['o'] : $hour_1['o']; $time_end = $hour_2['c'] == 'X' ? $hour_1['c'] : $hour_2['c']; $pause_start = $hour_1['c'] == 'X' ? false : $hour_1['c']; $pause_end = $hour_2['o'] == 'X' ? false : $hour_2['o']; } } else { $days[$day]['status'] = 'closed'; $days[$day]['available'] = false; } if (!empty($shop->rights_hasCalendar)) { if ($days[$day]['status'] == 'closed') { // apertura straordinaria $shop_availability = AphAvailability::getByDate($id_shop, 0, $day, 1); if (!empty($shop_availability)) { $days[$day]['status'] = 'opened'; $days[$day]['available'] = true; } } else { // chiusura straordinaria $shop_availability = AphAvailability::getByDate($id_shop, 0, $day, -1); if (!empty($shop_availability)) { $days[$day]['status'] = 'closed'; $days[$day]['available'] = false; } } if ($days[$day]['status'] == 'closed') { $days[$day]['class'] = 'store_closed'; $days[$day]['available'] = false; continue; } } // almeno un'offerta disponibile nel giorno $shop_offers = AphOffer::getByDate($id_shop, $id_product, $day, 1); if (!empty($shop_offers)) { $days[$day]['status'] = 'promoted'; $days[$day]['class'] = 'store_promoted'; } print_r($days[$day]['available']); if (!empty($days[$day]['available'])) { $times = array(); for ($hours = substr($time_start, 0, 2); $hours < substr($time_end, 0, 2); $hours++) { // the interval for hours is '1' for ($mins = 0; $mins < 60; $mins += $time_slice) { // the interval for mins is 'APH_CALENDAR_TIME_SLICE' $t = str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($mins, 2, '0', STR_PAD_LEFT); // se sto valutanto l'orario nella pausa allora lo ignoro if (!empty($pause_start) && !empty($pause_end) && $t >= $pause_start && $t < $pause_end) { continue; } $times[$t] = array('time' => $t, 'available' => false, 'status' => 'available', 'class' => $days[$day]['class']); $times[$t]['from'] = $t; $time = new DateTime($day . ' ' . $times[$t]['from']); $time->add(new DateInterval('PT' . $service_duration . 'M')); $times[$t]['to'] = $time->format('H:i'); if ($times[$t]['to'] > $time_end) { $times[$t]['available'] = false; $times[$t]['status'] = 'available'; $times[$t]['class'] .= ' time_notavailable'; $days[$day]['times_not_available']++; } $days[$day]['times_tot']++; if (!empty($shop->rights_hasCalendar)) { $completed_orders = AphOrderDetail::getBetweenTimes($id_shop, 0, 0, $days[$day]['date_ts'], $times[$t]['from'], $times[$t]['to']); if ($product_need_tools && !empty($products_use_this_tool)) { $completed_orders_about_tool = AphOrderDetail::getBetweenTimes($id_shop, 0, $products_use_this_tool, $days[$day]['date_ts'], $times[$t]['from'], $times[$t]['to']); $t = AphTool::getByDate($id_tool, $available_date); $tool_is_availability = !empty($t) ? true : false; } else { $completed_orders_about_tool = array(); } $availabilies_of_shop = AphAvailability::getBetweenTimes($id_shop, 0, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 1); $not_availabilies_of_shop = AphAvailability::getBetweenTimes($id_shop, 0, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 0); if ($product_need_employees && empty($not_availabilies_of_shop)) { $working_employees = AphWorkingDay::getByEmployeeAndDateBetweenTimes($id_shop, $employees, $day, $times[$t]['from'], $times[$t]['to'], 1); $availabilies_of_employees = AphAvailability::getBetweenTimes($id_shop, $employees, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 1); $not_availabilies_of_employees = AphAvailability::getBetweenTimes($id_shop, $employees, strtotime($day . ' ' . $times[$t]['from']), strtotime($day . ' ' . $times[$t]['to']), 0); } else { $working_employees = $availabilies_of_employees = $not_availabilies_of_employees = array(); } } // chiusura straordinaria if (!empty($not_availabilies_of_shop)) { $times[$t]['available'] = false; $times[$t]['status'] = 'closed'; $times[$t]['class'] .= ' time_closed'; $days[$day]['times_not_available']++; continue; } // slot di tempo esaurito per mancanza di dipendenti if ($product_need_employees && !empty($completed_orders) && !empty($working_employees) && sizeof($completed_orders) >= sizeof($working_employees) - sizeof($not_availabilies_of_employees)) { $times[$t]['available'] = false; $times[$t]['status'] = 'full'; $times[$t]['class'] .= ' time_full'; $days[$day]['times_full']++; continue; } // slot di tempo esaurito per mancanza di macchinari if ($product_need_tools && !$tool_is_availability || !empty($necessary_quantity_of_tool) && !empty($completed_orders_about_tool) && sizeof($completed_orders_about_tool) >= $necessary_quantity_of_tool) { $times[$t]['available'] = false; $times[$t]['status'] = 'full'; $times[$t]['class'] .= ' time_full'; $days[$day]['times_full']++; continue; } // apertura straordinaria (i macchinari sono sempre disponibili) if ($product_need_employees && !empty($availabilies_of_employees) && !empty($completed_orders) && !empty($availabilies_of_employees) && sizeof($completed_orders) >= sizeof($availabilies_of_employees) - sizeof($not_availabilies_of_employees)) { $times[$t]['available'] = false; $times[$t]['status'] = 'full'; $times[$t]['class'] .= ' time_full'; $days[$day]['times_full']++; continue; } $times[$t]['available'] = true; $times[$t]['status'] = 'available'; $times[$t]['class'] .= ' time_available'; if (!empty($times[$t]['available'])) { //error_log(var_export(__LINE__,true)); //$price = Product::getPriceStatic($id_product, true, 0, 2, null, false, true, 1, false, null, null, null, $specific_price, true, true, $context, true, $day, $times[$t]['from'], $times[$t]['to']); //$times[$t]['price'] = $price; $times[$t]['price'] = 0; $times[$t]['price_label'] = Tools::displayPrice($times[$t]['price'], $id_currency); if ($times[$t]['price'] < $days[$day]['price_from']) { $days[$day]['price_from'] = $times[$t]['price']; } } } } $days[$day]['times'] = $times; $days[$day]['price_from_label'] = Tools::displayPrice($days[$day]['price_from'], $id_currency); if ($days[$day]['times_full'] == $days[$day]['times']) { $days[$day]['available'] = false; $days[$day]['status'] = 'full'; $days[$day]['class'] = 'store_full'; } elseif ($days[$day]['times_not_available'] == $days[$day]['times']) { $days[$day]['available'] = false; $days[$day]['status'] = 'closed'; $days[$day]['class'] = 'store_closed'; } } } $jsVars = array(); $jsVars['calendar_params'] = array('ajax' => 1, 'ajaxCall' => 'ajaxshowCalendar', 'id_product' => $id_product, 'ids' => $id_shop, 'date' => $dday, 'id_city' => empty($id_city) ? $shop->id_city : $id_city); $this->context->smarty->assign(array('days' => $days, 'dday' => $dday, 'first_day' => $days[$first_day], 'last_day' => $days[$last_day], 'jsVars' => $jsVars)); // $jsVars = array( // 'language' => $this->context->language->iso_code, // 'slotDuration' => '00:'.Configuration::get('APH_CALENDAR_TIME_SLICE').':00' // ); // $this->content .= '<script>var admin_aphcalendar = '.json_encode($jsVars).';</script>'; return $this->display(__FILE__, 'availability_calendar.tpl', $this->getCacheId('blockmobilecart-column')); }
public function ajaxProcessGetEvents() { $shop = new AphStore((int) Context::getContext()->shop->id); $return = $events = array(); $AphAvailability = new AphAvailability(); $availabilities_of_shop = $AphAvailability->getBetweenDates((int) Context::getContext()->shop->id, 0, Tools::getValue('start'), Tools::getValue('end')); if (!empty($availabilities_of_shop) && is_array($availabilities_of_shop)) { foreach ($availabilities_of_shop as $availability) { /* // con badge $title = '<span class="badge"><i class="icon-'.((!empty($availability['available'])) ? 'check' : 'remove').'"></i> '.((!empty($availability['available'])) ? $this->l('Negozio aperto') : $this->l('Negozio chiuso')).'</span>'; $description = ((!empty($availability['available'])) ? $this->l('Negozio aperto') : $this->l('Negozio chiuso')); */ $title = !empty($availability['available']) ? $this->l('Negozio aperto') : $this->l('Negozio chiuso'); $events[] = array('id' => $availability['id_availability'], 'title' => $title, 'allDay' => true, 'start' => str_replace(' ', 'T', $availability['from']), 'end' => str_replace(' ', 'T', $availability['to']), 'object_id' => $availability['id_availability'], 'object_typology' => 'availability', 'className' => !empty($availability['available']) ? 'store_opened' : 'store_closed', 'backgroundColor' => $shop->bg_color, 'borderColor' => $shop->bg_color, 'textColor' => $shop->text_color); } } $employees = array(); if (Tools::getValue('employees') != '') { $employees = explode(';', Tools::getValue('employees')); } if (!empty($employees)) { $AphAvailability = new AphAvailability(); foreach ($employees as $employee) { $emp = new AphEmployeeProduct($employee); $availabilities_of_employee = $AphAvailability->getBetweenDates((int) Context::getContext()->shop->id, $employee, Tools::getValue('start'), Tools::getValue('end')); if (!empty($availabilities_of_employee) && is_array($availabilities_of_employee)) { foreach ($availabilities_of_employee as $availability) { $allDay = substr($availability['from'], 11) == '00:00:00' && substr($availability['to'], 11) == '00:00:00' ? true : false; $employee = $availability['fullName']; $title = !empty($availability['available']) ? $this->l('%s disponibile') : $this->l('%s non disponibile'); $title = sprintf($title, $employee); /* // con badge $title = '<span class="badge"><i class="icon-'.((!empty($availability['available'])) ? 'check' : 'remove').'"></i> '.$title.'</span>'; $description = (!empty($availability['available'])) ? $this->l('%s disponibile dal %s al %s') : $this->l('%s non disponibile dal %s al %s'); $description = sprintf($description, $employee, Tools::displayDate( $availability['from'], (int)Context::getContext()->language->id, !$allDay ), Tools::displayDate( $availability['to'], (int)Context::getContext()->language->id, !$allDay ) ); */ $events[] = array('id' => $availability['id_availability'], 'title' => $title, 'allDay' => $allDay, 'start' => str_replace(' ', 'T', $availability['from']), 'end' => str_replace(' ', 'T', $availability['to']), 'object_id' => $availability['id_availability'], 'object_typology' => 'availability', 'className' => !empty($availability['available']) ? 'employee_available' : 'employee_navailable', 'backgroundColor' => $emp->bg_color, 'borderColor' => $emp->bg_color, 'textColor' => $emp->text_color); } } } } $orders = Order::getOrderIdsByStatus(Configuration::get('APH_RESERVATION_OFFLINE_STATUS')); if (!empty($orders)) { foreach ($orders as &$id_order) { $order = new Order($id_order); $customer = new Customer($order->id_customer); $address = new Address($order->id_address_invoice); $order_details = AphOrderDetail::getList($id_order); if (!empty($order_details) && is_array($order_details)) { foreach ($order_details as &$order_detail) { if (intval($order_detail['id_employee']) > 0 && (empty($employees) || is_array($employees) && !in_array(intval($order_detail['id_employee']), $employees))) { continue; } $employee = NULL; if (intval($order_detail['id_employee']) > 0) { $employee = new AphEmployeeProduct($order_detail['id_employee']); } $title = '' . $order_detail['product_name'] . '' . (!empty($employee) ? '<br/>' . $employee->fullName : ''); $events[] = array('id' => $order_detail['id_order_detail'], 'title' => $title, 'product' => $order_detail['product_name'], 'employee' => !empty($employee) ? array('fullName' => $employee->fullName) : array(), 'customer' => array('fullName' => $address->firstname . (!empty($address->lastname) ? ' ' . $address->lastname : ''), 'phone' => (!empty($address->phone) ? ' T ' . $address->phone : '') . (!empty($address->phone_mobile) ? ' C ' . $address->phone_mobile : ''), 'email' => $customer->email), 'allDay' => false, 'start' => $order_detail['delivery_date'] . 'T' . $order_detail['delivery_time_from'], 'end' => $order_detail['delivery_date'] . 'T' . $order_detail['delivery_time_to'], 'object_id' => $order_detail['id_order_detail'], 'object_typology' => 'order', 'className' => 'order', 'backgroundColor' => !empty($employee) ? $employee->bg_color : $shop->bg_color, 'borderColor' => !empty($employee) ? $employee->bg_color : $shop->bg_color, 'textColor' => !empty($employee) ? $employee->text_color : $shop->text_color); } } } } $return['events'] = $events; die(Tools::jsonEncode($return)); }