Created
January 25, 2019 17:06
-
-
Save caionorder/168fb849283914079cdb70f14f98370b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function admin_add() { | |
$this->layout="Adm.admin"; | |
$plans = $this->Income->Plan->find('list',array( | |
'fields'=>array( | |
'Plan.id','Plan.nome' | |
), | |
'order'=>array( | |
'Plan.nome' | |
) | |
)); | |
$doctors = $this->Income->Doctor->find('list',array( | |
'fields'=>array( | |
'Doctor.id','Doctor.nome' | |
), | |
'order'=>array( | |
'Doctor.nome' | |
) | |
)); | |
$patients = $this->Income->Patient->find('list',array( | |
'fields'=>array( | |
'Patient.id','Patient.nome' | |
), | |
'order'=>array( | |
'Patient.nome' | |
) | |
)); | |
$banks = $this->Income->Bank->find('list',array( | |
'fields'=>array( | |
'Bank.id','Bank.banco' | |
), | |
'order'=>array( | |
'Bank.banco' | |
) | |
)); | |
$this->set(compact('doctors','patients','plans','banks')); | |
if ($this->request->is('post')) { | |
unset($this->request->data['table_listservices_length']); | |
unset($this->request->data['table_addservices_length']); | |
$this->request->data['Income']['customer_id'] = $this->Auth->user('customer_id'); | |
$this->request->data['Income']['user_id'] = $this->Auth->user('id'); | |
$this->request->data['Income']['created'] = $this->formatar_data($this->request->data['Income']['created']).' 10:00:00'; | |
$this->request->data['Income']['parcelamento']; | |
$this->request->data['Income']['total']; | |
$this->request->data['Income']['desconto']; | |
if($this->request->data['Income']['parcelamento'] == 0){ | |
$this->request->data['Movimentation']['valor'] = $this->request->data['Income']['total']; | |
$this->request->data['Movimentation']['tipo'] = $this->request->data['Income']['forma']; | |
$this->request->data['Movimentation']['bank_id'] = $this->request->data['Income']['bank_id']; | |
$this->request->data['Movimentation']['customer_id'] = $this->request->data['Income']['customer_id']; | |
$this->request->data['Movimentation']['data'] = date('Y-m-d'); | |
} else { | |
for ($i=0; $i < $this->request->data['Income']['parcelamento']; $i++) { | |
$this->request->data['Movimentation'][$i]['valor'] = $this->request->data['Income']['total']/$this->request->data['Income']['parcelamento']; | |
$this->request->data['Movimentation'][$i]['tipo'] = $this->request->data['Income']['forma']; | |
$this->request->data['Movimentation'][$i]['bank_id'] = $this->request->data['Income']['bank_id']; | |
$this->request->data['Movimentation'][$i]['customer_id'] = $this->request->data['Income']['customer_id']; | |
$this->request->data['Movimentation'][$i]['data'] = date("Y-m-d",strtotime("+".$i." month",strtotime(date("Y-m-d")))); | |
} | |
} | |
// pr($this->request->data); | |
// die(); | |
if($this->request->data['Income']['clonar'] > 0){ | |
for ($i=0; $i < $this->request->data['Income']['clonar']; $i++) { | |
$this->Income->create(); | |
if ($this->Income->save($this->request->data)) { | |
$this->Session->setFlash('cadastrado com sucesso','default',array('class'=>'ls-alert-success')); | |
} else { | |
$this->Session->setFlash('Erro, tente novamente','default',array('class'=>'ls-alert-danger')); | |
} | |
} | |
$this->redirect(array('action' => 'index')); | |
} else { | |
$this->Income->create(); | |
if ($this->Income->saveAssociated($this->request->data,array('deep'=>true))) { | |
$this->Session->setFlash('cadastrado com sucesso','default',array('class'=>'ls-alert-success')); | |
$this->redirect(array('action' => 'index')); | |
} else { | |
debug($this->Income->getErrors()); | |
die(); | |
$this->Session->setFlash('Erro, tente novamente','default',array('class'=>'ls-alert-danger')); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Income extends AppModel{ | |
public $recursive = 3; | |
public $actsAs = array('Containable'); | |
public $belongsTo = array( | |
'Doctor'=> array( | |
'className' => 'Doctors.Doctor', | |
'foreignKey' => 'doctor_id' | |
), | |
'Patient'=> array( | |
'className' => 'Patients.Patient', | |
'foreignKey' => 'patient_id' | |
), | |
'Plan'=> array( | |
'className' => 'Plans.Plan', | |
'foreignKey' => 'plan_id' | |
), | |
'Bank'=> array( | |
'className' => 'Banks.Bank', | |
'foreignKey' => 'bank_id' | |
) | |
); | |
public $hasMany = array( | |
'Movimentation'=> array( | |
'className' => 'Banks.Movimentation', | |
'foreignKey' => 'income_id' | |
) | |
); | |
public $hasAndBelongsToMany = array( | |
'Service' => array( | |
'className' => 'Services.Service', | |
'joinTable' => 'incomes_services', | |
'foreignKey' => 'income_id', | |
'associationForeignKey' => 'service_id', | |
'unique' =>true, | |
'dependent'=>true, | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment