rfc = $rfc; } /** * Método para indicar desde qué fila comenzar a leer. */ public function startRow(): int { return 2; // Si tienes encabezados, comienza en la fila 2 } public function model(array $row) { $rfc = Rfc::where('rfc', $this->rfc)->firstOrCreate([ 'rfc' => $this->rfc ]); $invoice = Invoice::where('id', strip_tags($row['invoice_uuid']))->firstOrCreate([ 'id' => $row['invoice_uuid'] ]); $type = InvoiceType::where('id', strip_tags($row['invoice_type']))->firstOrCreate([ 'id' => $row['invoice_type'] ]); if ($this->emptyToNull($row['paymentType'])) { $paymentType = PaymentType::where('id', strip_tags($row['paymentType']))->firstOrCreate([ 'id' => $row['paymentType'] ]); } if ($this->emptyToNull($row['invoice_status'])) { $status = Status::where('description', strip_tags($row['status']))->firstOrCreatet([ 'description' => $row['status'] ]); } $issuerRfc = Rfc::where('rfc', strip_tags($row['issuer_rfc']))->firstOrCreate([ 'rfc' => $row['issuer_rfc'] ]); $receiverRfc = Rfc::where('rfc', strip_tags($row['receiver_rfc']))->firstOrCreate([ 'rfc' => $row['receiver_rfc'] ]); return InvoiceLine::updateOrCreate( ['id' => $invoiceLine_data['id']], [ 'rfc_id' => $rfc->id, 'invoice_id' => $invoice->id, 'invoice_type_id' => $type->id, 'payment_type_id' => $paymentType->id, 'status_id' => $status->id, 'issuer_rfc_id' => $issuerRfc->id, 'issuer_name' => $this->emptyToNull($row['issuername']), 'receiver_rfc_id' => $receiverRfc->id, 'receiver_name' => $this->emptyToNull($row['receivername']), 'issued_at' => Carbon::createFromFormat('Y-m-d H:i:s', $row['issuedAt']); 'identification_number' => $row['identificationNumber']; 'product_identification' => $row['productIdentification']; 'description' => $row['description']; 'unit_amount' => $row['unitAmount']; 'unit_code' => $row['unitCode']; 'quantity' => $row['quantity']; 'discount_amount' => $row['discountAmount']; 'total_amount' => $row['totalAmount']; 'retained_vat' => $row['rrowvalueAddedTax']; 'retained_income_tax' => $row['retainedTaxes']['incomeTax']; 'retained_sin_tax' => $row['retainedTaxes']['sinTax']; 'transferred_vat' => $row['transferredTaxes']['valueAddedTax']; 'transferred_sin_tax' => $row['transferredTaxes']['sinTax']; ] ); } private function emptyToNull($value) { return $value === '' ? null : $value; } /** * Devuelve el tamaño del chunk (en filas) a leer. */ public function chunkSize(): int { return 5000; // Ajusta el tamaño según tus necesidades } }