Exemplo n.º 1
0
 /**
  * Finds the Invoice model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Invoice the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Invoice::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findApplyingByUser($user['userId']);
     if ($invoice) {
         return false;
     }
     $invoice = new Invoice();
     $user = Yii::$app->session->get('user');
     $invoice->userId = $user['userId'];
     $invoice->money = $this->money;
     $invoice->address = $user['address'];
     $invoice->createDate = DateFunctions::getCurrentDate();
     $invoice->state = Invoice::STATE_ING;
     $invoice->address = $this->address;
     if (!$invoice->save()) {
         throw new Exception("Invoice save error");
     }
     return true;
 }
Exemplo n.º 3
0
 public function record()
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findApplyingByUser($user['userId']);
     if ($invoice) {
         CommonFunctions::createAlertMessage("发票申请失败,您已经有正在申请中的发票了,一次只能申请一张", "error");
         return false;
     } else {
         $invoice = new Invoice();
         $invoice->userId = $user['userId'];
         $invoice->address = $this->address;
         $invoice->money = $this->money;
         $invoice->description = $this->description;
         $invoice->createDate = DateFunctions::getCurrentDate();
         $invoice->state = Invoice::STATE_ING;
         if (!$invoice->save()) {
             throw new Exception("Apply Invoice save error");
         }
         return true;
     }
 }
Exemplo n.º 4
0
 public function updateInvoice($state)
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findOne($this->invoiceId);
     /** @var $invoice \common\models\Invoice */
     $invoice->state = $state;
     $invoice->replyContent = $this->replyContent;
     $invoice->replyDate = DateFunctions::getCurrentDate();
     $invoice->replyUserId = $user['userId'];
     if (!$invoice->save()) {
         throw new Exception("invoice update error");
     }
 }
Exemplo n.º 5
0
 public function addInvoice()
 {
     if ($this->validate()) {
         $invoice = new Invoice();
         $invoice->invoice_no = $this->invoice_no;
         $invoice->due_date = $this->due_date;
         $invoice->bank_name = $this->bank_name;
         $invoice->account_no = $this->account_no;
         $invoice->customer = $this->customer;
         $invoice->address = $this->address;
         $invoice->telephone = $this->telephone;
         $invoice->fax = $this->fax;
         $invoice->pic = $this->pic;
         $invoice->mobile = $this->mobile;
         if ($invoice->save()) {
             $entpinvoice = new EntpInvoice();
             $entpinvoice->entrepreneur_user_id = Yii::$app->user->id;
             $entpinvoice->link('invoice', $invoice);
         }
         return $invoice;
     }
     return null;
 }
Exemplo n.º 6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Invoice::find()->with('registration')->andWhere(['deleted' => [0, 5]]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'registration_id' => $this->registration_id, 'order_number' => $this->order_number, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'deleted' => $this->deleted]);
     $query->andFilterWhere(['like', 'pay_number', $this->pay_number])->andFilterWhere(['like', 'invoice', $this->invoice])->andFilterWhere(['like', 'currency', $this->currency])->andFilterWhere(['like', 'payment_type', $this->payment_type])->andFilterWhere(['like', 'financial_institution', $this->financial_institution])->andFilterWhere(['like', 'ref_number', $this->ref_number])->andFilterWhere(['like', 'contract_number', $this->contract_number]);
     return $dataProvider;
 }
Exemplo n.º 7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Invoice::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'due_date' => $this->due_date, 'account_no' => $this->account_no, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'invoice_no', $this->invoice_no])->andFilterWhere(['like', 'bank_name', $this->bank_name])->andFilterWhere(['like', 'customer', $this->customer])->andFilterWhere(['like', 'address', $this->address])->andFilterWhere(['like', 'telephone', $this->telephone])->andFilterWhere(['like', 'fax', $this->fax])->andFilterWhere(['like', 'pic', $this->pic])->andFilterWhere(['like', 'mobile', $this->mobile]);
     return $dataProvider;
 }
