Created
October 11, 2020 08:56
-
-
Save jfalbel/1f2d4f131787dc366ef250a6cfc867fb to your computer and use it in GitHub Desktop.
This file contains 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
'Auth' => object(App\Model\Entity\Usuario) id:0 { | |
'id' => (int) 5 | |
'propietario_id' => (int) 3 | |
'usuario' => 'jfalbel' | |
'password' => '$2y$10$JdqPzmY8fxco9kO0UIvOFe.CUM1vNi.WtPcHZkzMVpnnyKaV3l1S.' | |
'timezone' => 'Europe/Madrid' | |
'created' => object(Cake\I18n\FrozenTime) id:1 { } | |
'modified' => object(Cake\I18n\FrozenTime) id:2 { } |
This file contains 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 | |
declare(strict_types=1); | |
namespace App\Model\Table; | |
use Cake\ORM\Query; | |
use Cake\ORM\RulesChecker; | |
use Cake\ORM\Table; | |
use Cake\Validation\Validator; | |
/** | |
* Clientes Model | |
* | |
* @property \App\Model\Table\PropietariosTable&\Cake\ORM\Association\BelongsTo $Propietarios | |
* @property \App\Model\Table\AlbaranesTable&\Cake\ORM\Association\HasMany $Albaranes | |
* @property \App\Model\Table\PedidosTable&\Cake\ORM\Association\HasMany $Pedidos | |
* | |
* @method \App\Model\Entity\Cliente newEmptyEntity() | |
* @method \App\Model\Entity\Cliente newEntity(array $data, array $options = []) | |
* @method \App\Model\Entity\Cliente[] newEntities(array $data, array $options = []) | |
* @method \App\Model\Entity\Cliente get($primaryKey, $options = []) | |
* @method \App\Model\Entity\Cliente findOrCreate($search, ?callable $callback = null, $options = []) | |
* @method \App\Model\Entity\Cliente patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) | |
* @method \App\Model\Entity\Cliente[] patchEntities(iterable $entities, array $data, array $options = []) | |
* @method \App\Model\Entity\Cliente|false save(\Cake\Datasource\EntityInterface $entity, $options = []) | |
* @method \App\Model\Entity\Cliente saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = []) | |
* @method \App\Model\Entity\Cliente[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, $options = []) | |
* @method \App\Model\Entity\Cliente[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, $options = []) | |
* @method \App\Model\Entity\Cliente[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, $options = []) | |
* @method \App\Model\Entity\Cliente[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, $options = []) | |
*/ | |
class ClientesTable extends Table | |
{ | |
/** | |
* Initialize method | |
* | |
* @param array $config The configuration for the Table. | |
* @return void | |
*/ | |
public function initialize(array $config): void | |
{ | |
parent::initialize($config); | |
$this->setTable('clientes'); | |
$this->setDisplayField('id'); | |
$this->setPrimaryKey('id'); | |
$this->belongsTo('Propietarios', [ | |
'foreignKey' => 'propietario_id', | |
'joinType' => 'INNER', | |
]); | |
$this->hasMany('Albaranes', [ | |
'foreignKey' => 'cliente_id', | |
]); | |
$this->hasMany('Pedidos', [ | |
'foreignKey' => 'cliente_id', | |
]); | |
$this->addBehavior('Muffin/Footprint.Footprint', [ | |
'events' => [ | |
'Model.beforeSave' => [ | |
'propietario_id' => 'new', | |
], | |
'Model.beforeFind' => [ | |
'propietario_id' | |
] | |
], | |
'propertiesMap' => [ | |
'propietario_id' => '_footprint.propietario_id', | |
], | |
]); | |
} | |
/** | |
* Default validation rules. | |
* | |
* @param \Cake\Validation\Validator $validator Validator instance. | |
* @return \Cake\Validation\Validator | |
*/ | |
public function validationDefault(Validator $validator): Validator | |
{ | |
$validator | |
->integer('id') | |
->allowEmptyString('id', null, 'create'); | |
$validator | |
->scalar('alias') | |
->maxLength('alias', 255) | |
->requirePresence('alias', 'create') | |
->notEmptyString('alias'); | |
$validator | |
->email('email') | |
->allowEmptyString('email'); | |
$validator | |
->scalar('nombre') | |
->maxLength('nombre', 255) | |
->allowEmptyString('nombre'); | |
$validator | |
->scalar('cif') | |
->maxLength('cif', 12) | |
->allowEmptyString('cif'); | |
$validator | |
->scalar('direccion') | |
->maxLength('direccion', 255) | |
->allowEmptyString('direccion'); | |
$validator | |
->scalar('localidad') | |
->maxLength('localidad', 255) | |
->allowEmptyString('localidad'); | |
$validator | |
->scalar('provincia') | |
->maxLength('provincia', 255) | |
->allowEmptyString('provincia'); | |
$validator | |
->scalar('cpostal') | |
->maxLength('cpostal', 5) | |
->allowEmptyString('cpostal'); | |
return $validator; | |
} | |
/** | |
* Returns a rules checker object that will be used for validating | |
* application integrity. | |
* | |
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. | |
* @return \Cake\ORM\RulesChecker | |
*/ | |
public function buildRules(RulesChecker $rules): RulesChecker | |
{ | |
$rules->add($rules->existsIn(['propietario_id'], 'Propietarios'), ['errorField' => 'propietario_id']); | |
return $rules; | |
} | |
} |
This file contains 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
/** | |
* Add method | |
* | |
* @return \Cake\Http\Response|null|void Redirects on successful add, renders view otherwise. | |
*/ | |
public function add() | |
{ | |
$factura = $this->Facturas->newEmptyEntity(); | |
if ($this->request->is('post')) { | |
$factura = $this->Facturas->patchEntity($factura, $this->request->getData()); | |
if ($this->Facturas->save($factura)) { | |
$this->Flash->success(__('The factura has been saved.')); | |
return $this->redirect(['action' => 'index']); | |
} | |
$this->Flash->error(__('The factura could not be saved. Please, try again.')); | |
} | |
$propietarios = $this->Facturas->Propietarios->find('list', ['limit' => 200]); | |
$clientes = $this->Facturas->Clientes->find('list', ['limit' => 200]); | |
$this->set(compact('factura', 'propietarios', 'clientes')); | |
} |
This file contains 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 | |
declare(strict_types=1); | |
namespace App\Model\Table; | |
use Cake\ORM\Query; | |
use Cake\ORM\RulesChecker; | |
use Cake\ORM\Table; | |
use Cake\Validation\Validator; | |
/** | |
* Facturas Model | |
* | |
* @property \App\Model\Table\PropietariosTable&\Cake\ORM\Association\BelongsTo $Propietarios | |
* @property \App\Model\Table\ClientesTable&\Cake\ORM\Association\BelongsTo $Clientes | |
* @property \App\Model\Table\AlbaranesTable&\Cake\ORM\Association\HasMany $Albaranes | |
* | |
* @method \App\Model\Entity\Factura newEmptyEntity() | |
* @method \App\Model\Entity\Factura newEntity(array $data, array $options = []) | |
* @method \App\Model\Entity\Factura[] newEntities(array $data, array $options = []) | |
* @method \App\Model\Entity\Factura get($primaryKey, $options = []) | |
* @method \App\Model\Entity\Factura findOrCreate($search, ?callable $callback = null, $options = []) | |
* @method \App\Model\Entity\Factura patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) | |
* @method \App\Model\Entity\Factura[] patchEntities(iterable $entities, array $data, array $options = []) | |
* @method \App\Model\Entity\Factura|false save(\Cake\Datasource\EntityInterface $entity, $options = []) | |
* @method \App\Model\Entity\Factura saveOrFail(\Cake\Datasource\EntityInterface $entity, $options = []) | |
* @method \App\Model\Entity\Factura[]|\Cake\Datasource\ResultSetInterface|false saveMany(iterable $entities, $options = []) | |
* @method \App\Model\Entity\Factura[]|\Cake\Datasource\ResultSetInterface saveManyOrFail(iterable $entities, $options = []) | |
* @method \App\Model\Entity\Factura[]|\Cake\Datasource\ResultSetInterface|false deleteMany(iterable $entities, $options = []) | |
* @method \App\Model\Entity\Factura[]|\Cake\Datasource\ResultSetInterface deleteManyOrFail(iterable $entities, $options = []) | |
*/ | |
class FacturasTable extends Table | |
{ | |
/** | |
* Initialize method | |
* | |
* @param array $config The configuration for the Table. | |
* @return void | |
*/ | |
public function initialize(array $config): void | |
{ | |
parent::initialize($config); | |
$this->setTable('facturas'); | |
$this->setDisplayField('id'); | |
$this->setPrimaryKey('id'); | |
$this->belongsTo('Propietarios', [ | |
'foreignKey' => 'propietario_id', | |
'joinType' => 'INNER', | |
]); | |
$this->belongsTo('Clientes', [ | |
'foreignKey' => 'cliente_id', | |
'joinType' => 'INNER', | |
]); | |
$this->belongsTo('Impuestos', [ | |
'foreignKey' => 'impuesto_id', | |
]); | |
$this->hasMany('Albaranes', [ | |
'foreignKey' => 'factura_id', | |
]); | |
$this->addBehavior('Muffin/Footprint.Footprint', [ | |
'events' => [ | |
'Model.beforeSave' => [ | |
'propietario_id' => 'new', | |
], | |
'Model.beforeFind' => [ | |
'propietario_id' | |
] | |
], | |
'propertiesMap' => [ | |
'propietario_id' => '_footprint.propietario_id', | |
], | |
]); | |
} | |
/** | |
* Default validation rules. | |
* | |
* @param \Cake\Validation\Validator $validator Validator instance. | |
* @return \Cake\Validation\Validator | |
*/ | |
public function validationDefault(Validator $validator): Validator | |
{ | |
$validator | |
->integer('id') | |
->allowEmptyString('id', null, 'create'); | |
$validator | |
->scalar('numero') | |
->maxLength('numero', 255) | |
->allowEmptyString('numero'); | |
$validator | |
->numeric('subtotal') | |
->notEmptyString('subtotal'); | |
$validator | |
->numeric('impuestos') | |
->notEmptyString('impuestos'); | |
$validator | |
->numeric('total') | |
->notEmptyString('total'); | |
$validator | |
->boolean('cobrada') | |
->notEmptyString('cobrada'); | |
$validator | |
->scalar('comentarios') | |
->maxLength('comentarios', 2000) | |
->allowEmptyString('comentarios'); | |
$validator | |
->dateTime('fechafactura') | |
->notEmptyDateTime('fechafactura'); | |
$validator | |
->dateTime('fechacobro') | |
->allowEmptyDateTime('fechacobro'); | |
return $validator; | |
} | |
/** | |
* Returns a rules checker object that will be used for validating | |
* application integrity. | |
* | |
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. | |
* @return \Cake\ORM\RulesChecker | |
*/ | |
public function buildRules(RulesChecker $rules): RulesChecker | |
{ | |
$rules->add($rules->existsIn(['propietario_id'], 'Propietarios'), ['errorField' => 'propietario_id']); | |
$rules->add($rules->existsIn(['cliente_id'], 'Clientes'), ['errorField' => 'cliente_id']); | |
$rules->add($rules->existsIn(['impuesto_id'], 'Impuestos'), ['errorField' => 'impuesto_id']); | |
return $rules; | |
} | |
public function findImpagadas(Query $q) | |
{ | |
return $q->where(['cobrada' => false]); | |
} | |
public function findRecientes(Query $q) | |
{ | |
return $q->where(['fechafactura' => date('Y-m-d H:i:s','-30 days')]); | |
} | |
} |
This file contains 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 | |
/** | |
* @var \App\View\AppView $this | |
* @var \App\Model\Entity\Factura $factura | |
*/ | |
?> | |
<div class="row"> | |
<aside class="column"> | |
<div class="side-nav"> | |
<h4 class="heading"><?= __('Actions') ?></h4> | |
<?= $this->Html->link(__('List Facturas'), ['action' => 'index'], ['class' => 'side-nav-item']) ?> | |
</div> | |
</aside> | |
<div class="column-responsive column-80"> | |
<div class="facturas form content"> | |
<?= $this->Form->create($factura) ?> | |
<fieldset> | |
<legend><?= __('Add Factura') ?></legend> | |
<?php | |
echo $this->Form->control('propietario_id', ['options' => $propietarios]); | |
echo $this->Form->control('cliente_id', ['options' => $clientes]); | |
echo $this->Form->control('impuesto_id'); | |
echo $this->Form->control('numero'); | |
echo $this->Form->control('subtotal'); | |
echo $this->Form->control('impuestos'); | |
echo $this->Form->control('total'); | |
echo $this->Form->control('cobrada'); | |
echo $this->Form->control('comentarios'); | |
echo $this->Form->control('fechafactura'); | |
echo $this->Form->control('fechacobro', ['empty' => true]); | |
?> | |
</fieldset> | |
<?= $this->Form->button(__('Submit')) ?> | |
<?= $this->Form->end() ?> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment