Beispiel #1
0
 public function reporteEjercidoRms($proyecto_id)
 {
     $rms = Rm::whereProyectoId($proyecto_id)->get(['id']);
     $egresos_id = [];
     foreach ($rms as $rm) {
         $rm_obj = RM::find($rm->id);
         //Exlusión de egresos de vales comprobados
         $egresos_id_comprobados = $this->getEgresosComprobados($rm_obj);
         $egresos_query = $rm->egresos()->where('cuenta_id', 1);
         if (count($egresos_id_comprobados) > 0) {
             $egresos_query->whereNotIn('egresos.id', $egresos_id_comprobados);
         }
         $nvo = $egresos_query->get(['egresos.id'])->lists('id')->all();
         $egresos_id = array_merge($egresos_id, $nvo);
     }
     $ejercido_rm = Egreso::whereIn('id', $egresos_id)->with('benef', 'cuenta', 'user')->get();
     return $ejercido_rm;
 }
Beispiel #2
0
 /**
  * @before _session
  * @after _csrfToken
  */
 public function register()
 {
     $this->seo(array("title" => "Advertiser Register", "description" => "Register"));
     $view = $this->getActionView();
     $view->set('errors', []);
     $token = RM::post("token", '');
     if (RM::post("action") == "register" && $this->verifyToken($token)) {
         $this->_advertiserRegister($this->org, $view);
     }
 }
Beispiel #3
0
 /**
  * @before _secure
  * @todo @Faizan_Ayubi Remove UNSAFE Actions from GET Request
  */
 public function postback($id)
 {
     $this->JSONView();
     $view = $this->getActionView();
     $postback = PostBack::first(["id" => $id, "org_id" => $this->org->_id]);
     if ($postback) {
         switch (strtolower(RM::type())) {
             case 'delete':
                 $postback->delete();
                 $view->set('message', 'PostBack Deleted Successfully');
                 break;
             case 'post':
                 $postback->live = (int) RM::post("live");
                 $postback->save();
                 $view->set('message', 'PostBack Updated Successfully');
                 break;
         }
     } else {
         $view->set('message', "Invalid Request!!");
     }
 }
Beispiel #4
0
 /**
  * @before _secure
  * @after _displayData
  */
 public function platforms($id = null)
 {
     $this->seo(["title" => "Platform wise click stats"]);
     $view = $this->getActionView();
     $org = $this->org;
     $clickCol = Registry::get("MongoDB")->clicks;
     // find the platforms
     $platforms = \Platform::all(['user_id' => ['$in' => $org->users('advertisers')]], ['_id', 'url']);
     if (count($platforms) === 0) {
         return $view->set(['platforms' => [], 'publishers' => []]);
     }
     $key = array_rand($platforms);
     $url = RM::get('link', $platforms[$key]->url);
     // find ads having this url
     $ads = \Ad::all(['org_id' => $org->_id], ['_id', 'url']);
     $in = Utils::mongoObjectId(array_keys($ads));
     $matched = [];
     foreach ($ads as $a) {
         $regex = preg_quote($url, '.');
         if (preg_match('#^' . $regex . '#', $a->url)) {
             $matched[] = Utils::mongoObjectId($a->_id);
         }
     }
     if (count($matched) === 0) {
         $query['adid'] = ['$in' => $in];
     } else {
         $query['adid'] = ['$in' => $matched];
     }
     $query['is_bot'] = false;
     $query['created'] = Db::dateQuery($this->start, $this->end);
     $records = $clickCol->aggregate([['$match' => $query], ['$projection' => ['_id' => 1, 'pid' => 1]], ['$group' => ['_id' => '$pid', 'count' => ['$sum' => 1]]], ['$sort' => ['count' => -1]]]);
     $result = [];
     $publishers = [];
     foreach ($records as $r) {
         $obj = (object) $r;
         $id = Utils::getMongoID($obj->_id);
         $user = User::first(['_id' => $id], ['_id', 'name']);
         $result[$id] = (object) ['_id' => $user->_id, 'name' => $user->name, 'clicks' => $obj->count];
     }
     $view->set(['platforms' => $platforms, 'link' => $url, 'publishers' => $result]);
 }
