public function pjActionUpdate() { $this->checkLogin(); if ($this->isAdmin() || $this->isEditor()) { if (isset($_POST['order_update'])) { $pjOrderModel = pjOrderModel::factory(); $pjOrderItemModel = pjOrderItemModel::factory(); $pjProductPriceModel = pjProductPriceModel::factory(); $pjExtraModel = pjExtraModel::factory(); $pjProductModel = pjProductModel::factory(); $arr = $pjOrderModel->find($_POST['id'])->getData(); if (empty($arr)) { pjUtil::redirect($_SERVER['PHP_SELF'] . "?controller=pjAdminOrders&action=pjActionIndex&err=AR08"); } if (isset($_POST['product_id']) && count($_POST['product_id']) > 0) { $keys = array_keys($_POST['product_id']); $pjOrderItemModel->reset()->where('order_id', $_POST['id'])->whereNotIn('hash', $keys)->eraseAll(); $pjOrderItemModel->reset()->where('order_id', $_POST['id'])->where('type', 'extra')->eraseAll(); foreach ($_POST['product_id'] as $k => $pid) { $product = $pjProductModel->reset()->find($pid)->getData(); $price = 0; $price_id = ":NULL"; if ($product['set_different_sizes'] == 'T') { $price_id = $_POST['price_id'][$k]; $price_arr = $pjProductPriceModel->reset()->find($price_id)->getData(); if ($price_arr) { $price = $price_arr['price']; } } else { $price = $product['price']; } if (strpos($k, 'new_') === 0) { $hash = md5(uniqid(rand(), true)); $oid = $pjOrderItemModel->reset()->setAttributes(array('order_id' => $_POST['id'], 'foreign_id' => $pid, 'type' => 'product', 'hash' => $hash, 'price_id' => $price_id, 'price' => $price, 'cnt' => $_POST['cnt'][$k]))->insert()->getInsertId(); if ($oid !== false && (int) $oid > 0) { if (isset($_POST['extra_id']) && isset($_POST['extra_id'][$k])) { foreach ($_POST['extra_id'][$k] as $i => $eid) { $extra_price = 0; $extra_arr = $pjExtraModel->reset()->find($eid)->getData(); if (!empty($extra_arr) && !empty($extra_arr['price'])) { $extra_price = $extra_arr['price']; } $pjOrderItemModel->reset()->setAttributes(array('order_id' => $_POST['id'], 'foreign_id' => $eid, 'type' => 'extra', 'hash' => $hash, 'price_id' => ':NULL', 'price' => $extra_price, 'cnt' => $_POST['extra_cnt'][$k][$i]))->insert(); } } } } else { $pjOrderItemModel->reset()->where('hash', $k)->where('type', 'product')->limit(1)->modifyAll(array('foreign_id' => $pid, 'cnt' => $_POST['cnt'][$k], 'price_id' => $price_id, 'price' => $price)); if (isset($_POST['extra_id']) && isset($_POST['extra_id'][$k])) { foreach ($_POST['extra_id'][$k] as $i => $eid) { $extra_price = 0; $extra_arr = $pjExtraModel->reset()->find($eid)->getData(); if (!empty($extra_arr) && !empty($extra_arr['price'])) { $extra_price = $extra_arr['price']; } $pjOrderItemModel->reset()->setAttributes(array('order_id' => $_POST['id'], 'foreign_id' => $eid, 'type' => 'extra', 'hash' => $k, 'price_id' => ':NULL', 'price' => $extra_price, 'cnt' => $_POST['extra_cnt'][$k][$i]))->insert(); } } } } } $data = array(); $data['ip'] = pjUtil::getClientIp(); switch ($_POST['type']) { case 'pickup': if (!empty($_POST['p_dt'])) { $date_time = $_POST['p_dt']; if (count(explode(" ", $date_time)) == 3) { list($_date, $_time, $_period) = explode(" ", $date_time); $time = pjUtil::formatTime($_time . ' ' . $_period, $this->option_arr['o_time_format']); } else { list($_date, $_time) = explode(" ", $date_time); $time = pjUtil::formatTime($_time, $this->option_arr['o_time_format']); } unset($_POST['p_dt']); unset($_POST['d_dt']); $data['p_dt'] = pjUtil::formatDate($_date, $this->option_arr['o_date_format']) . ' ' . $time; } if (isset($_POST['p_location_id']) && (int) $_POST['p_location_id'] > 0) { $data['location_id'] = $_POST['p_location_id']; } break; case 'delivery': if (!empty($_POST['d_dt'])) { $date_time = $_POST['d_dt']; if (count(explode(" ", $date_time)) == 3) { list($_date, $_time, $_period) = explode(" ", $date_time); $time = pjUtil::formatTime($_time . ' ' . $_period, $this->option_arr['o_time_format']); } else { list($_date, $_time) = explode(" ", $date_time); $time = pjUtil::formatTime($_time, $this->option_arr['o_time_format']); } unset($_POST['p_dt']); unset($_POST['d_dt']); $data['d_dt'] = pjUtil::formatDate($_date, $this->option_arr['o_date_format']) . ' ' . $time; } if (isset($_POST['d_location_id']) && (int) $_POST['d_location_id'] > 0) { $data['location_id'] = $_POST['d_location_id']; } break; } if ($_POST['payment_method'] == 'creditcard') { $data['cc_exp'] = $_POST['cc_exp_month'] . "/" . $_POST['cc_exp_year']; } $pjOrderModel->reset()->where('id', $_POST['id'])->limit(1)->modifyAll(array_merge($_POST, $data)); $err = 'AR01'; pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminOrders&action=pjActionIndex&err={$err}"); } else { $arr = pjOrderModel::factory()->join('pjClient', "t2.id=t1.client_id", 'left outer')->select('t1.*,t2.c_name as client_name')->find($_GET['id'])->getData(); if (count($arr) <= 0) { pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminOrders&action=pjActionIndex&err=AR08"); } $this->set('arr', $arr); $country_arr = pjCountryModel::factory()->select('t1.id, t2.content AS country_title')->join('pjMultiLang', "t2.model='pjCountry' AND t2.foreign_id=t1.id AND t2.field='name' AND t2.locale='" . $this->getLocaleId() . "'", 'left outer')->orderBy('`country_title` ASC')->findAll()->getData(); $this->set('country_arr', $country_arr); $product_arr = pjProductModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjProduct' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content AS name, (SELECT GROUP_CONCAT(extra_id SEPARATOR '~:~') FROM `" . pjProductExtraModel::factory()->getTable() . "` WHERE product_id = t1.id GROUP BY product_id LIMIT 1) AS allowed_extras ")->orderBy("name ASC")->findAll()->toArray('allowed_extras', '~:~')->getData(); $this->set('product_arr', $product_arr); $location_arr = pjLocationModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjLocation' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content AS name")->orderBy("name ASC")->findAll()->getData(); $this->set('location_arr', $location_arr); $extra_arr = pjExtraModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjExtra' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->select("t1.*, t2.content AS name")->orderBy("name ASC")->findAll()->getData(); $this->set('extra_arr', $extra_arr); $pjProductPriceModel = pjProductPriceModel::factory(); $oi_arr = array(); $_oi_arr = pjOrderItemModel::factory()->where('t1.order_id', $arr['id'])->findAll()->getData(); foreach ($_oi_arr as $item) { if ($item['type'] == 'product') { $item['price_arr'] = $pjProductPriceModel->reset()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjProductPrice' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'price_name'", 'left')->select("t1.*, t2.content AS price_name")->where('product_id', $item['foreign_id'])->findAll()->getData(); } $oi_arr[] = $item; } $this->set('oi_arr', $oi_arr); $this->appendJs('chosen.jquery.js', PJ_THIRD_PARTY_PATH . 'harvest/chosen/'); $this->appendCss('chosen.css', PJ_THIRD_PARTY_PATH . 'harvest/chosen/'); $this->appendJs('jquery-ui-sliderAccess.js', PJ_THIRD_PARTY_PATH . 'timepicker/'); $this->appendJs('jquery-ui-timepicker-addon.js', PJ_THIRD_PARTY_PATH . 'timepicker/'); $this->appendCss('jquery-ui-timepicker-addon.css', PJ_THIRD_PARTY_PATH . 'timepicker/'); $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/'); $this->appendJs('jquery.noty.packaged.min.js', PJ_THIRD_PARTY_PATH . 'noty/packaged/'); $this->appendJs('pjAdminOrders.js'); } } else { $this->set('status', 2); } }
__('lblSpecialInstructions'); ?> </label> <span class="inline-block"> <textarea name="d_notes" id="d_notes" class="pj-form-field w500 h120<?php echo $tpl['option_arr']['o_df_include_notes'] == 3 ? ' required' : NULL; ?> "><?php echo stripslashes($tpl['arr']['d_notes']); ?> </textarea> </span> </p> <?php } $date_time = !empty($tpl['arr']['d_dt']) ? pjUtil::formatDate(date('Y-m-d', strtotime($tpl['arr']['d_dt'])), 'Y-m-d', $tpl['option_arr']['o_date_format']) . ' ' . pjUtil::formatTime(date('H:i:s', strtotime($tpl['arr']['d_dt'])), 'H:i:s', $tpl['option_arr']['o_time_format']) : ''; ?> <p> <label class="title"><?php __('lblDeliveryDateTime'); ?> </label> <span class="block overflow"> <span class="pj-form-field-custom pj-form-field-custom-after float_left r5"> <input type="text" name="d_dt" id="d_dt" class="pj-form-field pointer w150 datetimepick required" readonly="readonly" rel="<?php echo $week_start; ?> " rev="<?php echo $jqDateFormat; ?> " lang="<?php
</abbr></span></label> <?php } ?> </div> </div>--> </div> <div class="dashboard_bottom"></div> </div> <div class="clear_left t20 overflow"> <div class="float_left black t30 t20"><span class="gray"><?php echo ucfirst(__('lblDashLastLogin', true)); ?> :</span> <?php echo pjUtil::formatDate(date('Y-m-d', strtotime($_SESSION[$controller->defaultUser]['last_login'])), 'Y-m-d', $tpl['option_arr']['o_date_format']) . ', ' . pjUtil::formatTime(date('H:i:s', strtotime($_SESSION[$controller->defaultUser]['last_login'])), 'H:i:s', $tpl['option_arr']['o_time_format']); ?> </div> <div class="float_right overflow"> <?php list($hour, $day, $other) = explode("_", date("H:i_l_F d, Y")); $days = __('days', true, false); ?> <div class="dashboard_date"> <abbr><?php echo $days[date('w')]; ?> </abbr> <?php echo pjUtil::formatDate(date('Y-m-d'), 'Y-m-d', $tpl['option_arr']['o_date_format']); ?>
public function getDiscount($data, $option_arr) { $resp = array(); if (isset($data['voucher_code']) && !empty($data['voucher_code'])) { $_arr = pjVoucherModel::factory()->where('code', $data['voucher_code'])->findAll()->getData(); if (count($_arr) > 0) { $arr = $_arr[0]; if ($data['type'] == 'delivery') { $date = null; $time = "00:00:00"; if (isset($data['d_dt'])) { $date_time = $data['d_dt']; if (count(explode(" ", $date_time)) == 3) { list($_date, $_time, $_period) = explode(" ", $date_time); $time = pjUtil::formatTime($_time . ' ' . $_period, $option_arr['o_time_format']); } else { list($_date, $_time) = explode(" ", $date_time); $time = pjUtil::formatTime($_time, $option_arr['o_time_format']); } $date = $_date; } if (isset($data['p_date'])) { $date = $data['d_date']; if (isset($data['d_hour']) && isset($data['d_minute'])) { $time = $data['d_hour'] . ":" . $data['d_minute'] . ":00"; } } } else { $date = null; $time = "00:00:00"; if (isset($data['p_dt'])) { $date_time = $data['p_dt']; if (count(explode(" ", $date_time)) == 3) { list($_date, $_time, $_period) = explode(" ", $date_time); $time = pjUtil::formatTime($_time . ' ' . $_period, $option_arr['o_time_format']); } else { list($_date, $_time) = explode(" ", $date_time); $time = pjUtil::formatTime($_time, $option_arr['o_time_format']); } $date = $_date; } if (isset($data['d_date'])) { $date = $data['p_date']; if (isset($data['p_hour']) && isset($data['p_minute'])) { $time = $data['p_hour'] . ":" . $data['p_minute'] . ":00"; } } } if (!empty($date)) { $date = pjUtil::formatDate($date, $option_arr['o_date_format']); $d = strtotime($date); $dt = strtotime($date . " " . $time); $valid = false; switch ($arr['valid']) { case 'fixed': $time_from = strtotime($arr['date_from'] . " " . $arr['time_from']); $time_to = strtotime($arr['date_to'] . " " . $arr['time_to']); if ($time_from <= $dt && $time_to >= $dt) { $valid = true; } break; case 'period': $d_from = strtotime($arr['date_from']); $d_to = strtotime($arr['date_to']); $t_from = strtotime($arr['date_from'] . " " . $arr['time_from']); $t_to = strtotime($arr['date_to'] . " " . $arr['time_to']); if ($d_from <= $d && $d_to >= $d && $t_from <= $dt && $t_to >= $dt) { $valid = true; } break; case 'recurring': $t_from = strtotime($date . " " . $arr['time_from']); $t_to = strtotime($date . " " . $arr['time_to']); if ($arr['every'] == strtolower(date("l", $dt)) && $t_from <= $dt && $t_to >= $dt) { $valid = true; } break; } if ($valid) { $resp['voucher_code'] = $arr['code']; $resp['voucher_type'] = $arr['type']; /* Manmohan code here */ $resp['voucher_code_for'] = $arr['code_for']; $resp['voucher_product_id'] = $arr['product_id']; $resp['voucher_category_id'] = $arr['category_id']; /* Manmohan end of code here */ $resp['voucher_discount'] = $arr['discount']; $resp['code'] = 200; } else { $resp['code'] = 102; } } else { $resp['code'] = 103; } } else { $resp['code'] = 101; } } else { $resp['code'] = 100; } return $resp; }