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
         }
     }
 }