Контекст :
Стоимость номера хранится в базе данных и является фиксированной, но динамически корректируется в системе для расчета стоимости в зависимости от часов или дней пребывания.Кроме того, продукты, потребляемые в номере (например, напитки или закуски), добавляются и должны быть добавлены к итоговой сумме счета.
Проблема возникает, когда я добавляю продукт в функции Register_update. Вместо правильного суммирования общей суммы цена продукта неправильно добавляет или изменяет стоимость комнаты.
Код: Выделить всё
foreach($detalle_first as $product) {
if ($product['impuesto'] == 1) {
$igv_first += number_format((((float) $product['precio_unitario'] - (float) $product['precio_unitario'] / 1.18) * (int) $product['cantidad']), 2, ".", "");
$igv_first = $this->redondeado($igv_first);
}
if ($product["codigo_igv"] == "10") {
$gravada_first += number_format((((float) $product['precio_unitario'] / 1.18) * (int) $product['cantidad']), 2, ".", "");
$gravada_first = $this->redondeado($gravada_first);
}
if ($product["codigo_igv"] == "20") {
$exonerada_first += number_format(((float) $product['precio_unitario'] * (int) $product['cantidad']), 2, ".", "");
$exonerada_first = $this->redondeado($exonerada_first);
}
if ($product["codigo_igv"] == "30") {
$inafecta_first += number_format(((float) $product['precio_unitario'] * (int) $product['cantidad']), 2, ".", "");
$inafecta_first = str_replace(',', '', $inafecta_first);
$inafecta_first = $this->redondeado($inafecta_first);
}
$subtotal_first = $exonerada_first + $gravada_first + $inafecta_first;
}
if(!empty($detalle_last)) {
foreach($detalle_last as $product) {
if ($product['impuesto'] == 1) {
$igv_last += number_format((((float) $product['precio_unitario'] - (float) $product['precio_unitario'] / 1.18) * (int) $product['cantidad']), 2, ".", "");
$igv_last = $this->redondeado($igv_last);
}
if ($product["codigo_igv"] == "10") {
$gravada_last += number_format((((float) $product['precio_unitario'] / 1.18) * (int) $product['cantidad']), 2, ".", "");
$gravada_last = $this->redondeado($gravada_last);
}
if ($product["codigo_igv"] == "20") {
$exonerada_last += number_format(((float) $product['precio_unitario'] * (int) $product['cantidad']), 2, ".", "");
$exonerada_last = $this->redondeado($exonerada_last);
}
if ($product["codigo_igv"] == "30") {
$inafecta_last += number_format(((float) $product['precio_unitario'] * (int) $product['cantidad']), 2, ".", "");
$inafecta_last = str_replace(',', '', $inafecta_last);
$inafecta_last = $this->redondeado($inafecta_last);
}
$subtotal_last = $exonerada_last + $gravada_last + $inafecta_last;
}
}
Reception::where('id', $idrecepcion)->update([
'fecha_salida' => $fecha_salida,
'exonerada' => $exonerada_first + $exonerada_last,
'inafecta' => $inafecta_first + $inafecta_last,
'gravada' => $gravada_first + $gravada_last,
'anticipo' => "0.00",
'igv' => $igv_first + $igv_last,
'gratuita' => "0.00",
'otros_cargos' => "0.00",
'total' => $subtotal_first + $subtotal_last,
'observaciones' => mb_strtoupper($observaciones),
]);
Подробнее здесь: https://stackoverflow.com/questions/791 ... hp-laravel