model() static public method

static public model ( null | string $className = __CLASS__ ) : User | static
$className null | string
return User | static
 /**
  * @param $id
  * @throws CHttpException
  */
 public function actionView($id)
 {
     $model = Client::model()->findByPk($id);
     if (null === $model) {
         throw new CHttpException(404);
     }
     $this->render('view', ['model' => $model, 'order' => new Order(), 'orders' => $model->getOrders()]);
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Client::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'Запрашиваемая страница не существует.');
     }
     return $model;
 }
	protected function clientNum($oid)
	{
		$num = Client::model()->count(array('condition'=>"oid=$oid"));
		if($num){
			return $num;
		}else{
			return 0;
		}
	}
 private static function parseBouncedEvent($value)
 {
     if ($model = MandrillEmail::model()->findByPk($value['msg']['_id'])) {
         $model->status = MandrillEmail::STATUS_BOUNCED;
         $model->save();
         if ($value['msg']['email']) {
             Client::model()->updateAll(['invalidEmail' => Client::INVALID_EMAIL], 'cli_email = :email', ['email' => $value['msg']['email']]);
         }
     }
 }
 public function actionDisplaySave($id = 0, $instructionId = 0)
 {
     $this->layout = '//layouts/new/popup';
     $cliId = isset($_GET['cliId']) ? $_GET['cliId'] : 0;
     $model = new Offer();
     if ($id) {
         $model = Offer::model()->findByPk($id);
         $instructionId = empty($instructionId) ? $model->off_deal : $instructionId;
         if (!$cliId) {
             $this->actionSaveClientToOffer($cliId, $id);
         }
     }
     if (isset($_POST['delete']) && $_POST['delete'] || isset($_POST['restore']) && $_POST['restore']) {
         $model->off_status = isset($_POST['delete']) ? Offer::STATUS_DELETED : Offer::STATUS_SUBMITTED;
         if ($model->save()) {
             if (isset($_POST['delete'])) {
                 Yii::app()->user->setFlash('offer-deleted', 'Offer is deleted!');
             } else {
                 Yii::app()->user->setFlash('offer-restored', 'Offer is restored!');
             }
             Yii::app()->user->setFlash('offer-callback', isset($_GET['callback']) ? $_GET['callback'] : "");
             $this->redirect(array('displaySave', 'id' => $id, 'instructionId' => $instructionId, 'callback' => isset($_GET['callback']) ? $_GET['callback'] : "", 'close' => isset($_POST['close'])));
         }
     } else {
         if (isset($_POST['Offer']) && $_POST['Offer']) {
             $model->attributes = $_POST['Offer'];
             if ($model->save()) {
                 if (isset($_POST['Offer']['clientId']) && $_POST['Offer']['clientId']) {
                     $this->actionSaveClientToOffer($_POST['Offer']['clientId'], $model->off_id);
                 }
                 if (isset($_POST['Offer']['clientStatus']) && $_POST['Offer']['clientStatus']) {
                     $clientStatus = $_POST['Offer']['clientStatus'];
                     $clientStatusType = Deal::model()->findByPk($instructionId)->dea_type == Deal::TYPE_SALES ? 'cli_salestatus' : 'cli_letstatus';
                     foreach ($clientStatus as $clientId => $clientStatusId) {
                         Client::model()->updateByPk($clientId, [$clientStatusType => $clientStatusId]);
                     }
                 }
                 Yii::app()->user->setFlash('offer-updated', 'Saved!');
                 Yii::app()->user->setFlash('offer-callback', isset($_GET['callback']) ? $_GET['callback'] : "");
                 $this->redirect(array('displaySave', 'id' => $model->off_id, 'instructionId' => $instructionId, 'callback' => isset($_GET['callback']) ? $_GET['callback'] : "", 'close' => isset($_POST['close']) ? true : false));
             }
         }
     }
     if (Yii::app()->user->hasFlash('offer-callback')) {
         $callback = Yii::app()->user->getFlash('offer-callback');
         $callbackObj = new PopupCallback($callback);
         if ($callback == 'showInstructionOffers') {
             $callbackObj->run(array($instructionId), isset($_GET['close']) && $_GET['close']);
         } else {
             $callbackObj->run(array($model->off_id), isset($_GET['close']) && $_GET['close']);
         }
     }
     $this->render('edit', ['model' => $model, 'instructionId' => $instructionId, 'clientId' => $cliId]);
 }
 /**
  * Step 2
  *
  * @throws CHttpException
  * @return void
  * @internal param $clientId
  */
 public function actionSelectProperty()
 {
     $clientId = AppointmentBuilder::getCurrent()->getClientId();
     /**
      * @var $client Client
      */
     $client = Client::model()->findByPk($clientId);
     if (!$client) {
         throw new CHttpException('404', 'Client [id: ' . $clientId . '] is not found');
     }
     $this->render('selectProperty', ['model' => $client]);
 }
 private function getDataBySearch($search)
 {
     $data = [];
     $clients = Client::model()->quickSearch($search);
     foreach ($clients as $key => $client) {
         $data[] = ['label' => $client->getFullName(), 'value' => $client->getFullName(), 'url' => $this->createUrl('client/update', ['id' => $client->cli_id])];
     }
     $instructions = Deal::model()->quickSearch($search);
     foreach ($instructions as $key => $instr) {
         $title = $instr->address->line1 . ' ' . $instr->title;
         $data[] = ['label' => $title, 'value' => $title, 'url' => $this->createUrl('instruction/summary', ['id' => $instr->dea_id])];
     }
     return $data;
 }
 public function actionReplyMessage()
 {
     if (isset(Yii::app()->params['twilio']['replyMessage']) && Yii::app()->params['twilio']['replyMessage']) {
         file_put_contents(Yii::app()->params['logDirPath'] . '/twilio_request.log', print_r($_REQUEST, true) . "\n\n", FILE_APPEND);
         $phone = str_replace('+44', '', $_REQUEST['From']);
         $client = Client::model()->findByPhone($phone);
         $sms = new Sms();
         $sms->clientId = $client ? $client->cli_id : 0;
         $sms->receive($_REQUEST);
         if ($client) {
             $latestText = Sms::model()->latestTextToClient($client);
         }
         header('content-type: text/xml');
         echo '<Response><Sms><![CDATA[' . Yii::app()->params['twilio']['replyMessage'] . ']]></Sms></Response>';
     }
 }
 public function actionOpen($client, $mail)
 {
     $hit = new MandrillMailshotHit();
     $mailshot = MandrillMailshot::model()->findByPk($mail);
     $client = Client::model()->findByPk($client);
     if (!$mailshot) {
         throw new CHttpException('mailshot [id : ' . $mail . '] was not found');
     }
     if (!$client) {
         throw new CHttpException('client [id : ' . $client . '] was not found');
     }
     $hit->clientId = $client->cli_id;
     $hit->mailshotId = $mailshot->id;
     $hit->userAgent = Yii::app()->request->getUserAgent();
     $hit->ip = Yii::app()->request->getUserHostAddress();
     $hit->save();
     $this->redirect(['property/view', 'id' => $mailshot->instructionId]);
 }
 public function validateClientEmail($email, $params)
 {
     if ($this->{$email}) {
         /** @var $client Client */
         $criteria = new CDbCriteria();
         $criteria->compare('cli_email', $this->{$email});
         $criteria->with = ['telephones'];
         /** @var $client Client */
         $clients = Client::model()->findAll($criteria);
         if ($client = $clients[0]) {
             $this->name = $client->cli_fname;
             $this->surname = $client->cli_sname;
             $this->telephone = $client->telephones[0]->tel_number;
             $this->addError('registeredInfo', 'You are already registered.');
             return false;
         }
     }
 }
 /**
  * if $_GET['owner'] is passed that means that proeprty will have an owner before it is created.
  * it is used in situation when wi select a client and want to create a property for him (valuation for example) then it is obvious that client is an owner
  *
  * @param Property $model property to edit
  */
 public function edit(Property $model)
 {
     /**
      * @var $address Address
      */
     if (isset($_POST['Property']) && $_POST['Property']) {
         $model->attributes = $_POST['Property'];
         $model->setClients(isset($_POST['owner']) && $_POST['owner'] ? $_POST['owner'] : [], Property::CLIENT_TYPE_OWNER);
         $model->setClients(isset($_POST['tenant']) && $_POST['tenant'] ? $_POST['tenant'] : [], Property::CLIENT_TYPE_TENANT);
         if (isset($_POST['propertyAddress']['id']) && $_POST['propertyAddress']['id']) {
             $address = Address::model()->findByPk($_POST['propertyAddress']['id']);
             if ($address) {
                 $model->setAddress($address);
             }
         }
         if ($model->save()) {
             Yii::app()->user->setFlash('property-update-success', 'Property updated.');
             $url = array('update', 'id' => $model->pro_id);
             if (isset($_GET['nextStep']) && $_GET['nextStep']) {
                 if (isset($_POST['proceed'])) {
                     if ($_GET['nextStep'] == 'AppointmentBuilder_propertySelected') {
                     }
                     $url = $this->createUrl('AppointmentBuilder/propertySelected', ['propertyId' => $model->pro_id]);
                 } else {
                     $url['nextStep'] = $_GET['nextStep'];
                 }
             }
             $this->redirect($url);
         }
     }
     $suggesstedOwner = null;
     if (Yii::app()->user->hasFlash('suggest-new-owner')) {
         $suggesstedOwner = Client::model()->findByPk(Yii::app()->user->getFlash('suggest-new-owner', null, false));
     }
     $this->render('edit', ['model' => $model, 'suggestedOwner' => $suggesstedOwner]);
 }
