public function postSaveComment()
 {
     $order = fil_service_order::find(Request::get('id'));
     if ($order == null) {
         return Response::json(array('success' => false, 'data' => 'Error al leer orden de servicio'));
     }
     if (Request::get('comment') == '' || Request::get('comment') == null) {
         return Response::json(array('success' => false, 'data' => 'Comentario requerido'));
     }
     $today = date('Y-m-d');
     foreach ($order->detailsProducts as $detail) {
         if ($detail->detailProduction != null) {
             $registry = $detail->detailProduction->productionRegistry;
             if ($registry->prr_customer_answer_1 == null || $registry->prr_customer_answer_1 == '0000-00-00') {
                 $registry->prr_customer_answer_1 = $today;
                 $registry->prr_customer_answer_1_comment = Request::get('comment');
             } else {
                 if ($registry->prr_customer_answer_2 == null || $registry->prr_customer_answer_2 == '0000-00-00') {
                     $registry->prr_customer_answer_2 = $today;
                     $registry->prr_customer_answer_2_comment = Request::get('comment');
                 } else {
                     $registry->prr_customer_answer_3 = $today;
                     $registry->prr_customer_answer_3_comment = Request::get('comment');
                 }
             }
             if ($this->convertToBoolean(Request::get('aprobate'))) {
                 $registry->prr_customer_approbation = 1;
                 $detail->detailProduction->dpr_status = 'Completa';
                 if (!$detail->detailProduction->save()) {
                     return Response::json(array('success' => false, 'data' => 'Error al guardar el registro'));
                 }
             }
             if (!$registry->save()) {
                 return Response::json(array('success' => false, 'data' => 'Error al guardar el registro'));
             }
         }
     }
     return 'Respuesta guardada';
 }
 public function postReadDetails()
 {
     $values = Request::all();
     $details = fil_service_order::find($values['ser_id'])->detailsProducts;
     $finalArray = [];
     if ($values['vid_type'] == 'programación') {
         foreach ($details as $value) {
             if ($value->product->pro_type == 'transmisión' && $value->video == null) {
                 if ($value->product->serviceProyection->spy_has_show == '1') {
                     $finalArray[] = $value;
                 }
             }
         }
     } else {
         foreach ($details as $value) {
             if ($value->product->pro_type == 'transmisión' && $value->video == null) {
                 if ($value->product->serviceProyection->spy_has_show == '0') {
                     $finalArray[] = $value;
                 }
             }
         }
     }
     return Response::json(array('success' => true, 'data' => $finalArray));
 }
 public function readPayments($id)
 {
     $payments = fil_service_order::find($id)->paymentScheme->paymentDates;
     if ($payments == null) {
         return Response::json(array('success' => false, 'data' => 'Error al leer los pagos'));
     }
     $outstanding = [];
     $full = [];
     $late = [];
     $today = date('Y-m-d');
     $today = date('Y-m-d', strtotime($today));
     foreach ($payments as $value) {
         if ($value->paymentScheme->serviceOrder->ser_auth_admin == 2 && $value->paymentScheme->serviceOrder->ser_auth_production == 2 && $value->paymentScheme->serviceOrder->ser_auth_sales == 2) {
             if ($value->pda_status == 'facturado') {
                 $paymentsTotal = 0;
                 foreach ($value->realPayments as $payment) {
                     $paymentsTotal = $paymentsTotal + (double) $payment->rpa_amount;
                 }
                 $value->paymentScheme->serviceOrder->customer;
                 $value->pda_outstanding = (double) $value->pda_amount - $paymentsTotal;
                 if ($today <= date('Y-m-d', strtotime($value->pda_date))) {
                     $outstanding[] = $value;
                 } else {
                     $late[] = $value;
                 }
             } else {
                 if ($value->pda_status == 'pagado') {
                     $full[] = $value;
                 }
             }
         }
     }
     $customer = fil_service_order::find($id)->customer->cus_contact_first_name . ' ' . fil_service_order::find($id)->customer->cus_contact_last_name;
     $commercialName = fil_service_order::find($id)->customer->cus_commercial_name;
     $data = array('outstanding' => json_encode($outstanding), 'full' => json_encode($full), 'late' => json_encode($late), 'header' => $id, 'customer' => $customer, 'commercialName' => $commercialName);
     return view('tesoreria_orden_de_servicio', $data);
 }