Beispiel #5
0
 /**
  * @before _secure
  */
 public function platforms($id = null)
 {
     $this->seo(array("title" => "Platforms"));
     $view = $this->getActionView();
     $query['user_id'] = ['$in' => $this->org->users('publisher')];
     $limit = RM::get("limit", 20);
     $page = RM::get("page", 1);
     $property = RM::get("property", '');
     $value = RM::get("value");
     if (in_array($property, ["live", "user_id"])) {
         $query["{$property} = ?"] = $value;
     } else {
         if (in_array($property, ["url"])) {
             $query[$property] = Utils::mongoRegex($value);
         }
     }
     if (RM::type() === 'POST') {
         $p = \Platform::first(['_id' => $id, 'user_id' => $query['user_id']]);
         if (!$p) {
             return $view->set('message', "Invalid Request!!");
         }
         try {
             $updateAble = ['live', 'user_id', 'url'];
             foreach ($_POST as $key => $value) {
                 if (in_array($key, $updateAble)) {
                     $p->{$key} = $value;
                 }
             }
             $p->save();
             return $view->set('message', 'Platform updated!!');
         } catch (\Exception $e) {
             return $view->set('message', "Invalid Request Parameters!!");
         }
     }
     if (RM::type() === 'DELETE') {
         $p = \Platform::first(['_id' => $id, 'user_id' => $query['user_id']]);
         if (!$p) {
             return $view->set('message', "Invalid Request!!");
         }
         $p->delete();
         return $view->set('message', "Platform Removed!!");
     }
     $platforms = Platform::all($query, [], 'created', 'desc', $limit, $page);
     $count = Platform::count($query);
     $view->set("platforms", $platforms)->set("count", $count)->set("property", $property)->set("value", $value)->set("limit", $limit)->set("page", $page);
 }
Beispiel #6
0
 /**
  * @before _secure
  */
 public function settings()
 {
     $this->seo(array("title" => "Campaign: Settings"));
     $view = $this->getActionView();
     $user = $this->user;
     $org = $this->org;
     if (RM::type() === 'DELETE') {
         switch (RM::get("action")) {
             case 'commDel':
                 $comm = Commission::first(['_id' => RM::get("comm_id"), "org_id" => $this->org->_id]);
                 if ($comm) {
                     $comm->delete();
                     $view->set('message', 'Commission removed!!');
                 } else {
                     $view->set('message', 'Invalid request!!');
                 }
                 return;
         }
     }
     if (RM::type() == 'POST') {
         $action = RM::post('action', '');
         switch ($action) {
             case 'commadd':
             case 'commedit':
                 $fields = ['model' => RM::post('model'), 'rate' => RM::post('rate'), 'coverage' => RM::post('coverage') ?? ['ALL']];
                 $comm_id = RM::post('comm_id');
                 if ($comm_id) {
                     $comm = Commission::first(['_id' => $comm_id, 'org_id' => $this->org->_id]);
                     if (!$comm) {
                         $view->set('Invalid Request!!');
                         break;
                     }
                 } else {
                     $comm = new Commission(['org_id' => $this->org->_id]);
                 }
                 foreach ($fields as $key => $value) {
                     $comm->{$key} = $value;
                 }
                 $comm->save();
                 //echo "<pre>", print_r($_POST), "</pre>";die();
                 $view->set('message', 'Commission saved successfully!!');
                 break;
             case 'domains':
                 $message = $org->updateDomains();
                 $this->setOrg($org);
                 $view->set('message', $message);
                 break;
             case 'categories':
                 $success = Category::updateNow($this->org);
                 if ($success) {
                     $msg = 'Categories updated Successfully!!';
                 } else {
                     $msg = 'Failed to delete some categories because in use by campaigns!!';
                 }
                 $view->set('message', $msg);
                 break;
         }
         $this->setUser($user);
     }
     $commissions = Commission::all(['org_id' => $this->org->_id]);
     $categories = \Category::all(['org_id' => $this->org->_id]);
     $view->set('categories', $categories)->set('hideRevenue', true)->set('commissions', $commissions);
 }
Beispiel #7
0
 /**
  * @before _secure
  */
 public function update($invoice_id)
 {
     $this->JSONView();
     $view = $this->getActionView();
     $i = \Invoice::first(["_id = ?" => $invoice_id, "org_id = ?" => $this->org->_id]);
     if (!$i || RM::type() !== 'POST') {
         return $view->set('message', 'Invalid Request!!');
     }
     $view->set('message', 'Updated successfully!!');
     $allowedFields = ['live'];
     foreach ($allowedFields as $f) {
         $i->{$f} = RM::post($f, $i->{$f});
     }
     $i->save();
     $view->set('invoice', $i);
 }
Beispiel #8
0
 /**
  * @before _session
  * @after _csrfToken
  */
 public function register()
 {
     $this->seo(array("title" => "Publisher Register", "description" => "Register"));
     $view = $this->getActionView();
     $view->set('errors', []);
     $afields = Meta::search('customField', $this->org);
     $view->set('afields', $afields ?? []);
     $token = RM::post("token", '');
     if (RM::post("action") == "register" && $this->verifyToken($token)) {
         $this->_publisherRegister($this->org, $view);
     }
 }
Beispiel #9
0
 /**
  * @before _admin
  */
 public function delete($record_id)
 {
     $this->JSONview();
     if (RM::type() !== 'DELETE') {
         $this->_404();
     }
 }