Example #12
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Client::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #13
0
<?php

/**
 * @var $offerClientList Deal Owners OR deal tenants
 * @ var $clientStatusType
 * @ var $instructionType
 */
ob_start();
$data = '';
if ($offerClientList) {
    $data = $data . '<table cellpadding="2 5 2 5">';
    foreach ($offerClientList as $offerClient) {
        $data = $data . '<tr><td>';
        if (!empty($offerClient->c2o_cli)) {
            $client = Client::model()->findByPk($offerClient->c2o_cli);
            $data = $data . CHtml::link($client->fullName, Yii::app()->createUrl('admin4/client/update', ['id' => $offerClient->c2o_cli]));
        }
        $data = $data . '</td><td>';
        $data = $data . CHtml::dropDownList('Offer[clientStatus][' . $client->cli_id . ']', $client->{$clientStatusType}, [0 => ''] + CHtml::listData(ClientStatus::model()->findAll(array('scopes' => array($instructionType))), 'cst_id', 'cst_title'), ['class' => 'input-xsmall']);
        $data = $data . '</td><td>';
        $data = $data . CHtml::link(CHtml::image(Yii::app()->params["imgUrl"] . "/sys/admin/icons/cross-icon.png", "Delete"), "#", ["onClick" => "deleteClient(" . $offerClient->c2o_id . ")"]);
        $data = $data . '</td></tr>';
    }
    $data = $data . '</table>';
}
echo json_encode(array('html' => $data));
Example #14
0
<?php

/**
 * @var $fixed boolean|null
 * @see
 */
