public function postDeletePayments()
 {
     $id = Request::input('id');
     $payment = fil_payment_date::find($id);
     if ($payment == null) {
         return Response::json(array('success' => false, 'data' => 'Pago no encontrado'));
     }
     $paymentScheme = $payment->paymentScheme;
     $number = (int) $paymentScheme->pay_number_payments;
     $paymentScheme->pay_number_payments = --$number;
     $paymentScheme->save();
     if (!$payment->delete()) {
         return Response::json(array('success' => false, 'data' => 'Error al eliminar el pago'));
     }
     $fixedAmount = 0;
     $fixedCount = 0;
     foreach ($paymentScheme->paymentDates as $value) {
         if ($value->pda_is_fixed) {
             $fixedAmount += (double) $value->pda_amount;
             $fixedCount++;
         }
     }
     foreach ($paymentScheme->paymentDates as $value) {
         if (!$value->pda_is_fixed) {
             $value->pda_amount = ((double) $paymentScheme->pay_amount_cash - $fixedAmount) / ($number - $fixedCount);
         }
         if (!$value->save()) {
             return Response::json(array('success' => false, 'data' => 'Error al guardar nuevos pagos'));
         }
     }
     return $this->jsonResponse($paymentScheme->serviceOrder->ser_id);
 }
 public function postSaveInvoice()
 {
     $payment = fil_payment_date::find(Request::get('id'));
     if ($payment == null) {
         return Response::json(array('success' => false, 'data' => 'Error al leer el pago'));
     }
     $invoice = new fil_invoice_data();
     $invoice->ind_id = $payment->pda_id;
     $invoice->ind_cfdi = Request::get('content');
     if (!$invoice->save()) {
         return Response::json(array('success' => false, 'data' => 'Error al guardar la factura'));
     }
     $payment->pda_status = 'facturado';
     if (!$payment->save()) {
         return Response::json(array('success' => false, 'data' => 'Error al guardar el pago'));
     }
     $response = Response::json(array('success' => true, 'data' => 'Factura guardada con exito'));
     return $response;
 }