我正在 Laravel 中开发房间注册和预订系统,当我在
Register_update
功能中添加产品时,我在更新房间信息时遇到问题。
背景:
房价存储在数据库中并且是固定的,但会在系统中动态调整,以根据入住的小时或天数计算费用。
此外,房间内消费的产品(例如饮料或零食)也将被添加到最终账单总额中。
当我在
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),
]);
添加产品时不会增加房间的费用。
这可能是问题:
number_format((((float) $product['precio_unitario'] - (float) $product['precio_unitario'] / 1.18) * (int) $product['cantidad']), 2, ".", "")
您从
(float) $product['precio_unitario'] / 1.18
中减去 (float) $product['precio_unitario']
。您可能只需要计算 precio_unitario 和 cantidad 的乘积,并将结果添加到您拥有的变量中。您对 $igv_first
、$gravada_first
、$exonerada_first
和 $inafecta_first
都有这种奇怪的(可能是错误的)模式。此外,还不清楚如何初始化它们以及 redondeado
到底是什么。