<div class="row"> <?php echo $form->label($model, 'code'); ?> <?php echo $form->textArea($model, 'code'); ?> </div> <div class="row"> <?php echo $form->label($model, 'action'); ?> <?php echo $form->dropDownList($model, 'action', GxHtml::listDataEx(VoucherAction::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All'))); ?> </div> <div class="row"> <?php echo $form->label($model, 'action_date'); ?> <?php echo $form->textField($model, 'action_date'); ?> </div> <div class="row"> <?php echo $form->label($model, 'deleted_at');
<?php $this->breadcrumbs = array($model->label(2) => array('index'), Yii::t('app', 'Manage')); $this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('voucher-history-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n"); ?> <h1><?php echo Yii::t('app', 'Manage') . ' ' . GxHtml::encode($model->label(2)); ?> </h1> <p> You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done. </p> <?php echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'voucher-history-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', 'code', array('name' => 'action', 'value' => 'GxHtml::valueEx($data->action0)', 'filter' => GxHtml::listDataEx(VoucherAction::model()->findAllAttributes(null, true))), 'action_date', 'deleted_at', 'parameters', array('class' => 'CButtonColumn'))));
<?php echo $form->labelEx($model, 'code'); ?> <?php echo $form->textArea($model, 'code'); ?> <?php echo $form->error($model, 'code'); ?> </div><!-- row --> <div class="row"> <?php echo $form->labelEx($model, 'action'); ?> <?php echo $form->dropDownList($model, 'action', GxHtml::listDataEx(VoucherAction::model()->findAllAttributes(null, true))); ?> <?php echo $form->error($model, 'action'); ?> </div><!-- row --> <div class="row"> <?php echo $form->labelEx($model, 'action_date'); ?> <?php echo $form->textField($model, 'action_date'); ?> <?php echo $form->error($model, 'action_date'); ?>
public function actionsync() { $this->layout = false; $return = []; $error = 0; $lang = 'en'; $error_count = 0; $sync_count = 0; $in_array = array('en', 'ar', 'tr'); $history_intry = new VoucherHistory(); $history_intry->action = VoucherAction::model()->find("name = 'SYNC'")->id; if (isset($_POST) && !empty($_POST)) { // IMPORT MOBILE DATA $post = ""; //foreach ($_POST as $key => $value) { // $post .= $key . " => " . $value . "/"; //} $history_intry->parameters = $post; if (isset($_POST['lang']) && !empty($_POST['lang']) && in_array($_POST['lang'], $in_array)) { $lang = filter_input(INPUT_GET, "lang", FILTER_SANITIZE_STRING); } if (!isset($_POST['redeemed_voucher']) || empty($_POST['redeemed_voucher'])) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } if (!isset($_POST['imei']) || empty($_POST['imei'])) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } $voucher_codes = $_POST['redeemed_voucher']; $redeem_redeemed_status = VoucherStatus::model()->find("name = :name", array(":name" => "REDEEMED")); foreach ($voucher_codes as $voucher_code) { $voucher = Voucher::model()->find("code = :code", array(":code" => $voucher_code)); if (!$voucher) { $error_count += 1; $error .= $voucher_code . ", "; } else { $voucher->status_id = $redeem_redeemed_status->id; $voucher->sync_date = new CDbExpression('NOW()'); $voucher->update(); $voucher->save(); $sync_count += 1; } } if ($error_count > 0) { $err_arr = []; $err_arr['count'] = $error_count; $err_arr['vouchers'] = $error; $this->respond("NOT_ALL_SYNCED", $err_arr, $lang, $history_intry); } else { $this->respond(NULL, $sync_count, $lang, $history_intry); } } elseif (isset($_GET) && !empty($_GET)) { // SEND NEW DATA $get = ""; foreach ($_GET as $key => $value) { $get .= $key . " => " . $value . "/"; } $history_intry->parameters = $get; if (!isset($_GET['imei']) || empty($_GET['imei'])) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } if (isset($_GET['lang']) && !empty($_GET['lang']) && in_array($_GET['lang'], $in_array)) { $lang = filter_input(INPUT_GET, "lang", FILTER_SANITIZE_STRING); } $imei = $_GET['imei']; $phone = Phone::model()->find("imei = :imei", array(":imei" => $imei)); if (!$phone) { $this->respond('ERR_INVALID_REEQUEST', [], $lang, $history_intry); } $vendor_mobiles = VendorMobile::model()->findAll("phone_id = :phone_id", array(":phone_id" => $phone->id)); $export_list = []; $update_list = []; foreach ($vendor_mobiles as $vendor_mobile) { $voucher_status = VoucherStatus::model()->find("name = :name", array(":name" => "PENDING")); $vouchers = Voucher::model()->findAll("status_id = :status_id and vendor_id = :vendor_id", array(":status_id" => $voucher_status->id, ":vendor_id" => $vendor_mobile->vendor_id)); //print_r($vouchers); foreach ($vouchers as $voucher) { $obj = new stdClass(); if ($voucher->distributionVoucher->subdistribution->distribution->id == $vendor_mobile->distribution_id) { foreach ($voucher as $key => $value) { $obj->{$key} = $value; } $beneficiary = Beneficiary::model()->findByPk($voucher->ben_id); if ($beneficiary->registration_code) { $obj->registration_code = $beneficiary->registration_code; } $subdistribution = $voucher->distributionVoucher->subdistribution; $obj->start_date = $subdistribution->start_date; $obj->expiration_date = $subdistribution->end_date; $obj->status_name = $voucher->status->name; array_push($export_list, $obj); array_push($update_list, $voucher); } } } $this->respond(NULL, $export_list, $lang, $history_intry, false); foreach ($update_list as $item) { $in_mobile_status = VoucherStatus::model()->find("name = 'IN_MOBILE'"); $item->status_id = $in_mobile_status->id; $item->update(); $item->save(); } Yii::app()->end(); } else { $this->respond('ERR_INVALID_REEQUEST', [], $lang, NULL); } }