$pendSales = Client::model()->pendingCount("sales");
$pendLet = Client::model()->pendingCount("lettings");
$fixed = isset($fixed) ? $fixed : null;
$menu = array(['htmlOptions' => ['class' => 'header'], 'url' => Yii::app()->params['globalUrlOld'] . 'home.php', 'label' => 'Home Page'], 'separator', ['htmlOptions' => ['class' => 'header'], 'url' => Yii::app()->params['globalUrlOld'] . 'calendar.php', 'label' => 'Calendar'], ['htmlOptions' => [], 'url' => ['AppointmentBuilder/selectClient', 'for' => 'viewing'], 'label' => 'Arrange Viewing'], ['htmlOptions' => [], 'url' => ['instruction/vendorCare'], 'label' => 'Vendor Care'], ['htmlOptions' => [], 'url' => ['AppointmentBuilder/selectClient', 'for' => 'valuation'], 'label' => 'Arrange Valuation'], ['htmlOptions' => [], 'url' => ['Appointment/search'], 'label' => 'Search Calendar'], 'separator', ['htmlOptions' => [], 'url' => ['property/select'], 'label' => 'Property'], ['htmlOptions' => [], 'url' => ['instruction/search', AdminFilterForm::generateResetParam('instruction-filter-form') => 'true'], 'label' => 'Search Instruction'], ['htmlOptions' => [], 'url' => ['property/select'], 'label' => 'Search Property'], 'separator', ['htmlOptions' => ['class' => 'header'], 'url' => array('client/search'), 'label' => 'Clients'], ['htmlOptions' => [], 'url' => ['client/create'], 'label' => 'Add Client'], ['htmlOptions' => [], 'url' => ['client/newlyRegistered'], 'label' => 'Newly Registered'], ['htmlOptions' => [], 'url' => ['sms/incoming'], 'label' => 'Incoming Messages'], 'separator', ['htmlOptions' => ['class' => 'header'], 'url' => Yii::app()->params['globalUrlOld'] . 'contact.php', 'label' => 'Contacts'], ['htmlOptions' => [], 'url' => Yii::app()->params['globalUrlOld'] . 'contact_add.php', 'label' => 'New Contact'], ['htmlOptions' => [], 'url' => Yii::app()->params['globalUrlOld'] . 'company_add.php', 'label' => 'New Company'], 'separator', ['htmlOptions' => ['class' => 'header'], 'url' => Yii::app()->params['globalUrlOld'] . 'tools.php', 'label' => 'Tools'], 'separator', ['htmlOptions' => ['class' => 'header'], 'url' => '/admin/index.php', 'label' => 'Old Admin']);
if (Yii::app()->user->is("SuperAdmin")) {
    $menu[] = 'separator';
    $menu[] = ['htmlOptions' => ['class' => 'header', 'style' => 'color:red'], 'url' => array('SuperAdmin/'), 'label' => 'Super Admin'];
}
$menu[] = 'separator';
$menu[] = ['htmlOptions' => ['class' => 'header'], 'url' => '#', 'label' => 'Listing'];
$menu[] = ['htmlOptions' => [], 'url' => ['LocalEvent/'], 'label' => 'Local Events'];
$menu[] = ['htmlOptions' => [], 'url' => ['Place/'], 'label' => 'Parks'];
$menu[] = ['htmlOptions' => [], 'url' => ['Blog/'], 'label' => 'Blog'];
$menu[] = ['htmlOptions' => [], 'url' => ['PropertyCategory/'], 'label' => 'Property Category'];
$menu[] = ['htmlOptions' => [], 'url' => ['OuterLink/'], 'label' => 'Links'];
$menu[] = 'separator';
$menu[] = ['htmlOptions' => ['class' => 'header'], 'url' => '#', 'label' => 'Quick Reports'];
$menu[] = ['htmlOptions' => [], 'url' => ['QuickReport/instructionsWithoutEPC'], 'label' => 'Mising EPCs'];
$menu[] = ['htmlOptions' => [], 'url' => ['instruction/missedFollowUpReport'], 'label' => 'Missed Follow ups'];
$menu[] = ['htmlOptions' => [], 'url' => ['site/logout'], 'label' => 'Logout'];
?>
<div class="left-menu <?php 
echo $fixed ? 'fixed' : '';
?>
">
Example #15
0
 /** Lookup Client for autocomplete
  *
  * @throws CHttpException
  */
 public function actionGetClient()
 {
     if (isset($_GET['term'])) {
         $term = trim($_GET['term']);
         $ret['results'] = Client::model()->select2Client($term);
         //PHP Example · ivaynberg/select2  http://bit.ly/10FNaXD got stuck serveral hoursss :|
         echo CJSON::encode($ret);
         Yii::app()->end();
     }
 }
 protected function customerInfo($customer_id)
 {
     $model = null;
     if ($customer_id != null) {
         $model = Client::model()->findbyPk($customer_id);
     }
     return $model;
 }
 public function actionIndex()
 {
     $concessioners = Concessioner::model()->findAll();
     $vehicles = Vehicle::model()->findAllByAttributes(array('status' => 'ACTIVE'));
     $versions = VehicleVersion::model()->findAllByAttributes(array('status' => 'ACTIVE'));
     $cities = City::model()->findAll();
     if (isset($_POST['Search'])) {
         $criteria = new CDbCriteria();
         $date = "";
         $vehicle_or_version = "";
         $columns = array();
         switch ($_POST['Search']['module']) {
             case "TechnicalDate":
                 $columns = array('id:number', 'client.identity:text', 'client.name:text', 'client.lastname:text', 'client.email:text', 'concessioner.name:text', 'work:text', 'preference_date:date', 'hour:text', 'taxi:text', 'detail_work:text', 'creation_date:date');
                 $date = "creation_date";
                 $vehicle_or_version = "vehicle_id";
                 break;
             case "Quotation":
                 $columns = array('id:number', 'client.identity:text', 'client.name:text', 'client.lastname:text', 'client.email:text', 'concessioner.name:text', 'vehicleversion.reference:text', 'vehicleversion2.reference:text', 'time:text', 'registration_date:date');
                 $date = "registration_date";
                 $vehicle_or_version = "vehicle_version_id";
                 break;
             case "Replacement":
                 $columns = array('id:number', 'client.identity:text', 'client.name:text', 'client.lastname:text', 'client.email:text', 'concessioner.name:text', 'part:text');
                 $vehicle_or_version = "vehicle_id";
                 break;
             case "Suggestion":
                 $columns = array('id:number', 'client.identity:text', 'client.name:text', 'client.lastname:text', 'client.email:text', 'concessioner.name:text', 'vehicle.name:text', 'description:text', 'type:text', 'creation_date:date');
                 $date = "creation_date";
                 break;
         }
         if ($_POST['Search']['date_from'] && $_POST['Search']['date_to']) {
             $criteria->addBetweenCondition('creation_date', $_POST['Search']['date_from'], $_POST['Search']['date_to']);
         }
         if ($_POST['Search']['city'] != 0 && $_POST['Search']['concessioner'] == 0) {
             $citiess = City::model()->findByPk($_POST['Search']['city']);
             foreach ($citiess->concessioners as $concessioner) {
                 $criteria->addSearchCondition('concessioner_id', $concessioner->id, "", 'OR');
             }
         } elseif ($_POST['Search']['city'] != 0 && $_POST['Search']['concessioner'] != 0) {
             $criteria->addSearchCondition('concessioner_id', $_POST['Search']['concessioner']);
         }
         if ($_POST['Search']['identity']) {
             $clients = Client::model()->findAllByAttributes(array('identity' => $_POST['Search']['identity']));
             foreach ($clients as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['name']) {
             $clients2 = Client::model()->findAllByAttributes(array('name' => $_POST['Search']['name']));
             foreach ($clients2 as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['lastname']) {
             $clients3 = Client::model()->findAllByAttributes(array('lastname' => $_POST['Search']['lastname']));
             foreach ($clients3 as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['email']) {
             $clients4 = Client::model()->findAllByAttributes(array('email' => $_POST['Search']['email']));
             foreach ($clients4 as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['model'] != 0 && $_POST['Search']['version'] == 0) {
             if ($vehicle_or_version == "vehicle_id") {
                 $criteria->addSearchCondition('vehicle_id', $_POST['Search']['model']);
             } elseif ($vehicle_or_version == "vehicle_version_id") {
                 $vehicle1 = Vehicle::model()->findByPk($_POST['Search']['model']);
                 foreach ($vehicle1->vehicleVersions as $version) {
                     $criteria->addSearchCondition('vehicle_version_id', $version->id, "", 'OR');
                     $criteria->addSearchCondition('vehicle_version_id2', $version->id, "", 'OR');
                 }
             }
         } elseif ($_POST['Search']['model'] == 0 && $_POST['Search']['version'] != 0) {
             if ($vehicle_or_version == "vehicle_version_id") {
                 $criteria->addSearchCondition('vehicle_version_id', $_POST['Search']['version'], "", 'OR');
                 $criteria->addSearchCondition('vehicle_version_id2', $_POST['Search']['version'], "", 'OR');
             }
         }
         if ($_POST['Search']['module'] != "0") {
             $pagination = new EDTPagination();
             $criteria->order = "id DESC";
             $pagination->applyLimit($criteria);
             $sort = new EDTSort($_POST['Search']['module'], $columns);
             $sort->defaultOrder = 'id';
             //die(print_r($criteria));
             $dataProvider = new CActiveDataProvider($_POST['Search']['module'], array('criteria' => $criteria, 'pagination' => $pagination, 'sort' => $sort));
         } else {
             $dataProvider = new CActiveDataProvider('TechnicalDate', array('criteria' => $criteria));
         }
         self::$wid = $this->createWidget('ext.EDataTables.EDataTables', array('id' => 'data_table', 'dataProvider' => $dataProvider, 'ajaxUrl' => $this->createUrl('grid/DataTables'), 'columns' => $columns, 'serverData' => array("module" => $_POST['Search']['module']), 'buttons' => array('export' => array('label' => Yii::t('app', 'Save as CSV'), 'text' => false, 'htmlClass' => '', 'icon' => Yii::app()->theme !== null && Yii::app()->theme->name == 'bootstrap' ? 'icon-download-alt' : 'ui-icon-disk', 'url' => $this->createUrl('grid/exportCVS'))), 'options' => array('bStateSave' => false, 'bPaginate' => false, 'bLengthChange' => true, 'iDisplayLength' => 50)));
         if (!Yii::app()->getRequest()->getIsAjaxRequest()) {
             $this->render('index', array('cities' => $cities, 'vehicles' => $vehicles, 'versions' => $versions, 'concessioners' => $concessioners, 'widget' => self::$wid));
             return;
         } else {
             echo json_encode($widget->getFormattedData(intval($_REQUEST['sEcho'])));
             Yii::app()->end();
         }
     } else {
         $this->render('index', array('cities' => $cities, 'vehicles' => $vehicles, 'versions' => $versions, 'concessioners' => $concessioners));
     }
 }
 public function actionEdit($username = null)
 {
     $params = array('username' => $username);
     if (Yii::app()->user->checkAccess('editOwnProfile', $params)) {
         $model = User::model()->findByPk(Yii::app()->user->name);
         $model->scenario = 'byUserEdit';
         if (isset($_POST['User'])) {
             $model->attributes = $_POST['User'];
             if (empty($model->client)) {
                 $model->client = new Client();
                 $model->client->card = Client::model()->find(array('select' => 'max(card) as maxCardNumber'))->maxCardNumber + 1;
             }
             $model->client->attributes = $model->attributes;
             $model->client->attributes = $_POST['Client'];
             if ($model->validate() && $model->client->validate()) {
                 $model->save(false);
                 $model->client->save(false);
                 $this->redirect(array('users/view', 'username' => $model->username));
             }
         }
         if (empty($model->client)) {
             $model->client = new Client();
         }
         $model->password = null;
         $model->password_confirm = null;
         $this->render('edit', array('model' => $model));
     } else {
         throw new CHttpException(403, 'У Вас нет доступа к редактированию этой страницы.');
     }
 }
Example #19
0
 private function updatesimple($typic, $grtype, $result, &$info)
 {
     if ($typic == 2) {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid " . " FROM tmp_xml a WHERE a.user="******" AND a.ctype=" . $typic;
     } else {
         $sql = "SELECT a.id AS p_id, a.ckey AS p_key, a.cname AS p_name , a.lid AS p_lid," . " b.id AS g_id, b.ckey AS  g_key, b.cname AS g_name, b.lid as g_lid " . " FROM tmp_xml a LEFT JOIN  tmp_xml b ON a.cgr=b.ckey AND b.user="******" AND b.ctype=" . $grtype . " WHERE a.user="******" AND a.ctype=" . $typic;
     }
     $recs = Yii::app()->db->createCommand($sql)->query();
     //we got the records for tmp_xml table
     $i = 0;
     $j = 0;
     $jj = 0;
     if (count($recs) > 0) {
         foreach ($recs as $value) {
             $doprod = 0;
             $doprodid = 0;
             $edid = 0;
             if ($value['p_lid'] === null) {
                 if ($result[$value['p_id']] === null) {
                     $doprod = -1;
                     $doprodid = 1;
                 } else {
                     $edid = (int) $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 2;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 1;
                     }
                 }
             } else {
                 if ($result[$value['p_id']] === null) {
                     $doprod = $value['p_lid'];
                 } else {
                     $edid = $result[$value['p_id']];
                     if ($edid > 0) {
                         $doprodid = 3;
                         $doprod = $edid;
                     } else {
                         $doprod = -1;
                         $doprodid = 4;
                     }
                 }
             }
             $grid = 0;
             if ($doprod < 0) {
                 if ($typic != 2) {
                     if ($value['g_lid'] === null) {
                         if ($typic == 0) {
                             $prodid = ProductgroupId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         } else {
                             $prodid = CountryId::model()->findByPk(array('ckey' => $value['g_key'], 'db' => 1));
                         }
                         if ($prodid === null) {
                             if ($typic == 0) {
                                 $group = new ProductGroup();
                                 $group->tnam = $value['g_name'];
                                 $group->save();
                                 $grid = $group->ckey;
                                 $groupid = new ProductgroupId();
                             } else {
                                 $group = new Country();
                                 $group->name = $value['g_name'];
                                 $group->save();
                                 $grid = $group->id;
                                 $groupid = new CountryId();
                             }
                             $groupid->ckey = $value['g_key'];
                             $groupid->db = 1;
                             $groupid->id = $grid;
                             $groupid->save();
                             $i++;
                         } else {
                             $grid = $prodid->id;
                         }
                     } else {
                         $grid = $value['g_lid'];
                     }
                 } else {
                     $grid = 1;
                 }
                 if ($grid > 0) {
                     if ($typic == 0) {
                         $prod = new Product();
                         $prod->tnam = $value['p_name'];
                         $prod->cgr = $grid;
                         $it = TmpXml::model()->find('ctype=:ctype AND ckey=:ckey AND user=:user', array(':ctype' => 10, ':ckey' => $value['p_key'], ':user' => Yii::app()->user->uid));
                         if ($it) {
                             $prod->it = (int) $it->cname;
                         }
                         $prod->save();
                         $grid = $prod->ckey;
                     } else {
                         if ($typic == 1) {
                             $prod = new Client();
                             $prod->name = $value['p_name'];
                             $prod->country_id = $grid;
                             $prod->save();
                             $grid = $prod->id;
                             $this->updateprop($value['p_key'], $grid);
                             $this->updatebank($value['p_key'], $grid);
                         } else {
                             $prod = new Department();
                             $prod->name = $value['p_name'];
                             $prod->save();
                             $grid = $prod->id;
                             $this->updatebank($value['p_key'], $grid, 0);
                         }
                     }
                     $j++;
                     if ($doprodid == 1) {
                         if ($typic == 0) {
                             $prodid = new ProductId();
                         } else {
                             if ($typic == 1) {
                                 $prodid = new ClientId();
                             } else {
                                 $prodid = new DepartmentId();
                             }
                         }
                         $prodid->ckey = $value['p_key'];
                         $prodid->db = 1;
                         $prodid->id = $grid;
                         $prodid->save();
                     } else {
                         if ($typic == 0) {
                             $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             if ($typic == 1) {
                                 $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             } else {
                                 $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                             }
                         }
                         if (!($prodid === null)) {
                             $prodid->id = $grid;
                             $prodid->save();
                         }
                     }
                 }
             }
             if ($doprodid == 2) {
                 if ($typic == 0) {
                     $prodid = new ProductId();
                 } else {
                     if ($typic == 1) {
                         $prodid = new ClientId();
                     } else {
                         $prodid = new DepartmentId();
                     }
                 }
                 $prodid->ckey = $value['p_key'];
                 $prodid->db = 1;
                 $prodid->id = $edid;
                 $prodid->save();
             } else {
                 if ($doprodid == 3) {
                     if ($typic == 0) {
                         $prodid = ProductId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                     } else {
                         if ($typic == 1) {
                             $prodid = ClientId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         } else {
                             $prodid = DepartmentId::model()->findByPk(array('ckey' => $value['p_key'], 'db' => 1));
                         }
                     }
                     if (!($prodid === null)) {
                         $prodid->id = $edid;
                         $prodid->save();
                     }
                 }
             }
             if ($doprod > 0) {
                 if ($typic == 0) {
                     $prod = Product::model()->findByPk($doprod);
                     if (!($prod === null)) {
                         if ($prod->tnam != $value['p_name']) {
                             $prod->tnam = $value['p_name'];
                             $prod->save();
                             $jj = 0;
                         }
                     }
                 } else {
                     if ($typic == 1) {
                         $prod = Client::model()->findByPk($doprod);
                         if (!($prod === null)) {
                             if ($prod->name != $value['p_name']) {
                                 $prod->name = $value['p_name'];
                                 $prod->save();
                                 $jj = 0;
                             }
                             $this->updateprop($value['p_key'], $prod->id);
                             $this->updatebank($value['p_key'], $prod->id);
                         }
                     } else {
                         if (!($prop = DepartmentProp::model()->findByPk(array('id' => $doprod, '_key' => 'stop')))) {
                             $prod = Department::model()->findByPk($doprod);
                             if (!($prod === null)) {
                                 if ($prod->name != $value['p_name']) {
                                     $prod->name = $value['p_name'];
                                     $prod->save();
                                     $jj = 0;
                                 }
                             }
                             $this->updatebank($value['p_key'], $doprod, 0);
                         }
                     }
                 }
             }
         }
     }
     if ($typic == 0) {
         $info[] = 'Создано новых групп товаров:' . $i;
         $info[] = 'Создано новых товаров:' . $j;
         $info[] = 'Обновлено товаров:' . $jj;
     } else {
         if ($typic == 1) {
             $info[] = 'Создано новых групп клиентов:' . $i;
             $info[] = 'Создано новых клиентов:' . $j;
             $info[] = 'Обновлено клиентов:' . $jj;
         } else {
             $info[] = 'Создано новых фирм:' . $j;
             $info[] = 'Обновлено фирм:' . $jj;
         }
     }
     return;
 }
Example #20
0
	public function actionIndex()
	{	
		$code = $this->checkKParm();
		
		if(isset($_GET['s'])){
			$sessid = $_GET['s'];
		}else{
			$sessid = '';
		}
		//$sessid = isset($_GET['s'])?$_GET['s']:'';
		
		$orderModel = $this->getOrderByRandCode($code,$sessid);
		//如果没有该订单,说明没有通过一步步预定,非法操作
		
		if($orderModel == null){
			$this->redirect(array('/tuan'));
			exit;
		}
		
		//如果已经是支付了的订单,直接跳到成功页面
		if($orderModel->status == 1){
			$this->redirect(array('/pay/over'));
			exit;
		}
		
		//计算门票总数
		/* $addsToken = 'adds'.$orderModel->id;
		$addArr = $this->checkAdditionsStep($addsToken);
		$tickers = 0;
		foreach($addArr[1] as $val)
			$tickers += $val; */
		$tickers = count($orderModel->Adds);
		
		//输出订单信息
		$oid = $orderModel->id;
		//输出参团人员信息
		$clientModel = Client::model()->findAll(array(
				'condition'=>"oid=$oid",
				));
		//保险id
		/* $insToken = 'ins'.$orderModel->id;
		$insuranceid = $this->getInsuranceId($insToken); */
		$insuModel = OrderInsurance::model()->find(array('select'=>'id','condition'=>"oid=$oid"));
		if($insuModel == null){
			$insuranceid = 0;
		}else{
			$insuranceid = $insuModel->id;
		}
		/* $isruModel = $orderModel->Insu->id; */
		/* if($isruModel != null){
			$insuranceid = $isruModel->id;
		} */
		
		//从session中得到房间信息
		/* $token = 'order'.$orderModel->id;
		$roomArr = $this->checkOrderRoomStep($token); */
		$roomArr = count($orderModel->Rooms);
		
		//联系人信息
		$conid = $orderModel->cid;
		$contact = Contacter::model()->find(array('condition'=>"id=$conid"));
		
		$this->render('index',array(
					'departure'=>date('Y-m-d',$orderModel->departure),
					'travel'=> $this->getTravelInfo($orderModel->tid),//旅游信息
					'tuanCode'=>$this->getTuanCode($orderModel->cal_id),//出团编号
					'clientModel'=>$clientModel,//参团人员信息,是一个数组
					'insurancename'=>$this->getNowInsurance($insuranceid),//保险名称
					'ticker'=>$tickers,//门票个数
					'aduit'=>$orderModel->aduit,//成人个数
					'child'=>$orderModel->child,//儿童个数
					'house'=>$roomArr,//$roomArr['rooms'],//房间个数
					//'housetypeid'=>$roomArr['type'],//房型ID,是个数组 array
					'gethouselist'=>$this->getHouseList(),//房型名称列表
					'totalprice'=>$this->getTotalPriceFormDb($orderModel->id),//总价格
					'token'=>$orderModel->id,
					'orid'=>$orderModel->id,
				'orderno'=>$orderModel->trackcode,
				'contacts'=>$contact,
					));
	}
Example #21
0
 public function setClients($clients, $clientType = self::CLIENT_TYPE_OWNER, $instantSave = true)
 {
     if (!in_array($clientType, self::getClientTypes())) {
         throw new InvalidArgumentException('Client type must be in list [' . implode(', ', self::getClientTypes()) . '] actual value : ' . $clientType);
     }
     $clientTableName = $clientType == self::CLIENT_TYPE_TENANT ? self::TENANT_TABLE_NAME : self::OWNER_TABLE_NAME;
     if ($this->pro_id) {
         $sql = 'DELETE FROM ' . $clientTableName . ' WHERE propertyId = ' . $this->pro_id;
         Yii::app()->db->createCommand($sql)->execute();
         $sql = [];
         foreach ($clients as $value) {
             $sql[] = "('" . $this->pro_id . "', '" . $value . "')";
         }
         if ($sql) {
             $sql = "REPLACE INTO " . $clientTableName . " (propertyId, clientId) VALUES " . implode(',', $sql) . "";
             Yii::app()->db->createCommand($sql)->execute();
         }
     } else {
         $this->attachEventHandler('onAfterSave', function () use($clients, $clientType) {
             static $run = false;
             if (!$run) {
                 $this->setClients($clients, $clientType);
                 $run = true;
             }
         });
     }
     if ($clientType == self::CLIENT_TYPE_TENANT) {
         $this->tenants = Client::model()->findAllByPk($clients);
     } else {
         $this->owners = Client::model()->findAllByPk($clients);
     }
 }
Example #22
0
	protected function getHasPayClientCount($cid)
	{
		$arr = Order::model()->findAll(array(
				'select'=>'id,cid',
				'condition'=>"cal_id=$cid and status=1",
		));
		$count = 0;
		foreach($arr as $value){
			$oid = $value->id;
			$count += Client::model()->count(array(
					'condition'=>"oid=$oid",
			));
		}
	
		return $count;
	}
 public function actionIndex()
 {
     $concessioners = Concessioner::model()->findAll();
     $vehicles = Vehicle::model()->findAllByAttributes(array('status' => 'ACTIVE'));
     $versions = VehicleVersion::model()->findAllByAttributes(array('status' => 'ACTIVE'));
     $cities = City::model()->findAll();
     if (isset($_POST['Search'])) {
         $criteria = new CDbCriteria();
         $date = "";
         $vehicle_or_version = "";
         $columns = array();
         switch ($_POST['Search']['module']) {
             case "TechnicalDate":
                 $columns = array('id', 'client.identity', 'client.name', 'client.lastname', 'client.email', 'client.phone', 'client.preference_contact', 'client.cellphone', 'client.medio', 'vehicle.model', 'vehicle.year', 'vehicle.license_plate', 'vehicle.kilometer', 'concessioner.name', 'concessioner.address', 'work', 'preference_date', 'hour', 'taxi', 'detail_work', 'creation_date');
                 $date = "creation_date";
                 $vehicle_or_version = "vehicle_id";
                 break;
             case "Quotation":
                 $columns = array('id', 'Cédula' => 'client.identity:text', 'Nombre' => 'client.name:text', 'Apellido' => 'client.lastname:text', 'client.email:text', 'client.phone', 'client.preference_contact', 'client.preference_contact2', 'client.cellphone', 'client.localize', 'client.medio', 'concessioner.name', 'Ciudad' => 'concessioner.city.name', 'Vehiculo 1' => 'vehicleversion.vehicle.name', 'Referencia 1 vehículo' => 'vehicleversion.reference', 'Vehiculo 2' => 'vehicleversion2.vehicle.name', 'Referencia 2 vehículo' => 'vehicleversion2.reference', 'Tiempo' => 'time:text', 'Fecha de creación' => 'creation_date');
                 $date = "creation_date";
                 $vehicle_or_version = "vehicle_version_id";
                 break;
             case "Replacement":
                 $columns = array('id:number', 'Cédula' => 'client.identity:text', 'Nombre' => 'client.name:text', 'Apellido' => 'client.lastname:text', 'client.email:text', 'client.phone', 'client.preference_contact', 'client.cellphone', 'client.medio', 'Concesionario' => 'concessioner.name:text', 'Parte a reemplazar' => 'part:text', 'vehicle.model', 'vehicle.year', 'vehicle.license_plate', 'vehicle.kilometer', 'vehicle.chasis', 'Fecha de creación' => 'creation_date');
                 $vehicle_or_version = "vehicle_id";
                 break;
             case "Suggestion":
                 $columns = array('id:number', 'Cédula' => 'client.identity:text', 'Nombre' => 'client.name:text', 'Apellido' => 'client.lastname:text', 'client.email:text', 'client.phone', 'client.preference_contact', 'client.cellphone', 'client.medio', 'Concesionario' => 'concessioner.name:text', 'Vehículo' => 'vehicle.name:text', 'Descripción' => 'description:text', 'Tipo' => 'type:text', 'Fecha de creación' => 'creation_date:date');
                 $date = "creation_date";
                 break;
             case "Satisfaction":
                 $columns = array('id:number', 'Cédula' => 'quotation.client.identity:text', 'Nombre' => 'quotation.client.name:text', 'Apellido' => 'quotation.client.lastname:text', 'quotation.client.email:text', 'quotation.client.phone', 'quotation.client.preference_contact', 'quotation.client.cellphone', 'client.medio', 'Concesionario' => 'quotation.concessioner.name:text', ' Cliente Contactado' => 'contact:text', 'Puntaje' => 'score:text', 'Descripción' => 'description:text', 'Fecha de creación' => 'creation_date:date');
                 $date = "creation_date";
                 break;
             case "SatisfactionR":
                 $columns = array('id:number', 'Cédula' => 'replacement.client.identity:text', 'Nombre' => 'replacement.client.name:text', 'Apellido' => 'replacement.client.lastname:text', 'replacement.client.email:text', 'replacement.client.phone', 'replacement.client.preference_contact', 'replacement.client.cellphone', 'Concesionario' => 'replacement.concessioner.name:text', ' Cliente Contactado' => 'contact:text', 'client.medio', 'Puntaje' => 'score:text', 'Descripción' => 'description:text', 'Fecha de creación' => 'creation_date:date');
                 $date = "creation_date";
                 break;
             case "SatisfactionS":
                 $columns = array('id:number', 'Cédula' => 'suggestion.client.identity:text', 'Nombre' => 'suggestion.client.name:text', 'Apellido' => 'suggestion.client.lastname:text', 'suggestion.client.email:text', 'suggestion.client.phone', 'suggestion.client.preference_contact', 'suggestion.client.cellphone', 'client.medio', 'Concesionario' => 'suggestion.concessioner.name:text', ' Cliente Contactado' => 'contact:text', 'Puntaje' => 'score:text', 'Descripción' => 'description:text', 'Fecha de creación' => 'creation_date:date');
                 $date = "creation_date";
                 break;
         }
         if ($_POST['Search']['date_from'] && $_POST['Search']['date_to']) {
             $criteria->addBetweenCondition('creation_date', $_POST['Search']['date_from'], $_POST['Search']['date_to']);
         }
         if ($_POST['Search']['city'] != 0 && $_POST['Search']['concessioner'] == 0) {
             $citiess = City::model()->findByPk($_POST['Search']['city']);
             foreach ($citiess->concessioners as $concessioner) {
                 $criteria->addSearchCondition('concessioner_id', $concessioner->id, "", 'OR');
             }
         } elseif ($_POST['Search']['city'] != 0 && $_POST['Search']['concessioner'] != 0) {
             $criteria->addSearchCondition('concessioner_id', $_POST['Search']['concessioner']);
         }
         if ($_POST['Search']['identity']) {
             $clients = Client::model()->findAllByAttributes(array('identity' => $_POST['Search']['identity']));
             foreach ($clients as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['name']) {
             $clients2 = Client::model()->findAllByAttributes(array('name' => $_POST['Search']['name']));
             foreach ($clients2 as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['lastname']) {
             $clients3 = Client::model()->findAllByAttributes(array('lastname' => $_POST['Search']['lastname']));
             foreach ($clients3 as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['email']) {
             $clients4 = Client::model()->findAllByAttributes(array('email' => $_POST['Search']['email']));
             foreach ($clients4 as $client) {
                 $criteria->addSearchCondition('client_id', $client->id, "", 'OR');
             }
         }
         if ($_POST['Search']['model'] != 0 && $_POST['Search']['version'] == 0) {
             if ($vehicle_or_version == "vehicle_id") {
                 $criteria->addSearchCondition('vehicle_id', $_POST['Search']['model']);
             } elseif ($vehicle_or_version == "vehicle_version_id") {
                 $vehicle1 = Vehicle::model()->findByPk($_POST['Search']['model']);
                 foreach ($vehicle1->vehicleVersions as $version) {
                     $criteria->addSearchCondition('vehicle_version_id', $version->id, "", 'OR');
                     $criteria->addSearchCondition('vehicle_version_id2', $version->id, "", 'OR');
                 }
             }
         } elseif ($_POST['Search']['model'] == 0 && $_POST['Search']['version'] != 0) {
             if ($vehicle_or_version == "vehicle_version_id") {
                 $criteria->addSearchCondition('vehicle_version_id', $_POST['Search']['version'], "", 'OR');
                 $criteria->addSearchCondition('vehicle_version_id2', $_POST['Search']['version'], "", 'OR');
             }
         }
         if ($_POST['Search']['module'] != "0") {
             $pagination = new EDTPagination();
             $criteria->order = "id DESC";
             $pagination->applyLimit($criteria);
             $sort = new EDTSort($_POST['Search']['module'], $columns);
             $sort->defaultOrder = 'id';
             //die(print_r($criteria));
             self::$dataProvider = new CActiveDataProvider($_POST['Search']['module'], array('criteria' => $criteria, 'pagination' => $pagination, 'sort' => $sort));
         } else {
             self::$dataProvider = new CActiveDataProvider('TechnicalDate', array('criteria' => $criteria));
         }
         $widget2 = $this->widget('EExcelView', array('dataProvider' => self::$dataProvider, 'grid_mode' => 'export', 'title' => 'report', 'autoWidth' => true, 'template' => "{summary}\n{items}\n{exportbuttons}\n{pager}", 'filename' => 'report', 'stream' => false, 'columns' => $columns));
         $widget1 = $this->createWidget('ext.EDataTables.EDataTables', array('id' => 'data_table', 'dataProvider' => self::$dataProvider, 'columns' => $columns, 'serverData' => array("module" => $_POST['Search']['module']), 'buttons' => array('refresh' => null), 'options' => array('bStateSave' => false, 'bPaginate' => false, 'bLengthChange' => true)));
         if (!Yii::app()->getRequest()->getIsAjaxRequest()) {
             $export = 0;
             if ($_POST['Search']['print'] == "YES") {
                 $export = 1;
             }
             $this->render('index', array('cities' => $cities, 'vehicles' => $vehicles, 'versions' => $versions, 'concessioners' => $concessioners, 'widget2' => $widget2, 'widget1' => $widget1, 'export' => $export));
             return;
         } else {
             echo json_encode(self::$wid->getFormattedData(intval($_REQUEST['sEcho'])));
             Yii::app()->end();
         }
     } else {
         $this->render('index', array('cities' => $cities, 'vehicles' => $vehicles, 'versions' => $versions, 'concessioners' => $concessioners));
     }
 }
Example #24
0
 public function setClients(array $clients, $instantSave = true)
 {
     if ($instantSave && (!$this->isNewRecord || $this->off_id)) {
         $sql = "DELETE FROM cli2off WHERE c2o_off = " . $this->off_id;
         Yii::app()->db->createCommand($sql)->execute();
         $sql = [];
         foreach ($clients as $value) {
             $sql[] = "('" . $this->off_id . "', '" . $value . "')";
         }
         if ($sql) {
             $sql = "REPLACE INTO cli2off (c2o_off, c2o_cli) VALUES " . implode(',', $sql) . "";
             Yii::app()->db->createCommand($sql)->execute();
         }
     } else {
         $run = false;
         $this->attachEventHandler('onAfterSave', function (CEvent $event) use($clients, &$run) {
             if (!$run) {
                 $event->sender->setClients($clients);
                 $run = true;
             }
         });
     }
     $this->clients = Client::model()->findAllByPk($clients);
 }
Example #25
0
 protected function sessionInfo($data = array())
 {
     //$data=array();
     $data['items'] = Yii::app()->shoppingCart->getCart();
     $data['count_item'] = Yii::app()->shoppingCart->getQuantityTotal();
     $data['payments'] = Yii::app()->shoppingCart->getPayments();
     $data['count_payment'] = count(Yii::app()->shoppingCart->getPayments());
     $data['payment_received'] = Yii::app()->shoppingCart->getPaymentsTotal();
     $data['sub_total'] = Yii::app()->shoppingCart->getSubTotal();
     $data['total_b4vat'] = Yii::app()->shoppingCart->getTotalB4Vat();
     $data['total'] = Yii::app()->shoppingCart->getTotal();
     $data['total_due'] = Yii::app()->shoppingCart->getTotalDue();
     $data['qtytotal'] = Yii::app()->shoppingCart->getQuantityTotal();
     $data['amount_change'] = Yii::app()->shoppingCart->getAmountDue();
     // This is only work for current invoice
     $data['amount_change'] = Yii::app()->shoppingCart->getTotalDue();
     // Outstanding + Current Invoice / Hot Bill - Total Payment
     $data['customer_id'] = Yii::app()->shoppingCart->getCustomer();
     $data['comment'] = Yii::app()->shoppingCart->getComment();
     $data['employee_id'] = Yii::app()->session['employeeid'];
     $data['salerep_id'] = Yii::app()->shoppingCart->getSaleRep();
     $data['transaction_date'] = date('d/m/Y');
     $data['transaction_time'] = date('h:i:s');
     $data['session_sale_id'] = Yii::app()->shoppingCart->getSaleId();
     //$data['employee'] = ucwords(Yii::app()->session['emp_fullname']);
     $data['total_discount'] = Yii::app()->shoppingCart->getTotalDiscount();
     $data['total_gst'] = Yii::app()->shoppingCart->getTotalGST();
     $data['disable_editprice'] = Yii::app()->user->checkAccess('sale.editprice') ? false : true;
     $data['disable_discount'] = Yii::app()->user->checkAccess('sale.discount') ? false : true;
     $data['colspan'] = Yii::app()->settings->get('sale', 'discount') == 'hidden' ? '2' : '3';
     $data['discount_amount'] = Common::calDiscountAmount($data['total_discount'], $data['sub_total']);
     $data['gst_amount'] = $data['total_b4vat'] * $data['total_gst'] / 100;
     $discount_arr = Common::Discount($data['total_discount']);
     $data['discount_amt'] = $discount_arr[0];
     $data['discount_symbol'] = $discount_arr[1];
     /** Rounding a numbere to a nearest 10 or 100 (Floor : round down, Ceil : round up , Round : standard round 
      *  Ref: http://stackoverflow.com/questions/1619265/how-to-round-up-a-number-to-nearest-10
      *    ** http://stackoverflow.com/questions/6619377/how-to-get-whole-and-decimal-part-of-a-number
      *  Method : using Round method here 
      */
     $data['usd_2_khr'] = Yii::app()->settings->get('exchange_rate', 'USD2KHR');
     $data['total_khr'] = $data['total'] * $data['usd_2_khr'];
     $data['amount_change_khr'] = $data['amount_change'] * $data['usd_2_khr'];
     //Stupid PHP passing calculation 0.9-1 * 4000 = -3999.1 ,  (0.9-1) * 4000 = 400 correct
     /*
      * Total is to round up [Ceil] - Company In
      * Amount_Change suppose to round done [Floor] but usually this value is minus so using [Ceil] instead
      */
     $data['total_khr_round'] = ceil($data['total_khr'] / 100) * 100;
     $data['amount_change_khr_round'] = ceil($data['amount_change_khr'] / 100 - 0.1) * 100;
     // Got no idea why PHP ceil(-0.1/100)*100 = 399
     $data['amount_change_whole'] = ceil($data['amount_change']);
     // floor(1.25)=1
     $data['amount_change_fraction_khr'] = ceil(($data['amount_change'] - $data['amount_change_whole']) * $data['usd_2_khr'] / 100 - 0.1) * 100;
     //Added 0.1 to solve ceil (-0.1/100)*100=399
     /*** Customer Account Info ***/
     $account = $this->custAccountInfo($data['customer_id']);
     $customer = Client::model()->clientByID($data['customer_id']);
     $employee = Employee::model()->employeeByID($data['employee_id']);
     $sale_rep = Employee::model()->employeeByID($data['salerep_id']);
     $data['account'] = $account;
     $data['customer'] = $customer;
     $data['employee'] = $employee;
     $data['acc_balance'] = $account !== null ? $account->current_balance : '';
     $data['cust_fullname'] = $customer !== null ? $customer->first_name . ' ' . $customer->last_name : 'General';
     $data['salerep_fullname'] = $sale_rep !== null ? $sale_rep->first_name . ' ' . $sale_rep->last_name : $employee->first_name . ' ' . $employee->last_name;
     $data['salerep_tel'] = $sale_rep !== null ? $sale_rep->mobile_no : '';
     $data['cust_address1'] = $customer !== null ? $customer->address1 : '';
     $data['cust_mobile_no'] = $customer !== null ? $customer->mobile_no : '';
     $data['cust_fax'] = $customer !== null ? $customer->fax : '';
     $data['cust_notes'] = $customer !== null ? $customer->notes : '';
     $data['cust_contact_fullname'] = '';
     if ($customer !== null) {
         $data['cust_contact_fullname'] = $customer->contact !== null ? $customer->contact->first_name . ' ' . $customer->contact->last_name : '';
     }
     return $data;
 }
 /**
  * This got messy
  *
  * @param $instructionId
  * @throws CHttpException
  */
 public function actionSendMailshot($instructionId)
 {
     $model = new Client('search');
     if (isset($_POST['send']) && $_POST['send']) {
         $instruction = Deal::model()->findByPk($instructionId);
         $type = MailshotType::model()->findByPk($_POST['MailshotType']);
         $model->attributes = $_GET['Client'];
         $dataProvider = $model->search();
         $dataProvider->setPagination(['pageSize' => 100]);
         if (!$type) {
             throw new CHttpException(404, 'Mailshot Type [name: ' . $_POST['MailshotType'] . '] was not found');
         }
         if (!$instruction) {
             throw new CHttpException(404, 'Instruction [id: ' . $instructionId . '] was not found');
         }
         $mailshot = new MandrillMailshot();
         $mailshot->instructionId = $instruction->dea_id;
         $mailshot->type = $type->name;
         $mailshot->save();
         if ($type->templatePath && file_exists($type->templatePath)) {
             ob_start();
             include $type->templatePath;
             $htmlTemplate = ob_get_clean();
         } else {
             $htmlTemplate = $this->execTemplate($type->htmlTemplate);
         }
         $textTemplate = $this->execTemplate($type->textTemplate);
         $mandrillMessagePreset = new MandrillMessage();
         $mandrillMessagePreset->setFrom(Yii::app()->params['mailshot']['sender_email'], Yii::app()->params['mailshot']['sender_name']);
         $mandrillMessagePreset->setHtmlBody($htmlTemplate);
         $mandrillMessagePreset->setTextBody($textTemplate);
         $mandrillMessagePreset->setSubject($type->subject);
         $mandrillMessagePreset->setPreserveRecepients(false);
         $mandrillMessagePreset->setGlobalMergeVar('MAILSHOT_ID', $mailshot->id);
         $mandrillMessagePreset->setGlobalMergeVar('INSTRUCTION_ID', $instruction->dea_id);
         $mandrillMessagePreset->setGlobalMergeVar('INSTRUCTION_PRICE', Locale::formatCurrency($instruction->dea_marketprice));
         $mandrillMessagePreset->setGlobalMergeVar('INSTRUCTION_TITLE', $instruction->title);
         $mandrillMessagePreset->setGlobalMergeVar('INSTRUCTION_STRAPLINE', $instruction->dea_strapline);
         $mandrillMessagePreset->setGlobalMergeVar('OFFICE_TITLE', $instruction->branch->office->title);
         $mandrillMessagePreset->setGlobalMergeVar('OFFICE_NUMBER', $instruction->branch->bra_tel);
         if (isset($_POST['test']) && $_POST['test']) {
             $mandrillMessagePreset->enableTest();
         }
         $iterator = new DataProviderIterator($dataProvider);
         /** @var $mandrillMessage MandrillMessage */
         $mandrillMessage = null;
         $x = 0;
         $staffEmails = array_fill_keys(Yii::app()->params['mailshot']['alwaysSendTo'], '?');
         if (Yii::app()->params['mandrill']['test_run']) {
             $testEmails = Yii::app()->params['mandrill']['test_emails'];
         }
         /** @var $client Client */
         foreach ($iterator as $client) {
             $email = $client->cli_email;
             if (isset($testEmails)) {
                 if (!$testEmails) {
                     break;
                 }
                 $email = array_shift($testEmails);
             }
             if (!$email) {
                 continue;
             }
             //we are sending emails to our staff in a different message
             if (array_key_exists($email, $staffEmails)) {
                 continue;
             }
             if ($x % Yii::app()->params['mandrill']['mails_in_message'] === 0) {
                 if ($mandrillMessage) {
                     $mandrillMessage->send();
                     $mailshot->addMessage($mandrillMessage);
                 }
                 $mandrillMessage = clone $mandrillMessagePreset;
             }
             $mandrillMessage->addTo($email, $client->getFullName());
             $mandrillMessage->setRecepientMergeVar($email, 'CLIENT_FULLNAME', $client->getFullName());
             $mandrillMessage->setRecepientMergeVar($email, 'CLIENT_SALUTATION', $client->cli_salutation);
             $mandrillMessage->setRecepientMergeVar($email, 'CLIENT_ID', $client->cli_id);
             $mandrillMessage->setRecepientMergeVar($email, 'CLIENT_EMAIL', $email);
             $mandrillMessage->setRecepientMetaData($email, 'clientId', $client->cli_id);
             $x++;
         }
         if (!$mandrillMessage->id) {
             $mandrillMessage->send();
             $mailshot->addMessage($mandrillMessage);
         }
         /**
          * doing a trick. will send an email to everyone in staff list to avoid complains
          */
         $staffMessage = clone $mandrillMessagePreset;
         $clients = Client::model()->findAll('cli_email IN (' . implode(', ', $staffEmails) . ')', array_keys($staffEmails));
         foreach ($clients as $client) {
             $email = $client->cli_email;
             $staffMessage->addTo($email, $client->getFullName());
             $staffMessage->setRecepientMergeVar($email, 'CLIENT_FULLNAME', $client->getFullName());
             $staffMessage->setRecepientMergeVar($email, 'CLIENT_SALUTATION', $client->cli_salutation);
             $staffMessage->setRecepientMergeVar($email, 'CLIENT_ID', $client->cli_id);
             $staffMessage->setRecepientMergeVar($email, 'CLIENT_EMAIL', $email);
             $staffMessage->setRecepientMetaData($email, 'clientId', $client->cli_id);
         }
         $staffMessage->send();
         $mailshot->addMessage($staffMessage);
         Yii::app()->user->setFlash('mailshot-sent', 'Mailshot successfully sent');
         $this->redirect(['instruction/summary', 'id' => $instructionId]);
     }
     $this->render('sendMailshot');
 }
Example #27
0
 /**
  * @return array counties names indexed by country
  */
 public function getClientOptions()
 {
     if ($this->allowOnlySuperAdmin()) {
         $allClients = Client::model()->findAll();
     } else {
         $condition = "Client_ID = :clientid";
         $params = array(":clientid" => yii::app()->user->getClientID());
         $allClients = Client::model()->findAll($condition, $params);
     }
     return CHtml::listData($allClients, 'Client_ID', 'fullName');
 }
 public static function clientByID($id)
 {
     $model = Client::model()->findByPk($id);
     return isset($model) ? $model : null;
 }
Example #29
0
 /**
  * HAS ONE relation
  * @return
  */
 public function client()
 {
     return Client::model()->findByAttributes(array('client' => $this->getPrimaryKey()));
 }
 public function actionCallback($email = '', $telephone = '', $message = '')
 {
     $this->layout = '/layouts/popup-iframe';
     if (isset($_POST['Callback']) && $_POST['Callback']) {
         $callback = $_POST['Callback'];
         $email = $callback['email'];
         $telephone = $callback['telephone'];
         $criteria = new CDbCriteria();
         $criteria->compare('cli_email', $email);
         $criteria->with = ['telephones'];
         $client = Client::model()->find($criteria);
         if ($client) {
             if (!$telephone) {
                 $telephone = $client->telephones[0]->tel_number;
             } else {
                 if ($client->telephones[0]->tel_number != $telephone) {
                     $telExist = false;
                     $tels = $client->telephones;
                     foreach ($tels as $tel) {
                         if ($tel->tel_number == $telephone) {
                             $telExist = true;
                             break;
                         }
                     }
                     if (!$telExist) {
                         $telephone = new Telephone();
                         $telephone->tel_type = 'Other';
                         $telephone->tel_number = $telephone;
                         $telephone->tel_cli = $client->cli_id;
                         $telephone->save();
                     }
                 }
             }
         }
         $message = $this->sendEmailForRegisteredClient($email, $telephone);
         echo json_encode($message);
     } else {
         $this->render('_callbackForm', ['email' => $email, 'telephone' => $telephone, 'message' => $message]);
     }
 }