/** * @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 } } }
// // throw new CHttpException(404, $exc->getMessage()); // // } } public function actionAgentUpdateLandlord($id) { try { $model = $this->loadModelVendorPurchaserDetail($id); $model->scenario = 'AgentUpdateLandlordFromTenancy'; if (isset($_GET['from_transactions'])) { $model->scenario = 'AgentUpdateLandlord'; } if (isset($_GET['add_property']) && $_GET['add_property'] == ProTransactions::ADD_UNLISTED) { $model->scenario = 'AgentUpdateLandlordUnlisted'; } if (isset($_POST['ProTransactionsVendorPurchaserDetail'])) { $model->attributes = $_POST['ProTransactionsVendorPurchaserDetail']; $model->validate(); if (!$model->hasErrors()) { $model->update(); Users::UpdateUserVendorPurchaserOnly($model); die('<script type="text/javascript">parent.$.fancybox.close(); parent.fnUpdateGridView("#landlord-grid");</script>'); } } $this->render('CreateTransaction/AgentUpdateLandlord', array('model' => $model)); } catch (Exception $exc) { throw new CHttpException(404, $exc->getMessage()); } } /** http://localhost/propertyinfo-dev/propertyinfo/member/member_profile/createTransaction/id/1/type/1/listing_id/2 * @Author: ANH DUNG Apr 14, 2014 * @Todo: for rent - create Tenant'’s Details */ public function actionAgentAddTenant() { try { $model = new ProTransactionsVendorPurchaserDetail('AgentAddTenantFromTenancy'); if (isset($_GET['from_transactions'])) { $model->scenario = 'AgentAddTenant'; } if (isset($_GET['add_property']) && $_GET['add_property'] == ProTransactions::ADD_UNLISTED) { $model->scenario = 'AgentAddTenantUnlisted'; } $model->transactions_id = $_GET['transactions_id']; if (isset($_POST['ProTransactionsVendorPurchaserDetail'])) { $model->attributes = $_POST['ProTransactionsVendorPurchaserDetail'];
//save ProTransactionsPropertyDocument /*Closed by HTram, because it were uploaded by ajax at the form ProTransactionsPropertyDocument::saveRecord($mTransactions); * */ // 1. email to all new user trong table pro_pro_transactions_vendor_purchaser_detail // Fix Aug 08, 2014 hàm này đã move vào admin (ProTransactions::UpdateAdminStatus) khi admin approve trong backend thì mới send // Dec 01, 2014 Once tenancy is submitted, admin need to approve. // Once admin approved, LL and Tenant account will automatically send an email with Login ID and Password (generated) to Tenant and LL. // ProTransactionsVendorPurchaserDetail::sendMailToNewUser($mTransactions->id, $mTransactions); // ProTransactionsVendorPurchaserDetail::updateRoleUserAfterCreateUpdateTransaction($mTransactions->id); // Fix Aug 08, 2014 // 2. delete all table pro_pro_transactions_vendor_purchaser_detail với transactions_id ko có id nằm trong mảng submit lên // không xử lý kiểu này nữa, khi tạo tenant hoặc landlord ở dưới thì mặc định là tạo mới trên hệ thống rồi // logic này đúng $mTransactions = ProTransactions::LoadModelRelationByPk($mTransactions->id); // Close Dec 01, 2014 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 // Close Dec 01, 2014 $mTransactions = ProTransactions::LoadModelRelationByPk($mTransactions->id); // Close Dec 01, 2014 ProTransactionsSaveCommission::saveOneTransaction($mTransactions); // đoạn này phải find lại model vì bên trên find có with thì // dữ liệu cập nhật ở hàm UpdateBillTo bên trên sẽ ko có trong model này => phải find lại // AutoGenInvoice // Close Dec 01, 2014 ProTransactionsInvoice::AutoGenInvoice($mTransactions); // Close Dec 01, 2014 Listing::SetStatusPastListing($mTransactions->listing_id); Yii::app()->user->setFlash('success', 'Your tenancy has been created successfully');