public function pjActionIndex() { $this->checkLogin(); if ($this->isAdmin()) { if (isset($_POST['working_time'])) { $pjWorkingTimeModel = pjWorkingTimeModel::factory(); $arr = $pjWorkingTimeModel->find($_POST['location_id'])->getData(); $data = array(); $data['location_id'] = $_POST['location_id']; $types = array('p_' => 'pickup', 'd_' => 'delivery'); $weekDays = pjUtil::getWeekdays(); foreach ($types as $prefix => $type) { foreach ($weekDays as $day) { if (!isset($_POST[$prefix . $day . '_dayoff'])) { $data[$prefix . $day . '_from'] = $_POST[$prefix . $day . '_hour_from'] . ":" . $_POST[$prefix . $day . '_minute_from']; $data[$prefix . $day . '_to'] = $_POST[$prefix . $day . '_hour_to'] . ":" . $_POST[$prefix . $day . '_minute_to']; } } } if (count($arr) > 0) { $pjWorkingTimeModel->reset()->setAttributes(array('location_id' => $_POST['location_id']))->erase(); } $pjWorkingTimeModel->reset()->setAttributes($data)->insert(); pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminTime&action=pjActionIndex&id=" . $_POST['location_id'] . "&err=AT01"); } if (isset($_POST['custom_time'])) { $date = pjUtil::formatDate($_POST['date'], $this->option_arr['o_date_format']); $pjDateModel = pjDateModel::factory(); $pjDateModel->where('type', $_POST['type'])->where('date', $date)->eraseAll(); $data = array(); $data['location_id'] = $_POST['location_id']; $data['start_time'] = join(":", array($_POST['start_hour'], $_POST['start_minute'])); $data['end_time'] = join(":", array($_POST['end_hour'], $_POST['end_minute'])); $data['date'] = $date; $data['type'] = $_POST['type']; $data['is_dayoff'] = $_POST['is_dayoff']; $pjDateModel->reset()->setAttributes($data)->insert(); pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminTime&action=pjActionIndex&id=" . $_POST['location_id'] . "&err=AT02&tab_id=tabs-2"); } $arr = pjLocationModel::factory()->find($_GET['id'])->getData(); if (count($arr) === 0) { pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionIndex&err=AL08"); } $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjLocation'); $this->set('arr', $arr); $this->set('wt_arr', pjWorkingTimeModel::factory()->find($_GET['id'])->getData()); $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/'); $this->appendJs('additional-methods.js', PJ_THIRD_PARTY_PATH . 'validate/'); $this->appendJs('jquery.datagrid.js', PJ_FRAMEWORK_LIBS_PATH . 'pj/js/'); $this->appendJs('pjAdminTime.js'); } else { $this->set('status', 2); } }
public function pjActionIndex() { $this->checkLogin(); if ($this->isAdmin() || $this->isEditor()) { $user_id = $_SESSION['admin_user']['id']; $pjOrderModel = pjOrderModel::factory(); $cnt_delivery_orders = $pjOrderModel->where('user_id', $user_id)->where("type", "delivery")->where("DATE(t1.d_dt) = CURDATE()")->findCount()->getData(); $amount_delivery_orders = $pjOrderModel->reset()->select("SUM(total) AS amount")->where("type", "delivery")->where('user_id', $user_id)->where("DATE(t1.d_dt) = CURDATE()")->findAll()->getData(); $cnt_pickup_orders = $pjOrderModel->reset()->where('user_id', $user_id)->where("type", "pickup")->where("DATE(t1.p_dt) = CURDATE()")->findCount()->getData(); $amount_pickup_orders = $pjOrderModel->reset()->select("SUM(total) AS amount")->where('user_id', $user_id)->where("type", "pickup")->where("DATE(t1.p_dt) = CURDATE()")->findAll()->getData(); $cnt_orders = $pjOrderModel->reset()->where('user_id', $user_id)->findCount()->getData(); $amount_orders = $pjOrderModel->reset()->select("SUM(total) AS amount")->where('user_id', $user_id)->findAll()->getData(); $this->set('cnt_delivery_orders', $cnt_delivery_orders); $this->set('amount_delivery_orders', !empty($amount_delivery_orders) ? $amount_delivery_orders[0]['amount'] : 0); $this->set('cnt_pickup_orders', $cnt_pickup_orders); $this->set('amount_pickup_orders', !empty($amount_pickup_orders) ? $amount_pickup_orders[0]['amount'] : 0); $this->set('cnt_orders', $cnt_orders); $this->set('amount_orders', !empty($amount_orders) ? $amount_orders[0]['amount'] : 0); $latest_delivery = $pjOrderModel->reset()->join('pjClient', "t2.id=t1.client_id", 'left outer')->join('pjMultiLang', "t3.model='pjLocation' AND t3.foreign_id=t1.location_id AND t3.field='name' AND t3.locale='" . $this->getLocaleId() . "'", 'left outer')->select('t1.*, t2.c_name as client_name, t3.content as location')->where("type", "delivery")->where('t1.user_id', $user_id)->orderBy("d_dt DESC")->limit(6)->findAll()->getData(); $latest_pickup = $pjOrderModel->reset()->join('pjClient', "t2.id=t1.client_id", 'left outer')->join('pjMultiLang', "t3.model='pjLocation' AND t3.foreign_id=t1.location_id AND t3.field='name' AND t3.locale='" . $this->getLocaleId() . "'", 'left outer')->select('t1.*, t2.c_name as client_name, t3.content as location')->where('t1.user_id', $user_id)->where("type", "pickup")->orderBy("p_dt DESC")->limit(6)->findAll()->getData(); $this->set('latest_delivery', $latest_delivery); $this->set('latest_pickup', $latest_pickup); $location_arr = pjWorkingTimeModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.location_id AND t2.model = 'pjLocation' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select('t1.*, t2.content as location_title')->findAll()->getData(); $week_day = strtolower(date("l")); $current_time = date('H:i:s'); foreach ($location_arr as $k => $v) { if ($v['p_' . $week_day . '_from'] <= $current_time && $current_time <= $v['p_' . $week_day . '_to']) { $v['pickup'] = __('lblOpened', true); } else { $v['pickup'] = __('lblClosed', true); } if ($v['d_' . $week_day . '_from'] <= $current_time && $current_time <= $v['d_' . $week_day . '_to']) { $v['delivery'] = __('lblOpened', true); } else { $v['delivery'] = __('lblClosed', true); } $location_arr[$k] = $v; } $this->set('location_arr', $location_arr); } else { $this->set('status', 2); } }
public function pjActionDeleteLocationBulk() { $this->setAjax(true); if ($this->isXHR()) { if (isset($_POST['record']) && count($_POST['record']) > 0) { pjLocationModel::factory()->whereIn('id', $_POST['record'])->eraseAll(); pjMultiLangModel::factory()->where('model', 'pjLocation')->whereIn('foreign_id', $_POST['record'])->eraseAll(); pjLocationCoordModel::factory()->whereIn('location_id', $_POST['record'])->eraseAll(); pjWorkingTimeModel::factory()->whereIn('location_id', $_POST['record'])->eraseAll(); } } exit; }
public function pjActionLoad() { ob_start(); header("Content-Type: text/javascript; charset=utf-8"); if (isset($_GET['locale']) && $_GET['locale'] > 0) { $_SESSION[$this->defaultLocale] = (int) $_GET['locale']; $_SESSION[$this->defaultLangMenu] = 'hide'; } else { $_SESSION[$this->defaultLangMenu] = 'show'; } $days_off = array(); $w_arr = pjWorkingTimeModel::factory()->orderBy("t1.location_id ASC")->findAll()->getData(); foreach ($w_arr as $w) { if ($w['p_monday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 1; } if ($w['p_tuesday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 2; } if ($w['p_wednesday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 3; } if ($w['p_thursday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 4; } if ($w['p_friday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 5; } if ($w['p_saturday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 6; } if ($w['p_sunday_dayoff'] == 'T') { $days_off[$w['location_id']]['pickup'][] = 0; } if ($w['d_monday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 1; } if ($w['d_tuesday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 2; } if ($w['d_wednesday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 3; } if ($w['d_thursday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 4; } if ($w['d_friday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 5; } if ($w['d_saturday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 6; } if ($w['d_sunday_dayoff'] == 'T') { $days_off[$w['location_id']]['delivery'][] = 0; } } $this->set('days_off', $days_off); $dates_off = $dates_on = array(); $d_arr = pjDateModel::factory()->where("t1.date >= CURDATE()")->findAll()->getData(); foreach ($d_arr as $date) { if ($date['is_dayoff'] == 'T') { $dates_off[$date['location_id']][$date['type']][] = $date['date']; } else { $dates_on[$date['location_id']][$date['type']][] = $date['date']; } } $this->set('dates_on', $dates_on); $this->set('dates_off', $dates_off); }
public function getWorkingTime($date, $location_id, $type) { $date_arr = pjDateModel::factory()->getWorkingTime($date, $location_id, $type); if ($date_arr === false) { $wt_arr = pjWorkingTimeModel::factory()->getWorkingTime($location_id, $type, $date); if (count($wt_arr) == 0) { return false; } $t_arr = $wt_arr; } else { if (count($date_arr) == 0) { return false; } $t_arr = $date_arr; } return $t_arr; }