| Server IP : 162.214.74.102 / Your IP : 216.73.217.114 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/www/lrsys_apps/leo/application/plugins/module_imobles/models/ |
Upload File : |
<?php
include_once __DIR__ . "/../../../autoload/My_Model.php";
include_once __DIR__ . "/../factories/ProposalFactory.php";
class ProposalModel extends My_Model {
/**
* @var string
*/
public $table = 'module_imobles_proposal';
public function createProposal($data) {
$proposal = self::create();
ProposalFactory::create($data, $proposal, true);
$proposal->save();
return $proposal;
}
public function updateProposal($data, $proposal) {
ORM::for_table($this->table)->create($proposal);
ProposalFactory::create($data, $proposal);
$proposal->save();
return $proposal;
}
public function deleteProposal($proposal) {
ORM::for_table($this->table)->create($proposal);
$now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$user = User::_info();
$proposal->deleted_at = $now->format('Y-m-d H:i:s');
$proposal->deleted_by = $user->id;
$proposal->save();
return $proposal;
}
public function addProposalComment($proposalID, $unitTypeID, $comment, $from_client = false, $api = false){
$c = ORM::for_table("module_imobles_proposal_comments")->create();
$c->created_at = date('Y-m-d H:i:s');
if ($api){
$c->created_by = null;
} else {
$user = User::_info();
$c->created_by = $user->id;
}
$c->proposal_id = $proposalID;
$c->unit_type_id = $unitTypeID;
$c->comment = $comment;
$c->from_me = !$from_client;
$c->save();
return $c;
}
public function getProposalComment($commentID){
$comment = ORM::for_table('module_imobles_proposal_comments')
->find_one($commentID);
return $comment;
}
public function getProposalComments($proposalID, $typeUnitID = null, $fromScenarioOnly = false){
$comments = ORM::for_table("module_imobles_proposal_comments")
->table_alias("c")
->select_many("c.id", "c.unit_type_id", "c.created_at", "comment", "from_me", "fullname")
->left_outer_join("sys_users", "c.created_by = u.id", "u")
->where("c.proposal_id", $proposalID)
->where_null('deleted_at')
->order_by_desc("c.created_at");
if($typeUnitID){
$comments->where("c.unit_type_id", $typeUnitID);
}
if($fromScenarioOnly){
$comments->where_null("c.unit_type_id");
}
$comments = $comments->find_many();
return $comments;
}
public function getClientScenarios($clientID, $hideReproved = false, $withComments = false){
$deal = ORM::for_table('module_imobles_deals')
->where('crm_account_id', $clientID)
->where_null('deleted_at')
->order_by_desc('id')
->find_one();
if(isset($deal->id)){
$scenarios = ORM::for_table($this->table)
->where('client_id', $clientID)
->where('deal_id', $deal->id)
->where_not_null('scenario_title')
->where_not_equal('scenario_title', '')
->where_null('deleted_at')
->order_by_desc("created_at");
if($hideReproved){
$scenarios->where_raw('(scenario_approved IS NULL OR scenario_approved = TRUE)');
}
$scenarios = $scenarios->find_many();
if($withComments){
foreach ($scenarios as $s){
$s->comments = $this->getProposalComments($s->id, null, true);
}
}
} else {
$scenarios = [];
}
return $scenarios;
}
public function editProposalComment($scenarioComment, $comment){
$now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$scenarioComment->comment = $comment;
$scenarioComment->updated_at = $now->format('Y-m-d H:i:s');
$scenarioComment->updated_by = null;
$scenarioComment->save();
return $scenarioComment;
}
public function deleteProposalComment($scenarioComment){
$now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
$scenarioComment->deleted_at = $now->format('Y-m-d H:i:s');
$scenarioComment->deleted_by = null;
$scenarioComment->save();
return $scenarioComment;
}
}