public function postLoadPackagesDetail() { $values = Request::all(); $package = fil_package::find($values['id']); if ($package == null) { return Response::json(array('success' => false, 'data' => 'Error al leer los paquetes')); } $detail = $package->packagesDetail; $finalArray = []; foreach ($detail as $value) { $row = []; $row['det_fk_product'] = $value->product->pro_id; $row['det_name'] = $value->product->pro_name; $row['det_type'] = $value->product->pro_type; $row['det_discount'] = $value->pad_discount; $row['det_final_price'] = $value->pad_final_price; if ($value->product->pro_type == 'transmisión') { if ($value->product->serviceProyection->spy_has_show) { $row['det_fk_show'] = null; } $row['det_impacts'] = $value->pad_impacts; $row['det_validity'] = $value->pad_validity; $row['det_subtotal'] = (double) $row['det_final_price'] * (double) $row['det_validity'] * (double) $row['det_impacts']; } else { if ($value->product->serviceProduction->spr_has_production_registry) { $row['det_has_production_registry'] = null; } $row['det_impacts'] = ""; $row['det_validity'] = ""; $row['det_subtotal'] = (double) $row['det_final_price']; } //if (($value->product->serviceProyection->spy_proyection_media == 'televisión') and ($value->product->serviceProyection->spy_has_show == "0")) { // $row['det_subtotal'] = (float)$row['det_final_price'] * (float)$row['det_validity'] * (float)$row['det_impacts'] * 10; //} //else { //} $finalArray[] = $row; } $response = Response::json(array('success' => true, 'data' => $finalArray)); return $response; }
public function postUpdatePrice() { $values = Request::all(); $package = fil_package::find($values['pac_id']); $totalOutlay = 0; foreach ($package->packagesDetail as $detail) { if ($detail->product->pro_type == 'transmisión') { $totalOutlay += (double) $detail->product->serviceProyection->spy_outlay * (double) $detail->pad_impacts * (double) $detail->pad_validity; } } $discount = (double) $values['pac_outlay'] / $totalOutlay; $discount = round($discount, 4); $discountToSave = 1 - $discount; foreach ($package->packagesDetail as $detail) { if ($detail->product->pro_type == 'transmisión') { $detail->pad_final_price = (double) $detail->product->serviceProyection->spy_outlay * $discount; $detail->pad_discount = $discountToSave; $detail->save(); } } $newOutlay = 0; $package = fil_package::find($values['pac_id']); foreach ($package->packagesDetail as $detail) { if ($detail->product->pro_type == 'transmisión') { $newOutlay += round((double) $detail->pad_final_price * (double) $detail->pad_validity * (double) $detail->pad_impacts, 2); } } $package->pac_outlay = $newOutlay; $package->save(); return Response::json(array('success' => true, 'data' => 'Paquete guardado correctamente')); }