public function actionModify($flag) { $model = Sale::model()->findByPk(1); $oldpic =''; switch($flag){ case 'top': $oldpic = $model->bgtop;$field='bgtop';break; case 'ttit': $oldpic = $model->titletuan;$field='titletuan';break; case 'tbg': $oldpic = $model->bgtuan;$field='bgtuan';break; case 'stit': $oldpic = $model->titlesale;$field='titlesale';break; case 'sbg': $oldpic = $model->bgsale;$field='bgsale';break; case 'bottom': $oldpic = $model->bgbottom;$field='bgbottom';break; } if(isset($_POST['Sale'])){ $newpic = CUploadedFile::getInstance($model,$field); if($newpic){ //删除原来的图片 if(file_exists('./'.$oldpic)){ @unlink('./'.$oldpic); } //上传新的图片 $preRand = 'img_'.$now.mt_rand(100,999); $imgName = $preRand.'.'.$newpic->extensionName; $dir = date('Ymd',$now); if(!is_dir('uploads/'.$dir)) { mkdir('uploads/'.$dir); } $newpic->saveAs('uploads/'.$dir.'/'.$imgName); $_POST['Sale'][$mykey] = '/uploads/'.$dir.'/'.$imgName;//成功,返回路径 $model->attributes = $_POST['Sale']; if($model->save(false)){ $this->redirect(array('index')); } } } $this->render('modify',array( 'oldpic'=>$oldpic, 'field'=>$field, )); }
public function actionElement($param) { //Если параметр текст - это каталог, если число - элемент $paramArr = explode("/", $param); $paramArr = array_pop($paramArr); if (is_numeric($paramArr)) { //Число - это элемент $model = Sale::model()->findByPk((int) $paramArr); //Смотрим, нужно ли вставить фотогалерею $model->description = $this->addPhotogalery($model->description); $render = 'view'; } else { //Список новостей категории $modelGroup = SaleGroup::model()->find('url LIKE "' . $paramArr . '"'); $model = array(); $model['group'] = array(); $model['no_group'] = Sale::model()->findAll(array("condition" => "status!=0 AND group_id = " . $modelGroup->id, "order" => "id DESC")); $render = 'index'; } if (empty($model)) { throw new CHttpException(404, 'The page can not be found.'); } $this->render($render, array('model' => $model)); }
public function actionDeleteSale($sale_id) { $result_id = Sale::model()->deleteSale($sale_id, 'Cancel Suspended Sale', Yii::app()->wshoppingCart->getEmployee()); if ($result_id === -1) { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, '<strong>Oh snap!</strong> Change a few things up and try submitting again.'); } else { Yii::app()->wshoppingCart->clearAll(); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, '<strong>Well done!</strong> Invoice Id ' . $sale_id . 'have been deleted successfully!'); $this->redirect('ListSuspendedSale'); } }
public function copyEntireSuspendSale($sale_id) { $this->clearAll(); $sale = Sale::model()->findbyPk($sale_id); $sale_item = SaleItem::model()->getSaleItem($sale_id); $payments = SalePayment::model()->getPayment($sale_id); foreach ($sale_item as $row) { if ($row->discount_type == '$') { $discount_amount = $row->discount_type . $row->discount_amount; } else { $discount_amount = $row->discount_amount; } $this->addItem($row->item_id, $row->quantity, $discount_amount, $row->price, $row->description); } foreach ($payments as $row) { $this->addPayment($row->payment_type, $row->payment_amount); } $this->setCustomer($sale->client_id); $this->setComment($sale->remark); $this->setTotalDiscount($sale->discount_amount); $this->setSaleId($sale_id); }
public function actionAjax() { if (isset($_POST)) { switch ((int) $_POST['type']) { case 1: //Смена статуса $model = $this->loadModel((int) $_POST['id']); $model->status = $model->status == 1 ? 0 : 1; $model->save(); //Меняем статус для новостей в группе foreach (Sale::model()->findAll('group_id = ' . $model->id) as $data) { $data->status = $model->status; $data->save(); } break; } echo CJavaScript::jsonEncode('ok'); } Yii::app()->end(); }
public function gridNoteColumn($data, $row) { echo Sale::model()->paymentNote($data['sale_id']); }
<legend><?php echo Yii::t("Bootstrap", "LIST.Sale"); ?> </legend> <?php $assetsDir = Yii::app()->basePath; $labels = Sale::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'pages-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'dataProvider' => $model->search(), 'filter' => null, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array(array('header' => $labels["id"], 'name' => "id"), array('header' => $labels["name"], 'name' => "name"), array('header' => $labels["brieftext"], 'name' => "brieftext"), array('header' => 'Статус', 'name' => "status", 'type' => 'raw', 'value' => function ($data) { return ' <a href="#" class="on-off-product" data-id="' . $data->id . '" data-status="' . $data->status . '"> <div style="margin-left:20px; width: 13px; height: 13px; border-radius: 3px; background:' . ($data->status == 1 ? 'green' : 'red') . '"></div> </a> '; }, 'filter' => ''), array('header' => $labels["primary"], 'name' => "primary", 'value' => 'Sale::model()->getDownliststatus($data->primary)', 'filter' => Sale::model()->getStatuslist()), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap'))))); ?> <a href="/admin/<?php echo Yii::app()->controller->module->id; ?> /<?php echo Yii::app()->controller->id; ?> /create" class="btn">Добавить акцию</a> <script> //Меняем статус $(document).on('click', '.on-off-product', function(){ $.ajax({ type: 'POST',
/** * @param bool $primary - выводить только те новости, у которых стоит признак "Главные новости" * @param int $count - количество новостей * @param int $sort - сортировка 1-по убыванию, 2-по возрастанию */ public function getLastSales($primary = true, $count = 3, $sort = 1) { $retrnData = null; $paramArray = array(); if ($primary == true) { $paramArray[] = '`primary`="1"'; } $param = implode(" AND ", $paramArray); $param .= ' ORDER BY maindate ' . ($sort == 1 ? 'DESC' : 'ASC'); $i = 0; foreach (Sale::model()->findAll($param) as $data) { $retrnData[] = $data; if ($i < (int) $count) { break; } ++$i; } return $retrnData; }
public function actionSavePayment() { if (!Yii::app()->user->checkAccess('payment.index')) { throw new CHttpException(403, 'You are not authorized to perform this action'); } $data = $this->sessionInfo(); if (isset($_POST['SalePayment'])) { $data['model']->attributes = $_POST['SalePayment']; if ($data['model']->validate()) { $paid_amount = $_POST['SalePayment']['payment_amount']; $note = $_POST['SalePayment']['note']; $payments = array($data['currency_code'] => array('currency_code' => $data['currency_code'], 'payment_amount' => $paid_amount)); if ($paid_amount <= $data['balance']) { Sale::model()->payment($data['client_id'], $payments, $data['employee_id'], $note); $data['warning'] = $data['cust_fullname'] . ' Successfully paid '; $this->renderPartial('_payment_success', $data); exit; /* $data['payment_id'] = Salepayment::model()->batchPayment($data['client_id'], $data['employee_id'], $data['account'], $paid_amount, $paid_date, $note); if (substr($data['payment_id'], 0, 2) == '-1') { $data['warning'] = $data['payment_id']; } else { $data = $this->sessionInfo(); $data['warning'] = $data['cust_fullname'] . ' Successfully paid '; $this->renderPartial('_payment_success', $data); //$this->redirect(array('salePayment/successPayment','cust_fullname'=>$data['cust_ful'])); //Yii::app()->paymentCart->clearAll(); exit; } */ } else { $data['model']->addError('payment_amount', Yii::t('app', 'Total amount to paid is only') . ' <strong>' . number_format($data['balance'], Common::getDecimalPlace()) . '</strong>'); } } } //$this->reload($data); if (Yii::app()->request->isAjaxRequest) { Yii::app()->clientScript->scriptMap['*.js'] = false; Yii::app()->clientScript->scriptMap['jquery-ui.css'] = false; Yii::app()->clientScript->scriptMap['box.css'] = false; $this->renderPartial('index', $data, false, true); } else { $this->render('index', $data); } }
protected function findSale($in_sale_id) { if ($in_sale_id) { $model = Sale::model()->findByPk((int) $in_sale_id); } else { $model = new Sale(); } return $model; }
?> <br> <?php echo CHtml::activeFileField($model, 'imagefile', array('style' => 'cursor: pointer;')); ?> </div> </div> <?php echo $form->DatePickerRow($model, 'maindate', array('options' => array('autoclose' => true, 'type' => 'Component', 'format' => 'yyyy-mm-dd'), 'htmlOptions' => array())); ?> <?php echo $form->dropDownListRow($model, 'status', Sale::model()->getStatuslist(), array('class' => 'span5')); ?> <div class="form-actions"> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'htmlOptions' => array('style' => 'margin-right: 20px'), 'label' => $model->isNewRecord ? Yii::t('Bootstrap', 'PHRASE.BUTTON.CREATE') : Yii::t('Bootstrap', 'PHRASE.BUTTON.SAVE'))); ?> <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'link', 'label' => Yii::t('Bootstrap', 'PHRASE.BUTTON.RETURN'), 'url' => $this->listUrl('index'))); ?> </div>
<h1>АКЦИИ</h1> </div> </main> <div class="news-block"> <main role="main" class="all"> <div class="container news-all"> <figure> <?php if (!empty($model->image)) { echo '<img src="/uploads/filestorage/sale/elements/small-' . $model->id . '.' . $model->image . '">'; } ?> </figure> <article> <p><?php echo Sale::model()->getDate($model->maindate); ?> </p> <blockquote> <?php echo $model->name; ?> </blockquote> <?php echo $model->description; ?> </article> </div> </main> </div>
public function actionEditSale($sale_id) { //if(Yii::app()->request->isPostRequest) //{ Yii::app()->clientitemCart->clearAll(); Yii::app()->clientitemCart->copyEntireSale($sale_id); Sale::model()->deleteSale($sale_id); //$this->reload(); $this->redirect('index'); //} }
/** * @param $model - модель SaleGroup * Возращает сформированый дизайн списка групп в соответствии с $model группы */ public function returnDesignGroup($model) { //Серый $template_gray = ' <section class="shadow mg-top-15"> <div class="bg-gray pd-bottom-40 bottom-shadow"> <main class="all" role="main"> <div class="container"> <h1 class="caption-big">%name%</h1> <a href="' . Yii::app()->request->requestUri . '/' . $model->url . '"> <figure class="main-pic" style="cursor: pointer;"> %image% <figcaption> %brieftext% </figcaption> </figure> </a> </div> </main> </div> </section> '; //Белый $template_white = ' <section class="metro pd-top-30 mg-bottom-30"> <main class="all" role="main"> <div class="container"> <h2 class="main-caption">%name%</h2> <a href="' . Yii::app()->request->requestUri . '/' . $model->url . '"> <figure class="main-pic" style="cursor: pointer;"> %image% <figcaption> %brieftext% </figcaption> </figure> </a> </div> </main> </section> '; $return = $template_white; if ($model->param_design == 2) { $return = $template_gray; } $return = str_replace("%name%", $model->name, $return); $return = str_replace("%image%", !empty($model->image) ? '<img src="/uploads/filestorage/sale/rubrics/' . $model->id . '.' . $model->image . '">' : '', $return); $return = str_replace("%brieftext%", $model->brieftext, $return); $return = str_replace("%description%", $model->description, $return); $sale_element = ''; $i = 0; foreach (Sale::model()->findAll('group_id = ' . $model->id . ' AND status!=0 ORDER BY id DESC') as $dataSale) { ++$i; if ($i % 2 != 0) { $sale_element .= '<div class="press-line">'; } $sale_element .= SaleGroup::model()->returnDesignElement($dataSale); if ($i % 2 == 0) { $sale_element .= '</div>'; } } $return = str_replace("%sale_element%", $sale_element, $return); return $return; }