Exemplo n.º 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Invoice::find()->andWhere(['not', ['status_id' => Invoice::STATUS_CURRENT]])->with('location.client');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     $dataProvider->sort->attributes['location_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC, Location::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC, Location::tableName() . '.name' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere([Invoice::tableName() . '.location_id' => $this->location_id, Invoice::tableName() . '.status_id' => $this->status_id]);
     $query->andFilterWhere(['like', Invoice::tableName() . '.id', (int) $this->id]);
     return $dataProvider;
 }
Exemplo n.º 9
0
 /** 发票申请 */
 public function actionInvoiceApply()
 {
     $applyInvoiceForm = new ApplyInvoiceForm();
     CommonFunctions::createAlertMessage("为了更好的为您提供服务,请认真填写相关信息!<br>\n        说明:申请金额至少50元起,不得大于可申请金额,且发票将采用到付方式快递给您。", "info");
     if ($applyInvoiceForm->load(Yii::$app->request->post()) && $applyInvoiceForm->validate()) {
         if ($applyInvoiceForm->record()) {
             CommonFunctions::createAlertMessage("您的申请已经记录,请耐心等待管理员审核和配送", "success");
         }
     }
     $user = Yii::$app->session->get('user');
     $query = Invoice::find()->where(['userId' => $user['userId']])->orderBy(['createDate' => SORT_DESC]);
     $pagination = new Pagination(['defaultPageSize' => 20, 'totalCount' => $query->count()]);
     $invoices = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('invoice-apply', ['applyInvoiceForm' => $applyInvoiceForm, 'invoices' => $invoices, 'pages' => $pagination]);
 }
Exemplo n.º 10
0
 public function beforeAction($action)
 {
     //$css_file_id='';
     $test = 11;
     $ref = Yii::$app->request->get('ref', '');
     $id = Yii::$app->request->get('id', '');
     $user_id = 0;
     if (!\Yii::$app->user->isGuest) {
         $user_id = \Yii::$app->user->identity->getId();
     }
     if (!empty($ref)) {
         $user_id = AlphaId::id($ref, true);
     }
     $user_setting = UserSetting::findByUserId($user_id);
     if ($user_setting) {
         $this->getView()->params['css_file_id'] = $user_setting->css_file_id;
         $this->getView()->params['logo_url'] = $user_setting->logo_url;
         $this->getView()->params['ref_user_id'] = $user_id;
         $this->getView()->params['id'] = $id;
         $this->getView()->params['ref'] = $ref;
     } else {
         $this->getView()->params['css_file_id'] = '';
         $this->getView()->params['logo_url'] = '';
     }
     if ($user_id != 0) {
         $cartForm = new CartForm();
         $rows = $cartForm->getUserCart($user_id, true);
         $this->getView()->params['cart_count'] = count($rows);
         $invoicies = Invoice::find()->where(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW])->all();
         $invoice = Invoice::findOne(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW]);
         $invoice_id = 0;
         if ($invoice) {
             $invoice_id = $invoice->id;
         }
         $this->getView()->params['invoice_count'] = count($invoicies);
         $this->getView()->params['invoice_id'] = $invoice_id;
         if (!Yii::$app->user->isGuest && Yii::$app->user && Yii::$app->user->identity) {
             $this->getView()->params['demo'] = Yii::$app->user->identity->role == User::ROLE_DEMO ? true : false;
         }
     } else {
         $this->getView()->params['demo'] = 0;
     }
     return parent::beforeAction($action);
 }
 /** 发票查询 */
 public function actionSearch()
 {
     $user = Yii::$app->session->get('user');
     $request = Yii::$app->request;
     $session = Yii::$app->session;
     $query = $session->getFlash('query');
     if ($request->isPost) {
         $type = $request->post('type');
         $content = $request->post('content');
     } else {
         $type = $request->get('type');
         $content = trim($request->get('content'));
     }
     if ($type || !$query) {
         switch ($type) {
             case 'orderNumber':
                 $query = Invoice::find()->where(['userId' => $user['userId']])->andWhere(['like', 'orderNumber', $content]);
                 break;
             case 'state':
                 $query = Invoice::find()->where(['userId' => $user['userId'], 'state' => $content]);
                 break;
             case 'money-more':
                 $query = Invoice::find()->where(['userId' => $user['userId']])->andWhere(['>=', 'money', $content]);
                 break;
             case 'money-equal':
                 $query = Invoice::find()->where(['userId' => $user['userId']])->andWhere(['==', 'money', $content]);
                 break;
             case 'money-less':
                 $query = Invoice::find()->where(['userId' => $user['userId']])->andWhere(['<=', 'money', $content]);
                 break;
             default:
                 $query = Invoice::find()->where(['like', $type, $content]);
                 break;
         }
     }
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $models = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['createDate' => SORT_DESC])->all();
     return $this->render('index', ['models' => $models, 'pages' => $pagination]);
 }
