Exemple #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
         }
     }
 }
 /**
  * @Author: ANH DUNG Jul 09, 2014
  * @Todo: view invoice for transaction
  * @Param: $id
  */
 public function actionViewInvoice($id)
 {
     $model = MyFormat::loadModelByClass($id, 'ProTransactionsInvoice');
     $mTransactions = ProTransactions::LoadModelRelationByPk($model->transactions_id);
     $this->render('ViewInvoice/print_invoice', array('model' => $model, 'mTransactions' => $mTransactions, 'actions' => $this->listActionsCanAccess));
 }
             $this->redirect(array('record_existing_tenancy', 'id' => $mTransactions->id, 'type' => $type, 'listing_id' => $listing_id, 'add_property' => $add_property));
         } else {
             $mTransactions = ProTransactions::getByPk($_GET['id']);
         }
         $this->ValidateLinkRecord($add_property, $listing_id);
         // OPEN IT
         $this->GetSomeInfoRecord($mTransactions, $add_property);
         $this->HandlePost($mTransactions);
         $this->render('record/record_existing_tenancy', array('mUser' => $mUser, 'mTransactions' => $mTransactions));
     } catch (Exception $exc) {
         //            echo $exc->getMessage();
         throw new CHttpException(404, 'Invalid Request');
     }
 }
 /**
  * @Author: ANH DUNG Apr 01, 2014
  * @Todo: validate link user type for create new record_existing_tenancy
  */
 public function ValidateLinkRecord($add_property, $listing_id)
 {
     $valid = true;
     if (!in_array($add_property, ProTransactions::$LIST_ADD_PROPERTY)) {
         $valid = false;
     }
     // 2, check $listing_id, có thể sẽ không check cái này
     //        $mListing = Listing::model()->findByPk($listing_id);
     //        if($mListing && Yii::app()->user->id!=$mListing->user_id)
     //                $valid=false;
     // 3. check transaction id
     if (isset($_GET['id'])) {
         $mTransactions = ProTransactions::getByPk($_GET['id']);
         if (is_null($mTransactions) || $mTransactions && Yii::app()->user->id != $mTransactions->user_id || $mTransactions && $mTransactions->status > STATUS_INACTIVE && $mTransactions->status != STATUS_TENANCY_DRAFT) {
             $valid = false;
         }
     }
     if (!$valid) {
         //            throw new CHttpException(404, 'Invalid Request');
         $this->redirect(Yii::app()->createAbsoluteUrl('member/member_profile/myprofile'));
     }
 }
 // xử lý lấy 1 số thông tin của model transaction
 public function GetSomeInfoRecord($mTransactions, $add_property)
 {
     $mTransactions->add_property = $add_property;
     $mTransactions->listing_autocompelte = '';
     if (isset($_GET['listing_id']) && $_GET['listing_id']) {
         $mTransactions->listing_id = $_GET['listing_id'];
         $mTransactions->listing_autocompelte = $mTransactions->listing ? $mTransactions->listing->property_name_or_address : '';
     }
     $mTransactions->mPropertyDetail = $mTransactions->rPropertyDetail ? $mTransactions->rPropertyDetail : new ProTransactionsPropertyDetail();
     $mTransactions->aModelPropertyDocument = count($mTransactions->rPropertyDocument) ? $mTransactions->rPropertyDocument : ProTransactionsPropertyDocument::getDefaultArrayForCreate($mTransactions->type);
     $mTransactions->mTenatDefault = $mTransactions->rTenantDefault ? $mTransactions->rTenantDefault : new ProTransactionsVendorPurchaserDetail();
     ProTransactionsVendorPurchaserDetail::OverideModel($mTransactions->mTenatDefault);
     if (!is_null($mTransactions->mTenatDefault->id)) {
         $mTransactions->mTenatDefault->pass_expiry_date = MyFormat::dateConverYmdToDmy($mTransactions->mTenatDefault->pass_expiry_date, 'd/m/Y');
     }
     $mTransactions->mLandlord = new ProTransactionsVendorPurchaserDetail();