/**
  * Lists all AccessApp models.
  * @return mixed
  */
 public function actionPreviewTpl($contr_id = '1')
 {
     /**
      * @var Pdf $pdf
      * @var Contract $ec
      * @var Group $group
      * @var Organization $provider
      * @var Traveller $assigned
      * @var Other $other
      */
     $this->layout = 'main_outer.php';
     $ec = Contract::findOne($contr_id);
     if (empty($ec)) {
         throw new Exception('合同不存在');
     }
     $version = ContractVersion::findOne($ec->vercode);
     if (empty($version)) {
         throw new Exception('合同版本不存在');
     }
     $travellers = Traveller::find()->andWhere('contr_id=:contr_id', [':contr_id' => $ec->contr_id])->all();
     $provider = Organization::findOne(1);
     $assigned = Traveller::find()->andWhere('contr_id=:contr_id and is_leader=:is_leader', [':contr_id' => $ec->contr_id, ':is_leader' => '1'])->one();
     $group = Group::find()->andWhere('contr_id=:contr_id', [':contr_id' => $ec->contr_id])->one();
     $other = Other::findOne($contr_id);
     $pay = json_decode($other->pay, true);
     $insurance = json_decode($other->insurance, true);
     $groupcorp = json_decode($other->groupcorp, true);
     $otherGroup = json_decode($other->group, true);
     $effect = json_decode($other->effect, true);
     $routes = Routes::find()->andWhere('contr_id=:contr_id and parentid=:parentid', [':contr_id' => $ec->contr_id, ':parentid' => 0])->all();
     //自愿购物活动补充协议
     $shops = ShopAgreement::find()->where("contr_id='{$ec->contr_id}'")->orderBy('index asc')->all();
     //自愿参加另行付费旅游项目补充协议
     $chargeables = Chargeable::find()->where("contr_id='{$ec->contr_id}'")->orderBy('index asc')->all();
     $data = ['contract' => $ec, 'version' => $version, 'provider' => $provider, 'group' => $group, 'assigned' => $assigned, 'travellers' => $travellers, 'routes' => $routes, 'shops' => $shops, 'chargeables' => $chargeables, 'other' => $other, 'pay' => $pay, 'insurance' => $insurance, 'groupcorp' => $groupcorp, 'otherGroup' => $otherGroup, 'effect' => $effect, 'app' => ConfigHelper::getParamsConfigArray('app'), 'company' => ConfigHelper::getParamsConfigArray('company'), 'year' => date('Y'), 'PAGE_BREAK' => PdfHelper::PAGE_BREAK];
     //pdf
     $css = Yii::$app->basePath . "/web/css/ec.css";
     $css = file_get_contents($css);
     $htmlContent = $this->renderPartial('inside.tpl', $data);
     //file_get_contents("D:/template/t2.htm");
     $pdf = Yii::$app->pdf;
     $pdf->cssInline .= $css;
     $pdf->content = $htmlContent;
     $pdf->filename = "电子合同-{$ec->contr_no}.pdf";
     //methods
     $pdf->methods['SetHeader'] = "合同编号<span class=\"color-tno\">{$ec->contr_no}</span>";
     $pdf->methods['SetTitle'] = ConfigHelper::getAppConfig('down');
     $pdf->methods['SetAuthor'] = ConfigHelper::getAppConfig('author');
     $pdf->methods['SetCreator'] = ConfigHelper::getAppConfig('creator');
     $pdf->methods['SetSubject'] = ConfigHelper::getAppConfig('subject');
     //$pdf->output($htmlContent);
     return $pdf->render();
     //return $this->render('inside.tpl',$data);
     //echo $htmlContent;
 }
Ejemplo n.º 2
0
 /**
  * 获取合同团的信息
  * @return \yii\db\ActiveQuery
  */
 public function getGroup()
 {
     return $this->hasOne(Group::className(), ['contr_id' => 'contr_id']);
 }