Exemplo n.º 12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Location::find()->joinWith('client')->andWhere([Client::tableName() . '.active' => true]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => ['defaultOrder' => ['client_id' => SORT_ASC, 'name' => SORT_ASC]]]);
     $dataProvider->sort->attributes['client_id'] = ['asc' => [Client::tableName() . '.name' => SORT_ASC], 'desc' => [Client::tableName() . '.name' => SORT_DESC]];
     if (Yii::$app->user->can('Accounting')) {
         $query->joinWith('lastInvoice');
         $dataProvider->sort->attributes['lastInvoiceStatus'] = ['asc' => [Invoice::tableName() . '.status_id' => SORT_ASC], 'desc' => [Invoice::tableName() . '.status_id' => SORT_DESC]];
     }
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere([self::tableName() . '.client_id' => $this->client_id, self::tableName() . '.proactive' => $this->proactive, self::tableName() . '.active' => $this->active]);
     if (Yii::$app->user->can('Accounting')) {
         $query->andFilterWhere([Invoice::tableName() . '.status_id' => $this->lastInvoiceStatus]);
     }
     $query->andFilterWhere(['or', ['like', self::tableName() . '.name', $this->name], ['like', Client::tableName() . '.name', $this->name]])->andFilterWhere(['like', 'phone', $this->phone]);
     return $dataProvider;
 }
Exemplo n.º 13
0
 public function save()
 {
     $invoice = Invoice::findOne(['id' => $this->id]);
     if (empty($invoice)) {
         $invoice = new Invoice();
         $invoice->user_id = $this->user_id;
         $invoice->status = $this->status;
         $invoice->data = json_encode($this->data);
         $invoice->payment_type = $this->payment_type;
         $invoice->currency = $this->currency;
         $invoice->total = $this->total;
         $invoice->delivery_address = $this->delivery_address;
         Yii::getLogger()->log('save:', YII_DEBUG);
         if ($invoice->save()) {
             $this->id = $invoice->id;
             return $invoice;
         } else {
             Yii::getLogger()->log('save error', YII_DEBUG);
         }
     } else {
         $invoice->user_id = $this->user_id;
         $invoice->status = $this->status;
         $invoice->data = json_encode($this->data);
         $invoice->payment_type = $this->payment_type;
         $invoice->currency = $this->currency;
         $invoice->total = $this->total;
         $invoice->delivery_address = $this->delivery_address;
         Yii::getLogger()->log('update:', YII_DEBUG);
         if ($invoice->update()) {
             return $invoice;
         } else {
             Yii::getLogger()->log('update error:' . print_r($invoice, true), YII_DEBUG);
         }
     }
     return null;
 }
Exemplo n.º 14
0
 /**
  * @return InvoiceQuery
  */
 public function getInvoice()
 {
     return $this->hasOne(Invoice::className(), ['id' => 'invoice_id'])->via('schedule')->inverseOf('travels');
 }
