public function actionSalesReport()
 {
     $str = Yii::app()->request->getParam('str');
     $text = Yii::app()->request->getParam('text');
     $begin_time = Yii::app()->request->getParam('begin_time', date('Y-m-d', time()));
     $end_time = Yii::app()->request->getParam('end_time', date('Y-m-d', time()));
     $criteria = new CDbCriteria();
     //		$criteria->select = 'year(t.update_at) as y_all,month(t.update_at) as m_all,day(t.update_at) as d_all,t.dpid,t.update_at,sum(t.reality_total) as all_reality,t.paytype,t.payment_method_id,t.order_status';
     //		$criteria->with = array('company','paymentMethod');
     //		$criteria->condition = 't.order_status in(3,4,8) and t.dpid='.$this->companyId ;
     //		if($str){
     //			$criteria->condition = ' t.order_status in(3,4,8) and t.dpid in('.$str.')';
     //		}
     //		$criteria->addCondition("t.update_at >='$begin_time 00:00:00'");
     //		$criteria->addCondition("t.update_at <='$end_time 23:59:59'");
     //		if($text==1){
     //			$criteria->group ='t.paytype,t.dpid,t.payment_method_id,year(t.update_at)';
     //			$criteria->order = 'year(t.update_at) asc,t.dpid asc';
     //		}elseif($text==2){
     //			$criteria->group ='t.paytype,t.dpid,t.payment_method_id,month(t.update_at)';
     //			$criteria->order = 'year(t.update_at) asc,month(t.update_at) asc,t.dpid asc';
     //		}else{
     //			$criteria->group ='t.paytype,t.dpid,t.payment_method_id,day(t.update_at)';
     //			$criteria->order = 'year(t.update_at) asc,month(t.update_at) asc,day(t.update_at) asc,t.dpid asc';
     //		}
     $criteria->select = 'year(t.update_at) as y_all,month(t.update_at) as m_all,day(t.update_at) as d_all,t.dpid,t.update_at,sum(t.pay_amount) as all_reality,t.paytype,t.payment_method_id';
     $criteria->with = array('company', 'order8');
     $criteria->condition = ' t.dpid=' . $this->companyId;
     if ($str) {
         $criteria->condition = ' t.dpid in(' . $str . ')';
     }
     $criteria->addCondition("order8.update_at >='{$begin_time} 00:00:00'");
     $criteria->addCondition("order8.update_at <='{$end_time} 23:59:59'");
     if ($text == 1) {
         $criteria->group = 't.paytype,t.dpid,year(t.update_at)';
         $criteria->order = 'year(t.update_at) asc,t.dpid asc';
     } elseif ($text == 2) {
         $criteria->group = 't.paytype,t.dpid,month(t.update_at)';
         $criteria->order = 'year(t.update_at) asc,month(t.update_at) asc,t.dpid asc';
     } else {
         $criteria->group = 't.paytype,t.dpid,day(t.update_at)';
         $criteria->order = 'year(t.update_at) asc,month(t.update_at) asc,day(t.update_at) asc,t.dpid asc';
     }
     //$criteria->order = 't.update_at asc,t.dpid asc';
     //$criteria->group = 't.paytype,t.payment_method_id';
     $pages = new CPagination(OrderPay::model()->count($criteria));
     //	    $pages->setPageSize(1);
     $pages->applyLimit($criteria);
     //var_dump($criteria);exit;
     $model = OrderPay::model()->findAll($criteria);
     $comName = $this->getComName();
     $this->render('salesReport', array('models' => $model, 'pages' => $pages, 'begin_time' => $begin_time, 'end_time' => $end_time, 'text' => $text, 'str' => $str, 'comName' => $comName));
 }
 public function actionAccountManul()
 {
     $orderId = Yii::app()->request->getParam('orderId', '0');
     $companyId = Yii::app()->request->getParam('companyId', '0');
     $typeId = Yii::app()->request->getParam('typeId', '0');
     $callId = Yii::app()->request->getParam('callId', '0');
     $padId = Yii::app()->request->getParam('padId', '0000000000');
     $totaldata = Yii::app()->request->getParam('total', '0');
     ///*************print
     $criteria = new CDbCriteria();
     $criteria->condition = 't.dpid=' . $companyId . ' and t.lid=' . $orderId;
     $criteria->order = ' t.lid desc ';
     $order = Order::model()->find($criteria);
     $order->should_total = $totaldata;
     $orderpay = new OrderPay();
     $orderpay->dpid = $order->dpid;
     $orderpay->order_id = $order->lid;
     $orderpay->paytype = "0";
     $orderpay->remark = "现金支付";
     $orderpay->create_at = date('Y-m-d H:i:s', time());
     $paymentMethods = PaymentClass::getPaymentMethodList($companyId);
     //var_dump($paymentMethods);exit;
     if (Yii::app()->request->isPostRequest) {
         Until::validOperate($companyId, $this);
         //var_dump(Yii::app()->request->getPost('Order'));exit;
         $order->attributes = Yii::app()->request->getPost('Order');
         $order->pay_time = date('Y-m-d H:i:s', time());
         $orderpay->attributes = Yii::app()->request->getPost('OrderPay');
         $order->paytype = $orderpay->paytype;
         //$order->payment_method_id=$orderpay->payment_method_id;
         $order->reality_total += $orderpay->pay_amount;
         $order->remark .= $orderpay->remark;
         $se = new Sequence("order_pay");
         $orderpay->lid = $se->nextval();
         //var_dump($order);exit;
         $memo = "";
         if ($order->order_status == "3") {
             $memo = yii::t('app', '收款') . ":" . $orderpay->pay_amount;
         } else {
             if ($order->order_status == "4") {
                 $memo = yii::t('app', '结单') . ":" . $orderpay->pay_amount;
             }
         }
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $criteria2 = new CDbCriteria();
             $criteria2->condition = 't.status in ("1","2","3") and t.dpid=' . $order->dpid . ' and t.site_id=' . $order->site_id . ' and t.is_temp=' . $order->is_temp;
             $criteria2->order = ' t.lid desc ';
             $siteNo = SiteNo::model()->find($criteria2);
             if ($siteNo->is_temp == '0') {
                 $site = Site::model()->with('siteType')->find('t.lid=:lid and t.dpid=:dpid', array(':lid' => $order->site_id, ':dpid' => $order->dpid));
                 $site->status = $order->order_status;
                 $site->save();
             } else {
                 $site = array();
             }
             //$order->order_status=$tempstatus;
             $order->save();
             $orderpay->save();
             $siteNo->status = $order->order_status;
             $siteNo->save();
             if ($order->order_status == '4') {
                 SiteClass::deleteCode($this->companyId, $siteNo->code);
                 //FeedBackClass::cancelAllOrderMsg("0000000000","0",$order->lid,$companyId);
                 $sqlfeedback = "update nb_order_feedback set is_deal='1' where dpid=:companyId and site_id=:siteId and is_temp=:istemp";
                 $commandfeedback = Yii::app()->db->createCommand($sqlfeedback);
                 $commandfeedback->bindValue(":companyId", $companyId);
                 $commandfeedback->bindValue(":siteId", $order->site_id);
                 $commandfeedback->bindValue(":istemp", $order->is_temp);
                 //var_dump($sqlsite);exit;
                 $commandfeedback->execute();
                 $sqlall = "update nb_order_feedback set is_deal='1'where dpid=:dpid and order_id=:orderId and is_order='1'";
                 $connorder = Yii::app()->db->createCommand($sqlall);
                 $connorder->bindValue(':dpid', $companyId);
                 $connorder->bindValue(':orderId', $orderId);
                 $connorder->execute();
                 $sql = 'update nb_order_feedback set is_deal=1 where dpid=:dpid and order_id in (select lid from nb_order_product where dpid=:sdpid and order_id=:sorderId) and is_order=0';
                 $connorderproduct = Yii::app()->db->createCommand($sql);
                 $connorderproduct->bindValue(':dpid', $companyId);
                 $connorderproduct->bindValue(':sdpid', $companyId);
                 $connorderproduct->bindValue(':sorderId', $orderId);
                 $connorderproduct->execute();
             }
             $transaction->commit();
             $pad = Pad::model()->find(' dpid=:dpid and lid=:lid', array(':dpid' => $order->dpid, 'lid' => $padId));
             if (!empty($pad)) {
                 $precode = "1B70001EFF00";
                 //开钱箱
                 $printserver = "1";
                 //$orderProducts= //传递要打印的菜品,这里是已经下单的
                 $orderProducts = OrderProduct::getHasOrderProducts($order->lid, $order->dpid);
                 $ret = Helper::printList($order, $orderProducts, $pad, $precode, $printserver, $memo);
             }
             //$ret=array('status'=>false,'dpid'=>"0000000011",'jobid'=>"0",'type'=>'none','msg'=>yii::t('app','没有要打印的菜品!'));
             $this->redirect(array('default/index', 'companyId' => $this->companyId, 'typeId' => $typeId));
         } catch (Exception $e) {
             $transaction->rollback();
         }
         //                        $this->renderPartial('printlist' , array(
         //                                'orderId'=>$orderId,
         //                                //'companyId'=>$companyId,
         //                                'ret'=>$ret,
         //
         //                                'typeId'=>$typeId
         //                        ));
         //                        exit;
     }
     //var_dump($order);exit;
     $this->renderPartial('accountmanul', array('order' => $order, 'orderpay' => $orderpay, 'typeId' => $typeId, 'callid' => $callId, 'padId' => $padId, 'paymentMethods' => $paymentMethods));
 }
 public function actionPaymentRecord()
 {
     $criteria = new CDbCriteria();
     $begin_time = Yii::app()->request->getParam('begin_time', date('Y-m-d', time()));
     $end_time = Yii::app()->request->getParam('end_time', date('Y-m-d', time()));
     $Did = Yii::app()->request->getParam('Did', 0);
     //var_dump($begin_time);exit;
     $orderID = Yii::app()->request->getParam('orderID');
     //var_dump($orderID);exit;
     $criteria->select = 't.*';
     //代表了要查询的字段,默认select='*';
     $criteria->addCondition("t.dpid= " . $this->companyId);
     // if ($Did > 0){
     // $criteria->addCondition("t.order_id = '$Did'");}
     $criteria->addCondition("t.update_at >='{$begin_time} 00:00:00'");
     $criteria->addCondition("t.update_at <='{$end_time} 23:59:59'");
     if ($orderID) {
         $criteria->addCondition("t.order_id= " . $orderID);
     }
     //$criteria->select = 't1.should_total';
     //var_dump($begin_time);exit;
     $criteria->with = array("company", "order");
     //连接表
     //$criteria->join = 'left join nb_order t1 on (t.dpid = t1.dpid and t.order_id = t1.lid )'; //连接表
     //var_dump();exit;
     // $criteria->join = 'left join nb_company on t.dpid = nb_company.dpid '; //连接表
     $criteria->order = 't.order_id ASC';
     //排序条件
     // var_dump($begin_time);exit;
     //$criteria->group = 'group 条件';
     //$criteria->having = 'having 条件 ';
     $criteria->distinct = TRUE;
     //是否唯一查询
     //$criteria = new CDbCriteria;
     //$sql = "select t1.company_name, t2.name, t.* from nb_order t left join  nb_payment_method t2 on( t.payment_method_id = t2.lid and t.dpid = t2.dpid )  left join  nb_company t1 on t.dpid = t1.dpid where t.order_status in(3,4,8) and  t.update_at >= '$begin_time 00:00:00' and t.update_at <= '$end_time 23:59:59' and t.dpid= ".$this->companyId;
     //var_dump($sql);exit;
     //$connect = Yii::app()->db->createCommand($sql);
     //$model = $connect->queryAll();
     $pages = new CPagination(OrderPay::model()->count($criteria));
     //$pages->PageSize = 10;
     $pages->applyLimit($criteria);
     // 注意事项:pages语句 必须放在  model 语句前面才能有效的执行。。。
     $model = OrderPay::model()->findAll($criteria);
     //var_dump($model);exit;
     //$categoryId = Yii::app()->request->getParam('cid',0);
     //exit;
     $this->render('paymentRecord', array('models' => $model, 'pages' => $pages, 'begin_time' => $begin_time, 'end_time' => $end_time, 'Did' => $Did, 'orderID' => $orderID));
 }