public function edit(Request $request)
 {
     $material = $this->CashMonthlyRepo->find($request->id);
     //var_dump($material);
     //die();
     $manager = new CashMonthlyManager($material, $request->all());
     $manager->save();
     //Event::fire('update.material',$material->all());
     return response()->json(['estado' => true, 'nombre' => $material->nombre]);
 }
 public function createPago2(Request $request)
 {
     //var_dump($request->all());die();
     \DB::beginTransaction();
     $otherPhead = $this->expenseRepo->find($request->idpago);
     $request->merge(["montoPagado" => floatval($otherPhead->montoPagado) + floatval($request->input("monto"))]);
     $request->merge(["Saldo" => floatval($otherPhead->Saldo) - floatval($request->input("monto"))]);
     if (!empty($request->input('cashe_id'))) {
         $caja = $this->cashRepo->find($request->input('cashe_id'));
         $request->merge(['montoCaja' => $caja->montoBruto]);
         $detCash = $this->detCashRepo->getModel();
         //var_dump($caja);die();
         $request->merge(['gastos' => $caja->gastos + $request->input('monto')]);
         $request->merge(['montoBruto' => floatval($caja->ingresos + $caja->montoInicial) - floatval($request->input('gastos'))]);
         $request->merge(['montoInicial' => $caja->montoInicial]);
         $request->merge(['fechaInicio' => $caja->fechaInicio]);
         $request->merge(['ingresos' => $caja->ingresos]);
         $request->merge(['montoReal' => $caja->montoReal]);
         $request->merge(['descuadre' => $caja->descuadre]);
         $request->merge(['estado' => $caja->estado]);
         $request->merge(['cashHeader_id' => $caja->cashHeader_id]);
         $request->merge(['user_id' => $caja->user_id]);
         $manager = new CashManager($caja, $request->all());
         $manager->save();
         $request->merge(['montoMovimientoTarjeta' => 0]);
         $request->merge(['montoMovimientoEfectivo' => $request->input('monto')]);
         $request->merge(['montoFinal' => $request->input('montoBruto')]);
         $request->merge(['estado' => 1]);
         $request->merge(['observacion' => 'Gastos Especiales']);
         $request->merge(['cashMotive_id' => 7]);
         $request->merge(['cash_id' => $request->input('cashe_id')]);
         $request->merge(['expense_id' => $request->input('idpago')]);
         //$cash = $this->CashRepo->getModel();
         // $var=$request->detalles;
         $detcash = new detCashManager($detCash, $request->all());
         $detcash->save();
     } else {
         $cashMonthly = $this->cashMonthlyRepo->getModel();
         $request->merge(['amount' => $request->input('monto')]);
         $request->merge(['descripcion' => 'Pago Por insumos y otros']);
         $request->merge(['expenseMonthlys_id' => 1]);
         $request->merge(['expense_id' => $request->input('idpago')]);
         $detcash = new CashMonthlyManager($cashMonthly, $request->all());
         $detcash->save();
     }
     $request->merge(["fecha" => $otherPhead->fecha]);
     $request->merge(["numeroDocumento" => $otherPhead->numeroDocumento]);
     $request->merge(["proveedor" => $otherPhead->proveedor]);
     $request->merge(["ruc" => $otherPhead->ruc]);
     $compras = new ExpenseManager($otherPhead, $request->only("fecha", "numeroDocumento", "proveedor", "ruc", "montoPagado", "Saldo"));
     $compras->save();
     \DB::commit();
     return response()->json(['estado' => true]);
 }
 public function create(Request $request)
 {
     \DB::beginTransaction();
     // var_dump($request->all());die();;
     $var = $request->detPayments;
     //var_dump($var);die();
     $detPayment = $this->detPaymentRepo->getModel();
     $cashMonthly = $this->cashMonthlyRepo->getModel();
     $detCash = $this->detCashRepo->getModel();
     //var_dump($request->input('id'));
     $cash = $this->cashRepo->find($request->cash_id);
     $payment = $this->paymentRepo->find($request->id);
     $update = new PaymentManager($payment, $request->only("Acuenta", "Saldo"));
     $update->save();
     $var['tipoPago'] = 'P';
     $verDeudas = $this->pendientAccountRepo->verSaldos($request->input("supplier_id"));
     /*if($request->input("methodPayment_id")==4){
             $request->merge(['Saldo'=>$verDeudas->Saldo-$SaldoAfavor]);
             $request->merge(['orderPurchase_id'=>$verDeudas->orderPurchase_id]);
             $request->merge(['supplier_id'=>$verDeudas->supplier_id]);
             $updateSaldoF=new pendientAccountManager($verDeudas,$request->all());
             $updateSaldoF->save();
       }*/
     if (intval($request->input('cash_id')) > 0) {
         //var_dump("hola");die();
         $detcash = new DetCashManager($detCash, $request->all());
         $detcash->save();
         $var['detCash_id'] = $detCash->id;
         $request->merge(["gastos" => floatval($cash->gastos) + floatval($var["montoPagado"])]);
         $request->merge(['fechaInicio' => $cash->fechaInicio]);
         $request->merge(['fechaFin' => $cash->fechaFin]);
         $request->merge(['montoInicial' => $cash->montoInicial]);
         $request->merge(['ingresos' => $cash->ingresos]);
         $request->merge(['montoBruto' => floatval($cash->montoBruto) - floatval($var["montoPagado"])]);
         $request->merge(['montoReal' => $cash->montoReal]);
         $request->merge(['descuadre' => $cash->descuadre]);
         $request->merge(['estado' => $cash->estado]);
         $request->merge(['notas' => $cash->notas]);
         $request->merge(['cashHeader_id' => $cash->cashHeader_id]);
         if ($cash->user_id == auth()->user()->id && $cash->estado == 1) {
             $request->merge(['user_id' => $cash->user_id]);
         } else {
             return response()->json(['estado' => 'Usted no tiene permisos sobre esta caja o la caja esta cerrada??']);
         }
         $cashr = new CashManager($cash, $request->all());
         $cashr->save();
     }
     if ($request->input('cajamensual') == true) {
         // $año=$this->yearRepo->findID($request->input("año"));
         //var_dump($request->input("año"));
         //$request->merge(["years_id"=>$año['id']]);
         $request->merge(["amount" => $var["montoPagado"]]);
         $request->merge(['descripcion' => "Pago a Proveedores"]);
         $request->merge(['expenseMonthlys_id' => 1]);
         //var_dump($request->detPayments["fecha"]);die();
         $request->merge(['fecha' => $request->detPayments["fecha"]]);
         $cashMontl = new CashMonthlyManager($cashMonthly, $request->all());
         $cashMontl->save();
         $var['cashMonthly_id'] = $cashMonthly->id;
     }
     $manager = new DetPaymentManager($detPayment, $var);
     $manager->save();
     $idpago = $detPayment->id;
     /* if($this->detPaymentRepo->validateDate(substr($request->exedetPayments['fecha'],0,10))){
            $request->detPayments['fecha'] = substr($request->detPayments['fecha'],0,10);
        }else{
           
            $request->detPayments['fecha'] = null;
        }*/
     // $detPayment->save();
     // $this->detPaymentRepo->consultDetpayments($provicional);
     $montoTotalPagado = 0;
     foreach ($this->detPaymentRepo->consultDetpayments($request->id) as $object) {
         $montoTotalPagado = $montoTotalPagado + floatval($object["montoPagado"]);
     }
     $payment1 = $this->paymentRepo->find($request->id);
     $request->merge(["Acuenta" => $montoTotalPagado]);
     if (floatval($payment1->MontoTotal) - $montoTotalPagado >= 0) {
         $request->merge(["Saldo" => floatval($payment1->MontoTotal) - $montoTotalPagado]);
     } else {
         return response()->json('error');
     }
     $manager = new PaymentManager($payment1, $request->only("Acuenta", "Saldo"));
     $manager->save();
     \DB::commit();
     return response()->json(['estado' => true, 'id' => $idpago, 'montoP' => $detPayment->Acuenta]);
 }
 public function edit(Request $request)
 {
     \DB::beginTransaction();
     $var = $request->detPayments;
     $detPayment = $this->detPaymentRepo->find($request->detpId);
     $pagoTemporal = $detPayment->montoPagado;
     $detpay = new DetPaymentManager($detPayment, $var);
     $detpay->save();
     $payment = $this->paymentRepo->find($request->id);
     $montoTotalPagado = 0;
     foreach ($this->detPaymentRepo->consultDetpayments($request->id) as $object) {
         $montoTotalPagado = $montoTotalPagado + floatval($object["montoPagado"]);
     }
     //$payment1 = $this->paymentRepo->find($provicional);
     $request->merge(["Acuenta" => $montoTotalPagado]);
     if (floatval($payment->MontoTotal) - $montoTotalPagado >= 0) {
         $request->merge(["Saldo" => floatval($payment->MontoTotal) - $montoTotalPagado]);
     } else {
         return response()->json('error');
     }
     $manager = new PaymentManager($payment, $request->only("Acuenta", "Saldo"));
     $manager->save();
     // $manager = new PaymentManager($payment,$request->only("Acuenta","Saldo"));
     // $manager->save();
     //=======================================================
     //var_dump($request->input('Saldo_F'));die();
     if (intval($request->input('Saldo_F')) > 0) {
         //var_dump($request->input("fecha"));die();
         $SaldosTemporales = $this->pendientAccountRepo->find2($detPayment['Saldo_F']);
         if ($SaldosTemporales != null) {
             //  var_dump($SaldosTemporales->Saldo);die();
             $request->merge(['Saldo' => floatval($SaldosTemporales->Saldo) + floatval($pagoTemporal)]);
             $request->merge(['Saldo' => floatval($request->input('Saldo')) - floatval($detPayment['montoPagado'])]);
             //var_dump($request->input("Saldo"));die();
             $request->merge(['orderPurchase_id' => $SaldosTemporales->orderPurchase_id]);
             $request->merge(['supplier_id' => $SaldosTemporales->supplier_id]);
             $request->merge(['estado' => 0]);
             $request->merge(["fecha" => $SaldosTemporales->fecha]);
             $insercount = new PendientAccountManager($SaldosTemporales, $request->all());
             $insercount->save();
         }
     }
     //=====================================================================
     //$provicional;
     if (intval($request->input('detCash_id')) > 0) {
         $detCash = $this->detCashRepo->find($request->input('detCash_id'));
         $cash = $this->cashRepo->find($detCash["cash_id"]);
         $request->merge(['montoCaja' => floatval($cash->montoBruto) + floatval($pagoTemporal)]);
         //var_dump(floatval($request->input('montoCaja')));
         $request->merge(['montoMovimientoEfectivo' => floatval($var["montoPagado"])]);
         $totalCajaACtual = $request->input('montoMovimientoEfectivo');
         //var_dump(floatval($totalCajaACtual));
         //$request->merge(['montoMovimientoEfectivo'=>floatval($totalCajaACtual)+floatval($var['montoPagado'])]);
         //$totalCajaACtual=$request->input('montoMovimientoEfectivo');
         //var_dump(floatval($totalCajaACtual));die();
         //$request->merge(["montoBruto"=>floatval($request->input('montoCaja')-floatval($pagoTemporal)])
         $request->merge(['montoFinal' => floatval($request->input('montoCaja')) - floatval($totalCajaACtual)]);
         $request->merge(['montoBruto' => floatval($request->input("montoFinal"))]);
         // var_dump(floatval($request->input('montoBruto')));die();
         $request->merge(["gastos" => floatval($cash->gastos) - floatval($pagoTemporal)]);
         $request->merge(["gastos" => floatval($request->input("gastos") + floatval($var["montoPagado"]))]);
         // var_dump($request->all());
         $request->merge(['fecha' => $detCash->fecha]);
         $request->merge(['montoMovimientoTarjeta' => 0]);
         $request->merge(['hora' => $detCash->hora]);
         $request->merge(['estado' => 1]);
         $request->merge(['cashMotive_id' => $detCash->cashMotive_id]);
         if ($cash->user_id == auth()->user()->id && $cash->estado == 1) {
             $request->merge(['user_id' => $cash->user_id]);
         } else {
             return response()->json(['estado' => 'Usted no tiene permisos sobre esta caja o la caja esta cerrada??']);
         }
         //   var_dump($request->all());die();
         $detcash = new DetCashManager($detCash, $request->all());
         $detcash->save();
         $request->merge(['fechaInicio' => $cash->fechaInicio]);
         $request->merge(['fechaFin' => $cash->fechaFin]);
         $request->merge(['montoInicial' => $cash->montoInicial]);
         $request->merge(['ingresos' => $cash->ingresos]);
         $request->merge(['montoReal' => $cash->montoReal]);
         $request->merge(['descuadre' => $cash->descuadre]);
         $request->merge(['estado' => $cash->estado]);
         $request->merge(['notas' => $cash->notas]);
         $request->merge(['cashHeader_id' => $cash->cashHeader_id]);
         $cashr = new CashManager($cash, $request->all());
         $cashr->save();
     }
     if (intval($request->input('cashMonthly_id')) > 0) {
         $cashMontly = $this->cashMonthlyRepo->find($request->input("cashMonthly_id"));
         //var_dump($año["id"]);die();
         $request->merge(["years_id" => $cashMontly->years_id]);
         $request->merge(["amount" => $var["montoPagado"]]);
         $request->merge(['descripcion' => "Pago a Proveedores"]);
         $request->merge(['expenseMonthlys_id' => 1]);
         $request->merge(['fecha' => $var["fecha"]]);
         $request->merge(['months_id' => $cashMontly->months_id]);
         $cashMontl = new CashMonthlyManager($cashMontly, $request->all());
         $cashMontl->save();
         //$var['cashMonthly_id']=$cashMonthly->id;
     }
     \DB::commit();
     //==============================
     return response()->json(['estado' => true, 'nombre' => $payment->nombre]);
 }