Exemplo n.º 15
0
 public function actionCreateCreditNote($code, $targetBlank = false)
 {
     /**
      * @var $model Registration
      * @var $invoice Invoice
      */
     $model = $this->findModelByCode($code);
     if ($model->status === $model::STATUS_CONFIRM) {
         $invoice = Invoice::getByRegistrationId($model->id);
         $pdfHelper = new PdfHelper();
         $invoice->newAmount = Yii::$app->request->post('Invoice')['newAmount'];
         $invoice->subject = Yii::$app->request->post('Invoice')['subject'];
         $invoice->finalText = Yii::$app->request->post('Invoice')['finalText'];
         $content = $this->renderPartial('credit_note_pdf', ['model' => $model, 'invoice' => $invoice]);
         if ($targetBlank) {
             $pdfHelper->renderPDF($content, $model, $invoice);
         } else {
             $pdfHelper->generatePDF($content, $model, $invoice);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getInvoice()
 {
     return $this->hasOne(Invoice::className(), ['id' => 'invoice_id']);
 }
Exemplo n.º 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getInvoices()
 {
     return $this->hasMany(Invoice::className(), ['id' => 'invoice_id'])->viaTable('{{%entp_invoice}}', ['entrepreneur_user_id' => 'user_id']);
 }
Exemplo n.º 18
0
 /**
  * @return InvoiceQuery
  */
 public function getInvoices()
 {
     return $this->hasMany(Invoice::className(), ['location_id' => 'id'])->inverseOf('location');
 }
Exemplo n.º 19
0
 /**
  * 获取用户剩余的可以申请发票的钱
  * @param $userId
  * @return mixed
  */
 public static function findRemainMoneyByUser($userId)
 {
     $consume = Invoice::findTotalInvoice($userId);
     $income = Money::findTotalPay($userId);
     return $income - $consume;
 }
Exemplo n.º 20
0
 /**
  * @return $this
  */
 public function current()
 {
     $this->joinWith('invoice')->andWhere([Invoice::tableName() . '.status_id' => Invoice::STATUS_CURRENT]);
     return $this;
 }
Exemplo n.º 21
0
                    <input type="text" name="content" class="form-control" placeholder="请输入查找内容">
                    <button type="submit" class="btn  btn-small btn btn-primary">查找</button>
                </div>
                <?php 
echo Html::endForm();
?>
            </div>
        </div>
        <table class="table table-bordered table-striped margin-bottom-20">
            <tr>
                <td><strong>总计申请开票金额:</strong><?php 
echo Invoice::findTotalApplyMoney();
?>
(元)</td>
                <td><strong>总计已开票金额:</strong><?php 
echo Invoice::findTotalAgreeMoney();
?>
(元)</td>
            </tr>
        </table>
        <table class="table table-hover table-bordered text-align-center">
            <thead class="bordered-blue">
            <tr> <th class="text-align-center">序号</th>
                <th class="text-align-center">用户号</th>
                <th class="text-align-center">用户名称</th>
                <th class="text-align-center">申请开票金额</th>
                <th class="text-align-center">申请开票时间</th>
                <th class="text-align-center">状态</th>
                <th class="text-align-center">详细地址</th>
                <th class="text-align-center">经手人</th>
                <th class="text-align-center">回复日期</th>
Exemplo n.º 22
0
 /**
  * @return InvoiceQuery
  */
 public function getInvoice()
 {
     return $this->hasOne(Invoice::className(), ['id' => 'invoice_id'])->inverseOf('tickets');
 }
Exemplo n.º 23
0
                        <option value="money-equal">开票金额等于</option>
                        <option value="money-less">开票金额小于</option>
                        <option value="orderNumber">快递单号</option>
                    </select>
                    <input type="text" name="content" class="form-control" placeholder="请输入查找内容">
                    <button type="submit" class="btn  btn-small btn btn-primary">查找</button>
                </div>
                <?php 
echo Html::endForm();
?>
            </div>
        </div>
        <table class="table table-bordered table-striped margin-bottom-20">
            <tr>
                <td><strong>总计已完成申请开票金额:</strong><?php 
echo Invoice::findTotalInvoice($user['userId']);
?>
(元)</td>
            </tr>
        </table>
        <table class="table table-hover table-bordered text-align-center">
            <thead class="bordered-blue">
            <tr> <th class="text-align-center">序号</th>
                <th class="text-align-center">用户号</th>
                <th class="text-align-center">用户名称</th>
                <th class="text-align-center">申请开票金额</th>
                <th class="text-align-center">申请开票时间</th>
                <th class="text-align-center">状态</th>
                <th class="text-align-center">详细地址</th>
                <th class="text-align-center">管理员回复内容</th>
                <th class="text-align-center">快递单号</th>
Exemplo n.º 24
0
 /**
  * Finds the Invoice model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @param boolean $excludeCurrent  Whether to return a 404 error if the found Invoice is the placeholder for current tickets for that location. Defaults to true.
  * @return Invoice the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id, $excludeCurrent = true)
 {
     /** @var $model Invoice */
     if (($model = Invoice::findOne($id)) !== null && !($excludeCurrent && $model->status_id == $model::STATUS_CURRENT)) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 25
0
 /** 发票查询 */
 public function actionSearch()
 {
     $request = Yii::$app->request;
     $session = Yii::$app->session;
     $query = $session->getFlash('query');
     if ($request->isPost) {
         $type = $request->post('type');
         $content = $request->post('content');
     } else {
         $type = $request->get('type');
         $content = trim($request->get('content'));
     }
     if ($type || !$query) {
         switch ($type) {
             case 'nickname':
                 $table_a = Invoice::tableName();
                 $table_b = Users::tableName();
                 $query = Invoice::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(['like', "{$table_b}.nickname", $content]);
                 break;
             case 'money-more':
                 $query = Invoice::find()->Where(['>=', 'money', $content]);
                 break;
             case 'money-equal':
                 $query = Invoice::find()->where(['==', 'money', $content]);
                 break;
             case 'money-less':
                 $query = Invoice::find()->Where(['<=', 'money', $content]);
                 break;
             case 'role':
                 $role = '';
                 if ($content == 'a' || $content == 'A' || $content == 'A级') {
                     $role = Users::ROLE_A;
                 } elseif (strstr('金牌伙伴', $content)) {
                     $role = Users::ROLE_AA;
                 } elseif (strstr('钻石伙伴', $content)) {
                     $role = Users::ROLE_AAA;
                 } elseif ($content == '管理员') {
                     $role = Users::ROLE_ADMIN;
                 }
                 $table_a = Invoice::tableName();
                 $table_b = Users::tableName();
                 $query = Invoice::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(["{$table_b}.role" => $role]);
                 break;
             default:
                 $query = Invoice::find()->where(['like', $type, $content]);
                 break;
         }
     }
     $view = $session->getFlash('view');
     if (!$view) {
         //非下一页
         $view = $request->get('view');
         //取哪个页面的搜索
         if (!$view) {
             //不存在即为index的搜索
             $view = 'index';
         }
     }
     if ($view == 'apply') {
         //发票申请的搜索
         $query->andWhere(['state' => Invoice::STATE_ING]);
     } elseif ($view == 'opener') {
         //发票开具的搜索
         $query->andWhere(['state' => Invoice::STATE_PASS]);
     }
     $session->setFlash('view', $view);
     $session->setFlash('query', $query);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $models = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['createDate' => SORT_DESC])->all();
     return $this->render($view, ['models' => $models, 'pages' => $pagination]);
 }
Exemplo n.º 26
0
 public static function changeState($invoiceId, $state, $replyContent)
 {
     $user = Yii::$app->session->get('user');
     $invoice = Invoice::findOne($invoiceId);
     $invoice->state = $state;
     $invoice->replyContent = $replyContent;
     $invoice->replyDate = DateFunctions::getCurrentDate();
     $invoice->replyUserId = $user['userId'];
     if (!$invoice->update()) {
         throw new Exception("Invoice update error");
     }
 }
Exemplo n.º 27
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getInvoices()
 {
     return $this->hasMany(Invoice::className(), ['id' => 'invoice_id'])->viaTable('{{%entp_invoiceitem}}', ['invoice_item_id' => 'id']);
 }