setTable('credito'); } public function create(?array $data = null): Model\Venta\Credito { $map = (new Implement\Repository\MapperParser(['valor'])) ->register('pago', (new Implement\Repository\Mapper()) ->setFunction(function($data) { return $this->pagoService->getById($data['pago']); })); return $this->parseData(new Model\Venta\Credito(), $data, $map); } public function save(Define\Model $model): Model\Venta\Credito { $model->id = $this->saveNew( ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], [$model->pago->banco?->id, $model->valor ?? (($model->pago->uf > 0) ? $model->pago->valor / $model->pago->uf : null), $model->pago->fecha->format('Y-m-d'), $model->pago->uf, null, null, $model->pago->id] ); return $model; } public function edit(Define\Model $model, array $new_data): Model\Venta\Credito { return $this->update($model, ['banco', 'valor', 'fecha', 'uf', 'abonado', 'fecha_abono', 'pago'], $new_data); } /** * @param int $value * @return array * @throws Implement\Exception\EmptyResult */ public function fetchByValue(int $value): array { $query = $this->connection->getQueryBuilder() ->select() ->from($this->getTable()) ->where('valor = ?'); return $this->fetchMany($query, [$value]); } public function fetchByPago(int $pago_id): Model\Venta\Credito { $query = $this->connection->getQueryBuilder() ->select() ->from($this->getTable()) ->where('pago = ?'); return $this->fetchOne($query, [$pago_id]); } public function fetchByVenta(int $venta_id): Model\Venta\Credito { $query = $this->connection->getQueryBuilder() ->select('a.*') ->from("{$this->getTable()} a") ->joined('JOIN venta ON venta.credito = a.id') ->where('venta.id = ?'); return $this->fetchOne($query, [$venta_id]); } }