Пример #1
0
 function _getSubscriptionData($oKTNotification)
 {
     $appName = APP_NAME;
     $info = array('object_name' => $oKTNotification->getLabel(), 'event_type' => $oKTNotification->getStrData1(), 'location_name' => $oKTNotification->getStrData2(), 'object_id' => $oKTNotification->getIntData1(), 'actor_id' => $oKTNotification->getIntData2(), 'has_actor' => false, 'notify_id' => $oKTNotification->getId());
     //		$info['title'] = KTUtil::arrayGet($this->_eventTypeNames, $info['event_type'], 'Subscription alert:') .': ' . $info['object_name'];
     $info['title'] = $appName . ': ' . _kt('Subscription notification for') . ' "' . $info['object_name'] . '" - ' . $this->_eventTypeNames[$info['event_type']];
     if ($info['actor_id'] !== null) {
         $oTempUser = User::get($info['actor_id']);
         if (PEAR::isError($oTempUser) || $oTempUser == false) {
             // no-act
             $info['actor'] = null;
         } else {
             $info['actor'] = $oTempUser;
             $info['has_actor'] = true;
             $sName = $oTempUser->getName();
             $iUnitId = $oTempUser->getUnitId();
             if ($iUnitId !== false) {
                 $oUnit = Unit::get($iUnitId);
                 if (!PEAR::isError($oUnit)) {
                     $sName .= sprintf(" (%s)", $oUnit->getName());
                 }
             }
             $info['actor_name'] = $sName;
         }
     }
     if ($info['object_id'] !== null) {
         $info['object'] = $this->_getEventObject($info['event_type'], $info['object_id']);
     }
     return $info;
 }
Пример #2
0
 function _getUnitName($oGroup)
 {
     $iUnitId = $oGroup->getUnitId();
     if (empty($iUnitId)) {
         return null;
     }
     $u = Unit::get($iUnitId);
     if (PEAR::isError($u)) {
         return null;
         // XXX: prevent failure if the $u is a PEAR::error
     }
     return $u->getName();
 }
Пример #3
0
 function stock_get()
 {
     $filters = $this->get("filter")["filters"];
     $page = $this->get('page') !== false ? $this->get('page') : 1;
     $limit = $this->get('limit') !== false ? $this->get('limit') : 100;
     $sort = $this->get("sort");
     $data["results"] = array();
     $data["count"] = 0;
     $obj = new Bill_line(null, $this->entity);
     //Sort
     if (!empty($sort) && isset($sort)) {
         foreach ($sort as $value) {
             $obj->order_by($value["field"], $value["dir"]);
         }
     }
     //Filter
     if (!empty($filters) && isset($filters)) {
         foreach ($filters as $value) {
             if (!empty($value["operator"]) && isset($value["operator"])) {
                 if ($value["operator"] == "where_in") {
                     $obj->where_in($value["field"], $value["value"]);
                 } else {
                     if ($value["operator"] == "or_where_in") {
                         $obj->or_where_in($value["field"], $value["value"]);
                     } else {
                         if ($value["operator"] == "where_not_in") {
                             $obj->where_not_in($value["field"], $value["value"]);
                         } else {
                             if ($value["operator"] == "or_where_not_in") {
                                 $obj->or_where_not_in($value["field"], $value["value"]);
                             } else {
                                 if ($value["operator"] == "like") {
                                     $obj->like($value["field"], $value["value"]);
                                 } else {
                                     if ($value["operator"] == "or_like") {
                                         $obj->or_like($value["field"], $value["value"]);
                                     } else {
                                         if ($value["operator"] == "not_like") {
                                             $obj->not_like($value["field"], $value["value"]);
                                         } else {
                                             if ($value["operator"] == "or_not_like") {
                                                 $obj->or_not_like($value["field"], $value["value"]);
                                             } else {
                                                 if ($value["operator"] == "startswith") {
                                                     $obj->like($value["field"], $value["value"], "after");
                                                 } else {
                                                     if ($value["operator"] == "endswith") {
                                                         $obj->like($value["field"], $value["value"], "before");
                                                     } else {
                                                         if ($value["operator"] == "contains") {
                                                             $obj->like($value["field"], $value["value"], "both");
                                                         } else {
                                                             if ($value["operator"] == "or_where") {
                                                                 $obj->or_where($value["field"], $value["value"]);
                                                             } else {
                                                                 $obj->where($value["field"] . ' ' . $value["operator"], $value["value"]);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             } else {
                 $obj->where($value["field"], $value["value"]);
             }
         }
     }
     //Results
     if (!empty($limit) && !empty($page)) {
         $obj->get_paged_iterated($page, $limit);
         $data["count"] = $obj->paged->total_rows;
     }
     if ($obj->result_count() > 0) {
         foreach ($obj as $value) {
             $pl = new Price_list(null, $this->entity);
             if ($value->product_id > 0) {
                 $pl->get_by_product_id($value->product_id);
                 $priceList = [];
                 foreach ($pl as $p) {
                     $priceList[] = array("id" => $p->id, "currency_id" => $p->currency_id, "product_id" => $p->product_id, "unit_id" => $p->unit_id, "price" => floatval($p->price), "unit_value" => floatval($p->unit_value), "locale" => $p->currency->get()->locale, "unit" => $p->unit->get()->name);
                 }
             } else {
                 $un = new Unit(null, $this->entity);
                 $un->get();
                 $priceList = [];
                 foreach ($un as $u) {
                     $priceList[] = array("id" => $u->id, "currency_id" => 0, "product_id" => 0, "unit_id" => $u->id, "price" => 0, "unit_value" => 0, "currency" => "km-KH", "unit" => $u->name);
                 }
             }
             $data["results"][] = array("id" => $value->id, "bill_id" => $value->bill_id, "unit_id" => $value->unit_id, "currency_id" => $value->currency_id, "product_id" => $value->product_id, "description" => $value->description, "quantity" => floatval($value->quantity), "price" => floatval($value->price), "amount" => floatval($value->amount), "rate" => floatval($value->rate), "product" => $value->product->get_raw()->result(), "unit" => $value->unit->get_raw()->result(), "currency" => $value->currency->get_raw()->result(), "priceList" => $priceList);
         }
     }
     //Response Data
     $this->response($data, 200);
 }