Beispiel #1
0
 /**
  * @Author: ANH DUNG Dec 01, 2014
  * @Todo: handle POST for create tenancy without create transaction
  * @belongto: actionCreateTenancy
  */
 public static function HandlePost($mTransactions)
 {
     if (isset($_POST['ProTransactionsPropertyDetail'])) {
         ProTransactions::HandleSaveAsDraft($mTransactions);
         ProTransactions::GetPostAndValidateTenancy($mTransactions);
         if (!$mTransactions->hasErrors() && !$mTransactions->mPropertyDetail->hasErrors() && !$mTransactions->mTenatDefault->hasErrors() && !$mTransactions->mTenatDefault->hasErrors() && !$mTransactions->mTenant->hasErrors() && !$mTransactions->mPropertyDocument->hasErrors() && !$mTransactions->mBillTo->hasErrors() && !$mTransactions->mVendor->hasErrors() && !$mTransactions->mPurchaser->hasErrors()) {
             ProTransactions::convertToDbDate($mTransactions);
             $prefix_code = "T" . date('Y') . date('m');
             //                if(!isset($_GET['update_transactions'])){
             if (!strlen($mTransactions->transactions_no)) {
                 // Fix Feb 03, 2015 for update tenancy and trans
                 $mTransactions->transactions_no = MyFormat::getNextId('ProTransactions', $prefix_code, 'transactions_no', ProTransactions::LENGTH_TRANS_NO);
             }
             $link = Yii::app()->createAbsoluteUrl('admin/tenancy/view', array('id' => $mTransactions->id));
             $cController = strtolower(Yii::app()->controller->id);
             if ($cController == "transactions") {
                 // Feb 03, 2015 , fix for update transaction
                 $link = Yii::app()->createAbsoluteUrl('admin/transactions/view', array('id' => $mTransactions->id));
             }
             //                $mTransactions->status = STATUS_TENANCY_NEW;
             // Feb 02, 2015 , fix for update transaction
             $cAction = Yii::app()->controller->action->id;
             if ($cAction != 'update') {
                 $mTransactions->status = STATUS_TENANCY_APPROVE;
             }
             // Feb 02, 2015 , fix for update transaction
             $mTransactions->save();
             // save transaction
             // save  mPropertyDetail
             $mTransactions->mPropertyDetail->transactions_id = $mTransactions->id;
             $mTransactions->mPropertyDetail->listing_id = $mTransactions->listing_id;
             $mTransactions->mPropertyDetail->save();
             //save mBillTo
             $mTransactions->mBillTo->transactions_id = $mTransactions->id;
             $mTransactions->mBillTo->client_type_id = $mTransactions->client_type_id;
             $mTransactions->mBillTo->type = ProTransactionsBillTo::TYPE_VENDOR_PURCHASER;
             $mUserBillTo = Users::saveUserExternalCoBroke($mTransactions->mBillTo, ROLE_EXTERNAL_CO_BROKE);
             $mTransactions->mBillTo->user_id = $mUserBillTo->id;
             if ($cAction == 'update' && ProTransactions::IsTenancyTransaction($mTransactions)) {
                 $mTransactions->mBillTo->save();
                 // save mBillTo
             }
             // save tenant
             if ($mTransactions->type == ProTransactions::FOR_RENT) {
                 $mTransactions->mTenatDefault->transactions_id = $mTransactions->id;
                 ProTransactionsVendorPurchaserDetail::saveOneTenant($mTransactions->mTenatDefault, 1);
                 // update new expiration date for tenant to check login
                 ProTransactionsVendorPurchaserDetail::updateExpirationTenant($mTransactions);
             }
             // end save tenant
             //save ProTransactionsPropertyDocument
             ProTransactionsPropertyDocument::saveRecord($mTransactions);
             $mTransactions = ProTransactions::LoadModelRelationByPk($mTransactions->id);
             // Mar 05, 2015 create landlord and send mail to new user if not yet send
             ProTransactions::CreateNewTenantLandlordAndSendMail($mTransactions);
             // Mar 05, 2015  create landlord and send mail to new user if not yet send
             // Feb 02, 2015 , fix for update transaction need for save Comm
             if ($cAction == 'update' && ProTransactions::IsTenancyTransaction($mTransactions)) {
                 // comm here
                 ProTransactionsBillTo::UpdateBillTo($mTransactions);
                 // Jun 16, 2014 đưa bill to lên trên save commission thì mới có đc rExternalCoBrokeCommission
                 // chỗ này find lại model của transaction để lấy hết relation - single query
                 $mTransactions = ProTransactions::LoadModelRelationByPk($mTransactions->id);
                 ProTransactionsSaveCommission::saveOneTransaction($mTransactions);
                 ProTransactionsInvoice::AutoGenInvoice($mTransactions);
             }
             // Feb 02, 2015 , fix for update transaction need for save Comm
             Yii::app()->controller->redirect($link);
             // may be redirect to view
         }
     }
 }
                     $model->property_id = $enquiry;
                     $model->get_update = 1;
                     if ($model->save()) {
                         /*
                          * -----------------
                          * dtoan : send mail
                          * -----------------
                          */
                         SendEmail::sendEmailShortList($model);
                     }
                 }
                 $thankYouEnquiry = Pages::getPageById(PAGE_THANK_ENQUIRY_PROPERTY);
                 Yii::app()->user->setFlash('success', $thankYouEnquiry->content);
                 //                    $this->redirect(Yii::app()->createAbsoluteUrl('site/thankyou'));
                 $this->redirect(Yii::app()->createAbsoluteUrl('page/index', array('slug' => 'thank-you-message-for-sending-global-enquiry')));
             }
         }
         $this->render('normal_user/sendEnquiry', array('model' => $model, 'listing' => $listing));
     } else {
         throw new CHttpException(404, 'Invalid request. Please do not repeat this request again.');
     }
 }
 /**
  * @Author: ANH DUNG Mar 27, 2014
  * @Todo: dùng để tạo mới và update transaction - khá là rối logic - be careful
  * @param: $type: 1: for sale, 2: for rent
  * @param: $listing_id: listing_id
  */
 //    public function actionCreateTransaction($type, $listing_id){
 public function actionCreateTransaction($type)
 {
     /** 1. get thông tin user login
      * 2. createnew tạo mới 1 transaction với status tạm =0, sau đó get thông tin liên quan
      * 3. get thông tin của listing đưa vào model của $mTransactionsPropertyDetail
      * 4. get thông tin của ,1: vendor,2: purchaser, 3: Landlord, 4: Tenant Purchaser’s Details, External Co-broke details
      * 
      */
     MyFormat::validateUserAccess(ROLE_AGENT);
     $this->pageTitle = "Create Transaction - " . Yii::app()->params['title'];
     //        try {
     $mUser = Users::model()->findByPk(Yii::app()->user->id);
     $listing_id = 0;
     if (isset($_GET['listing_id'])) {
         $listing_id = $_GET['listing_id'];
     }
     // Dec 02, 2014
     $add_property = ProTransactions::ADD_EXISTING;
     if (isset($_GET['add_property']) && in_array($_GET['add_property'], ProTransactions::$LIST_ADD_PROPERTY)) {
         $add_property = $_GET['add_property'];
     }
     // Dec 02, 2014
     if (!isset($_GET['id'])) {
         $mTransactions = ProTransactions::CreateNewRecordTransaction($type, $listing_id);
         $this->redirect(array('createTransaction', 'id' => $mTransactions->id, 'type' => $type, 'listing_id' => $listing_id, 'add_property' => $add_property, 'list' => $_GET['list']));
     } else {
         $mTransactions = ProTransactions::getByPk($_GET['id']);
     }
     $this->validateLink($type, $listing_id, $add_property);
     // OPEN IT
     $this->GetSomeInfo($mTransactions, $type, $add_property);
     if (isset($_POST['ProTransactionsPropertyDetail'])) {
         $this->GetPostAndValidate($mTransactions);
         if (!$mTransactions->hasErrors() && !$mTransactions->mPropertyDetail->hasErrors() && !$mTransactions->mBillTo->hasErrors() && !$mTransactions->mTenatDefault->hasErrors() && !$mTransactions->mLandlord->hasErrors() && !$mTransactions->mTenant->hasErrors() && !$mTransactions->mVendor->hasErrors() && !$mTransactions->mPurchaser->hasErrors() && !$mTransactions->mPropertyDocument->hasErrors()) {
             $mTransactions->invoice_bill_to = $mTransactions->mBillTo->bill_to_id;
             ProTransactions::convertToDbDate($mTransactions);
             $prefix_code = date('Y') . date('m');
             if (!isset($_GET['update_transactions'])) {
                 $mTransactions->transactions_no = MyFormat::getNextId('ProTransactions', $prefix_code, 'transactions_no', ProTransactions::LENGTH_TRANS_NO);
             }
             $mTransactions->status = STATUS_ACTIVE;
             $mTransactions->update();
             // update transaction
             // save  mPropertyDetail
             $mTransactions->mPropertyDetail->transactions_id = $mTransactions->id;
             $mTransactions->mPropertyDetail->listing_id = $mTransactions->listing_id;
             $mTransactions->mPropertyDetail->save();
             //save mBillTo
             $mTransactions->mBillTo->transactions_id = $mTransactions->id;
             $mTransactions->mBillTo->client_type_id = $mTransactions->client_type_id;
             $mTransactions->mBillTo->type = ProTransactionsBillTo::TYPE_VENDOR_PURCHASER;
             $mUserBillTo = Users::saveUserExternalCoBroke($mTransactions->mBillTo, ROLE_EXTERNAL_CO_BROKE);
             $mTransactions->mBillTo->user_id = $mUserBillTo->id;
             $mTransactions->mBillTo->save();
             // save mBillTo
             // save tenant
             if ($mTransactions->type == ProTransactions::FOR_RENT) {
                 $mTransactions->mTenatDefault->transactions_id = $mTransactions->id;
                 ProTransactionsVendorPurchaserDetail::saveOneTenant($mTransactions->mTenatDefault, 1);
                 // update new expiration date for tenant to check login
                 ProTransactionsVendorPurchaserDetail::updateExpirationTenant($mTransactions);
             }
             // end save tenant
             //save ProTransactionsPropertyDocument
             /* Closed by HTram, because it were uploaded by ajax at the form