Ejemplo n.º 3
0
 /**
  * 上传或者提交合同
  * @author lvkui
  * @param $data
  * @param bool $method
  * @throws \Exception
  * @throws \yii\base\Exception
  */
 function sys_submitContract($data, $method = true)
 {
     $tran = null;
     try {
         $tran = Yii::$app->db->beginTransaction();
         if (!isset($data['contract']) || $this->isStrEmpty($data['contract'])) {
             throw new Exception('an empty string is not allowed for $contract');
         }
         $user = AccessTokenService::getCurrentUser();
         //电子合同
         $ec = $data['contract'];
         $model = new Contract();
         $model->vercode = $ec['vercode'];
         $model->type = $ec['type'];
         $model->is_lock = Contract::CONTRACT_NO;
         $model->status = $method ? Contract::CONTRACT_STATUS_COMMITIN : Contract::CONTRACT_STATUS_UNCOMMIT;
         $model->audit_status = $user->org->isaudit ? Contract::CONTRACT_YES : Contract::CONTRACT_NO;
         $model->is_submit = $model->status;
         $model->sub_time = $model->is_submit ? DataHelper::getCurrentTime() : '';
         $model->price = $ec['price'];
         $model->num = $ec['num'];
         $model->transactor = $ec['transactor'];
         $model->oldcontr = $ec['contr_no'];
         $model->save();
         //线路信息
         if (isset($data['group'])) {
             $g = $data['group'];
             $gModel = new Group();
             $gModel->contr_id = $model->contr_id;
             $gModel->teamcode = $g['teamcode'];
             $gModel->linename = $g['linename'];
             $gModel->personLimit = $g['personLimit'];
             $gModel->payGuide = $g['payGuide'];
             $gModel->days = $g['days'];
             $gModel->nights = $g['nights'];
             $gModel->bgndate = $g['bgndate'];
             $gModel->enddate = $g['enddate'];
             $gModel->from = $g['from'];
             $gModel->aim = $g['aim'];
             $gModel->save();
         }
         //游客信息
         if (isset($data['traveller'])) {
             $t = $data['traveller'];
             $tModel = new Traveller();
             $tModel->contr_id = $model->contr_id;
             $tModel->name = $t['name'];
             $tModel->sex = $t['sex'];
             $tModel->birthday = $t['birthday'];
             $tModel->nation = $t['nation'];
             $tModel->folk = $t['folk'];
             $tModel->mobile = $t['mobile'];
             $tModel->idtype = $t['idtype'];
             $tModel->idcode = $t['idcode'];
             $tModel->addr = $t['addr'];
             $tModel->no = $t['no'];
             $tModel->is_leader = $t['is_leader'];
             if ($tModel->is_leader) {
                 $tModel->extra_data = $t['extra_data'];
             }
             $tModel->save();
         }
         //行程信息
         if (isset($data['routes'])) {
             $r = $data['routes'];
             if (!empty($r['journeys'])) {
                 foreach ($r['journeys'] as $k => $j) {
                     $rModel = new Routes();
                     $rModel->contr_id = $model->contr_id;
                     $rModel->parentid = '0';
                     $rModel->title = $j['title'];
                     $rModel->ctype = Routes::ROUTE_TYPE_JOURNEY;
                     $rModel->index = $j['index'];
                     if ($rModel->save()) {
                         $parentid = $rModel->id;
                         if (!empty($j['citys'])) {
                             foreach ($j['citys'] as $i => $c) {
                                 $cModel = new Routes();
                                 $cModel->contr_id = $model->contr_id;
                                 $cModel->parentid = $parentid;
                                 $cModel->title = $c['title'];
                                 $cModel->ctype = Routes::ROUTE_TYPE_CITY;
                                 $cModel->transit = $c['transit'];
                                 $cModel->index = $c['index'];
                                 $cModel->from = $c['from'];
                                 $cModel->aim_city = $c['aim_city'];
                                 $cModel->aim_country = $c['aim_country'];
                                 $cModel->sign = DataHelper::getSign($c['content']);
                                 $text = Text::findOne($cModel->sign);
                                 if (empty($text)) {
                                     $text->sign = $cModel->sign;
                                     $text->content = $c['content'];
                                     $text->save();
                                 }
                                 //$cModel->extra_data=$c['extra_data'];
                                 $cModel->save();
                             }
                         }
                     }
                 }
             }
         }
         //购物协议
         if (isset($data['shops'])) {
             foreach ($data['shops'] as $shop) {
                 $sModel = new ShopAgreement();
                 $sModel->contr_id = $model->contr_id;
                 $sModel->name = $shop['name'];
                 $sModel->addr = $shop['addr'];
                 $sModel->time = $shop['time'];
                 $sModel->goods = $shop['goods'];
                 $sModel->duration = $shop['duration'];
                 $sModel->memo = $shop['memo'];
                 $sModel->agree = $shop['agree'];
                 $sModel->index = $shop['index'];
                 $sModel->save();
             }
         }
         //自费协议
         if (isset($data['chargeables'])) {
             foreach ($data['chargeables'] as $charge) {
                 $chModel = new Chargeable();
                 $chModel->contr_id = $model->contr_id;
                 $chModel->name = $charge['name'];
                 $chModel->addr = $charge['addr'];
                 $chModel->time = $charge['time'];
                 $chModel->price = $charge['price'];
                 $chModel->duration = $charge['duration'];
                 $chModel->memo = $charge['memo'];
                 $chModel->agree = $charge['agree'];
                 $chModel->index = $charge['index'];
                 $chModel->save();
             }
         }
         //合同其它信息
         if (isset($data['other'])) {
             $other = $data['other'];
             $oModel = new Other();
             $oModel->contr_id = $model->contr_id;
             $oModel->groupcorp = $other['groupcorp'];
             $oModel->pay = $other['pay'];
             $oModel->insurance = $other['insurance'];
             $oModel->group = $other['group'];
             if (!empty($other['goldenweek'])) {
                 $oModel->goldenweek = $other['goldenweek'];
             }
             if (!empty($other['controversy'])) {
                 $oModel->controversy = $other['controversy'];
             }
             $oModel->other = $other['other'];
             $oModel->effect = $other['effect'];
             $oModel->save();
         }
         $tran->commit();
     } catch (Exception $e) {
         $tran->rollBack();
         throw $e;
     }
 }