File: /var/www/dtw.bradford/app/Models/OdooRenditions.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class OdooRenditions extends Model
{
use HasFactory;
protected $table = 'odoo_renditions_view';
public $timestamps = false;
protected $fillable = [
'account_move_id',
'name',
'display_name',
'state',
'move_type',
'ref',
'date',
'invoice_date_due',
'partner_id',
'partner',
'partner_id_vat',
'currency_id',
'currency',
'amount_untaxed',
'amount_tax',
'amount_total',
'amount_total_words',
'payment_state',
'journal_id',
'journal',
'partner_bank_id',
'partner_bank',
'company_id',
'company',
'invoice_payment_term',
'create_uid_id',
'create_uid_name',
'account_move_lines' // JSON con los detalles de la factura
];
// Método para obtener detalles de líneas de la factura
protected function details()
{
// Decode JSON from account_move_lines to an array
return collect(json_decode($this->account_move_lines, true))->map(function ($line) {
return [
'line_id' => $line['line_id'],
'move_id' => $line['move_id'],
'name' => $line['name'],
'product_id' => $line['product_id'],
'product' => $line['product'],
'quantity' => $line['quantity'],
'price_unit' => $line['price_unit'],
'price_subtotal' => $line['price_subtotal'],
'price_total' => $line['price_total'],
];
});
}
// Sobrescribir el método toArray
public function toArray()
{
$array = parent::toArray();
$array['account_move_lines'] = $this->details(); // Añadir las líneas formateadas
return $array;
}
}