public function edit(Request $request)
 {
     \DB::beginTransaction();
     $pendientAccount = $this->pendientAccountRepo->find($request->id);
     $cash = $this->cashRepo->find($request->input('cash_id'));
     $detCash = $this->detCashRepo->getModel();
     $manager = new PendientAccountManager($pendientAccount, $request->except("fecha"));
     $manager->save();
     if (!empty($cash)) {
         //===============================================================
         $request->merge(["montoMovimientoTarjeta" => 0]);
         $request->merge(["montoMovimientoEfectivo" => $request->input("nuevoSaldo")]);
         $request->merge(["estado" => 1]);
         $request->merge(["observacion" => "ingreso por pago de saldos anteriores"]);
         $request->merge(["cashMotive_id" => 5]);
         $request->merge(["montoCaja" => $cash->montoBruto]);
         $request->merge(["montoFinal" => floatval($cash->montoBruto) + floatval($request->input("nuevoSaldo"))]);
         $detcash = new DetCashManager($detCash, $request->all());
         $detcash->save();
         $var['detCash_id'] = $detCash->id;
         $request->merge(["gastos" => $cash->gastos]);
         $request->merge(['fechaInicio' => $cash->fechaInicio]);
         $request->merge(['fechaFin' => $cash->fechaFin]);
         $request->merge(['montoInicial' => $cash->montoInicial]);
         $request->merge(['ingresos' => floatval($cash->ingresos) + floatval($request->input("nuevoSaldo"))]);
         $request->merge(['montoBruto' => floatval($cash->montoBruto) + floatval($request->input("nuevoSaldo"))]);
         $request->merge(['montoReal' => $cash->montoReal]);
         $request->merge(['descuadre' => $cash->descuadre]);
         $request->merge(['notas' => $cash->notas]);
         $request->merge(['cashHeader_id' => $cash->cashHeader_id]);
         $cashr = new CashManager($cash, $request->all());
         $cashr->save();
         \DB::commit();
     }
     //===============================================================
     return response()->json(['estado' => true]);
 }
 public function edit(Request $request)
 {
     $varDetOrders = $request->detOrder;
     $varPayment = $request->payment;
     $movimiento = $request->movimiento;
     if ($movimiento['montoMovimientoEfectivo'] > 0) {
         //---create movimiento---
         //var_dump($request->movimiento);die();
         $detCashrepo;
         $movimiento['observacion'] = "temporal";
         $detCashrepo = new DetCashRepo();
         $movimientoSave = $detCashrepo->getModel();
         $insertarMovimiento = new DetCashManager($movimientoSave, $movimiento);
         $insertarMovimiento->save();
         //---Autualizar Caja---
         $cajaAct = $request->caja;
         $cashrepo;
         $cashrepo = new CashRepo();
         $cajaSave = $cashrepo->getModel();
         $cash1 = $cashrepo->find($cajaAct["id"]);
         $manager1 = new CashManager($cash1, $cajaAct);
         $manager1->save();
         //----------------
         $salePaymentRepo;
         $salePaymentRepo = new SalePaymentRepo();
         $payment = $salePaymentRepo->find($varPayment['id']);
         $manager = new SalePaymentManager($payment, $varPayment);
         $manager->save();
     }
     $detOrderSaleRepo;
     foreach ($varDetOrders as $object) {
         $detOrderSaleRepo = new DetOrderSaleRepo();
         $detorderSale = $detOrderSaleRepo->find($object['id']);
         $manager = new DetOrderSaleManager($detorderSale, $object);
         $manager->save();
         $stokRepo;
         $stokRepo = new StockRepo();
         $cajaSave = $stokRepo->getModel();
         $stockOri = $stokRepo->find($object['id']);
         $stock = $stokRepo->find($object['idStock']);
         if ($object['estad'] == true) {
             $stock->stockPedidos = $stock->stockPedidos - $object['canPendiente'];
         } else {
             $stock->stockPedidos = $stock->stockPedidos + $object['canPendiente'];
         }
         $stock->save();
     }
     $orderSale = $this->orderSaleRepo->find($request->id);
     $manager = new OrderSaleManager($orderSale, $request->all());
     $manager->save();
     return response()->json(['estado' => true, 'nombre' => $orderSale->nombre]);
 }
 public function create(Request $request)
 {
     \DB::beginTransaction();
     $var = $request->detPayments;
     //var_dump("Hola"); die();
     $detPayment = $this->saleDetPaymentRepo->getModel();
     //$cashMonthly=$this->cashMonthlyRepo->getModel();
     $detCash = $this->detCashRepo->getModel();
     $cash = $this->cashRepo->find($request->cash_id);
     $payment = $this->salePaymentRepo->find($request->id);
     $update = new SalePaymentManager($payment, $request->only("Acuenta", "Saldo"));
     $update->save();
     $var['tipoPago'] = 'P';
     //$verDeudas=$this->pendientAccountRepo->verSaldos($request->input("supplier_id"));
     //if(intval($request->input('cash_id'))>0){
     $detcash = new DetCashManager($detCash, $request->all());
     $detcash->save();
     $var['detCash_id'] = $detCash->id;
     $request->merge(["ingresos" => floatval($cash->ingresos) + floatval($var["monto"])]);
     $request->merge(['fechaInicio' => $cash->fechaInicio]);
     $request->merge(['fechaFin' => $cash->fechaFin]);
     $request->merge(['montoInicial' => $cash->montoInicial]);
     $request->merge(['gastos' => $cash->gastos]);
     $request->merge(['montoBruto' => floatval($cash->montoBruto) + floatval($var["monto"])]);
     $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){
     
         $request->merge(["amount"=>$var["montoPagado"]]);
         $request->merge(['descripcion'=>"Pago a Proveedores"]);
         $request->merge(['expenseMonthlys_id'=>1]);
     
         $request->merge(['fecha'=>$request->detPayments["fecha"]]);
         $cashMontl = new CashMonthlyManager($cashMonthly,$request->all());
         $cashMontl->save();
         $var['cashMonthly_id']=$cashMonthly->id;
     }*/
     $manager = new SaleDetPaymentManager($detPayment, $var);
     $manager->save();
     $idpago = $detPayment->id;
     $monto = 0;
     foreach ($this->saleDetPaymentRepo->consultDetpayments($request->id) as $object) {
         $monto = $monto + floatval($object["monto"]);
     }
     $payment1 = $this->salePaymentRepo->find($request->id);
     $request->merge(["Acuenta" => $monto]);
     if (floatval($payment1->MontoTotal) - $monto >= 0) {
         $request->merge(["Saldo" => floatval($payment1->MontoTotal) - $monto]);
     } else {
         return response()->json('error');
     }
     $manager = new SalePaymentManager($payment1, $request->only("Acuenta", "Saldo"));
     $manager->save();
     \DB::commit();
     return response()->json(['estado' => true, 'id' => $idpago, 'montoP' => $detPayment->Acuenta]);
 }
Example #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Request $request)
 {
     \DB::beginTransaction();
     $varDetOrders = $request->detOrder;
     $varPayment = $request->payment;
     $movimiento = $request->movimiento;
     if ($movimiento['montoMovimientoEfectivo'] > 0) {
         //---create movimiento---
         //var_dump($request->movimiento);die();
         $detCashrepo;
         $movimiento['observacion'] = "temporal";
         $movimiento['fecha'] = date('Y-m-d');
         $movimiento['hora'] = date('H:i:s');
         $detCashrepo = new DetCashRepo();
         $movimientoSave = $detCashrepo->getModel();
         $insertarMovimiento = new DetCashManager($movimientoSave, $movimiento);
         $insertarMovimiento->save();
         //---Autualizar Caja---
         $cajaAct = $request->caja;
         $cashrepo;
         $cashrepo = new CashRepo();
         $cajaSave = $cashrepo->getModel();
         $cash1 = $cashrepo->find($cajaAct["id"]);
         $manager1 = new CashManager($cash1, $cajaAct);
         $manager1->save();
         //----------------
         $salePaymentRepo;
         $salePaymentRepo = new SalePaymentRepo();
         //$payment = $salePaymentRepo->find($varPayment['id']);
         $payment = $salePaymentRepo->find($varPayment['idPAY']);
         $manager = new SalePaymentManager($payment, $varPayment);
         $manager->save();
     }
     $HeadStockRepo;
     $codigoHeadIS = 0;
     //$detOrderSaleRepo;
     foreach ($varDetOrders as $object) {
         //$detOrderSaleRepo = new DetSaleRepo;
         //$detorderSale = $detOrderSaleRepo->find($object['id']);
         //$manager = new DetSaleManager($detorderSale,$object);
         //$manager->save();
         if (!empty($object['idStock'])) {
             $stokRepo;
             $stokRepo = new StockRepo();
             $cajaSave = $stokRepo->getModel();
             $stockOri = $stokRepo->find($object['id']);
             $stock = $stokRepo->find($object['idStock']);
             //+++if ($object['estad']==true) {
             $stock->stockActual = $stock->stockActual + $object['cantidad'];
             //+++}else{
             //+++$stock->stockPedidos= $stock->stockPedidos+$object['canPendiente'];
             //+++}
             $stock->save();
             //--------------reporte stock------------
             $object["variant_id"] = $object['vari'];
             if ($codigoHeadIS === 0) {
                 $object["warehouses_id"] = $object['idAlmacen'];
                 //$object["cantidad_llegado"]=$cantidaCalculada;
                 //$object['descripcion']='Entrada por compra';
                 //$object['tipo']='Entrada Venta';
                 $object['tipo'] = 'Entrada-Anulado';
                 $object["user_id"] = auth()->user()->id;
                 //$object["Fecha"]=$request->input("fechaPedido");
                 $object["Fecha"] = date('Y-m-d H:i:s');
                 $HeadStockRepo = new HeadInputStockRepo();
                 $HeadStock = $HeadStockRepo->getModel();
                 $HeadStockinsert = new HeadInputStockManager($HeadStock, $object);
                 $HeadStockinsert->save();
                 $codigoHeadIS = $HeadStock->id;
             }
             $object['headInputStock_id'] = $codigoHeadIS;
             $object["producto"] = $object['nameProducto'] . "(" . $object['NombreAtributos'] . ")";
             $object["cantidad_llegado"] = $object['cantidad'];
             $object['descripcion'] = 'Entrada-Venta-Anulada';
             $inputRepo;
             $inputRepo = new InputStockRepo();
             $inputstock = $inputRepo->getModel();
             $inputInsert = new InputStockManager($inputstock, $object);
             $inputInsert->save();
         }
         //---------------------------------------
     }
     $orderSale = $this->saleRepo->find($request->id);
     if ($request->input('estado') == '3') {
         $request->merge(array('fechaAnulado' => date('Y-m-d H:i:s')));
     }
     $manager = new SaleManager($orderSale, $request->all());
     $manager->save();
     $serviceID = $orderSale->service_id;
     if (!empty($serviceID)) {
         $servicio = $this->serviceRepo->find($serviceID);
         $request->merge(["estado" => 4]);
         $request->merge(["numeroServicio" => $servicio->numeroServicio]);
         $request->merge(["fechaServicio" => $servicio->fechaServicio]);
         $request->merge(["tipo" => $servicio->tipo]);
         $request->merge(["cliente" => $servicio->cliente]);
         $request->merge(["ruc" => $servicio->ruc]);
         $request->merge(["direcion" => $servicio->direcion]);
         $request->merge(["telefono" => $servicio->telefono]);
         $request->merge(["empresa" => $servicio->empresa]);
         $request->merge(["descripcion" => $servicio->descripcion]);
         $request->merge(["modelo" => $servicio->modelo]);
         $request->merge(["serie" => $servicio->serie]);
         $request->merge(["accesorios" => $servicio->accesorios]);
         $request->merge(["diagnostico" => $servicio->diagnostico]);
         $request->merge(["accionCorrectiva" => $servicio->accionCorrectiva]);
         $request->merge(["ordenTrabajo" => $servicio->ordenTrabajo]);
         $request->merge(["customer_id" => $servicio->customer_id]);
         $request->merge(["employee_id" => $servicio->employee_id]);
         $request->merge(["user_id" => $servicio->user_id]);
         $manager = new ServiceManager($servicio, $request->all());
         $manager->save();
     }
     \DB::commit();
     return response()->json(['estado' => true, 'nombre' => $orderSale->nombre]);
 }
 public function destroy(Request $request)
 {
     \DB::beginTransaction();
     $detPayment = $this->servicePaymentRepo->find($request->detpId);
     $pagoTemporal = $detPayment->monto;
     $detPayment->delete();
     //$MontotalTemp=$request->input('monto');
     //$AcuentaTemp=$request->input('Acuenta');
     //$request->merge(['Acuenta'=>$AcuentaTemp-$pagoTemporal]);
     //$AcuentaTemp2=$request->input('Acuenta');
     //$request->merge(['Saldo'=>$MontotalTemp-$AcuentaTemp2]);
     //$payment = $this->salePaymentRepo->find($request->id);
     //      $montoTotalPagado=0;
     //foreach($this->servicePaymentRepo->consultDetpayments($request->id) as $object){
     //  $montoTotalPagado=$montoTotalPagado+floatval($object["monto"]);
     //}
     //$request->merge(["Acuenta"=>$montoTotalPagado]);
     //if(floatval($payment->MontoTotal)-$montoTotalPagado>=0){
     //    $request->merge(["Saldo"=>floatval($payment->MontoTotal)-$montoTotalPagado]);
     //}else{
     //    return response()->json('error');
     //}
     //$manager = new SalePaymentManager($payment,$request->only("Acuenta","Saldo"));
     //$manager->save();
     $detcash = $this->detCashRepo->find($request->input("detCash_id"));
     $cash = $this->cashRepo->find($detcash->cash_id);
     $request->merge(["ingresos" => floatval($cash->ingresos) - floatval($pagoTemporal)]);
     $request->merge(['montoBruto' => floatval($cash->montoBruto) - floatval($pagoTemporal)]);
     $request->merge(['fechaInicio' => $cash->fechaInicio]);
     $request->merge(['fechaFin' => $cash->fechaFin]);
     $request->merge(['montoInicial' => $cash->montoInicial]);
     $request->merge(['gastos' => $cash->gastos]);
     $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();
     $detcash->delete();
     \DB::commit();
     return response()->json(['estado' => true]);
 }
 public function create(Request $request)
 {
     $orderSale = $this->separateSaleRepo->getModel();
     $var = $request->detOrders;
     $payment = $request->salePayment;
     $saledetPayments = $request->saledetPayments;
     $manager = new SeparateSaleManager($orderSale, $request->all());
     $manager->save();
     /*
            if($this->purchaseRepo->validateDate(substr($request->input('fechaEntrega'),0,10))){
                 $order->fechaEntrega = substr($request->input('fechaEntrega'),0,10);
             }else{
                
                 $order->fechaEntrega = null;
             }*/
     $orderSale->save();
     $temporal = $orderSale->id;
     //---create movimiento---
     $movimiento = $request->movimiento;
     $detCashrepo;
     $movimiento['observacion'] = $temporal;
     $detCashrepo = new DetCashRepo();
     $movimientoSave = $detCashrepo->getModel();
     $insertarMovimiento = new DetCashManager($movimientoSave, $movimiento);
     $insertarMovimiento->save();
     $detCash_id = $movimientoSave->id;
     //---Autualizar Caja---
     $cajaAct = $request->caja;
     $cashrepo;
     $cashrepo = new CashRepo();
     $cajaSave = $cashrepo->getModel();
     $cash1 = $cashrepo->find($cajaAct["id"]);
     $manager1 = new CashManager($cash1, $cajaAct);
     $manager1->save();
     //----------------
     $salePaymentrepo;
     $payment['separateSale_id'] = $temporal;
     $salePaymentrepo = new SalePaymentRepo();
     $paymentSave = $salePaymentrepo->getModel();
     $insertarpayment = new SalePaymentManager($paymentSave, $payment);
     $insertarpayment->save();
     $paymentSave->save();
     $temporal1 = $paymentSave->id;
     //--------------------------
     $saledetPaymentrepo;
     foreach ($saledetPayments as $object1) {
         $object1['salePayment_id'] = $temporal1;
         $object1['detCash_id'] = $detCash_id;
         $saledetPaymentrepo = new SaleDetPaymentRepo();
         $insertar = new SaleDetPaymentManager($saledetPaymentrepo->getModel(), $object1);
         $insertar->save();
         $saledetPaymentrepo = null;
     }
     $detOrderrepox;
     foreach ($var as $object) {
         $object['separateSale_id'] = $temporal;
         $detOrderrepox = new DetSeparateSaleRepo();
         $insertar = new DetSeparateSaleManager($detOrderrepox->getModel(), $object);
         $insertar->save();
         $detOrderrepox = null;
         //-------------------------------------
         $stockmodel = new StockRepo();
         $object['warehouse_id'] = $object['idAlmacen'];
         $object["variant_id"] = $object['vari'];
         $stockac = $stockmodel->encontrar($object["variant_id"], $object['warehouse_id']);
         if (!empty($stockac)) {
             if ($object["equivalencia"] == null) {
                 $object["stockSeparados"] = $stockac->stockSeparados + $object["cantidad"];
                 //
             } else {
                 $object["stockSeparados"] = $stockac->stockSeparados + $object["cantidad"] * $object["equivalencia"];
             }
             $manager = new StockManager($stockac, $object);
             $manager->save();
         } else {
         }
         $stockac = null;
         //-----------------------------------------------------
     }
     return response()->json(['estado' => true, 'nombres' => $orderSale->nombres]);
 }
 public function destroy(Request $request)
 {
     \DB::beginTransaction();
     $detPayment = $this->saleDetPaymentRepo->find($request->detpId);
     $pagoTemporal = $detPayment->monto;
     //$monto=$detPayment->montoPagado;
     $detPayment->delete();
     $MontotalTemp = $request->input('monto');
     $AcuentaTemp = $request->input('Acuenta');
     $request->merge(['Acuenta' => $AcuentaTemp - $pagoTemporal]);
     $AcuentaTemp2 = $request->input('Acuenta');
     $request->merge(['Saldo' => $MontotalTemp - $AcuentaTemp2]);
     $payment = $this->salePaymentRepo->find($request->id);
     $montoTotalPagado = 0;
     foreach ($this->saleDetPaymentRepo->consultDetpayments($request->id) as $object) {
         $montoTotalPagado = $montoTotalPagado + floatval($object["monto"]);
     }
     $request->merge(["Acuenta" => $montoTotalPagado]);
     if (floatval($payment->MontoTotal) - $montoTotalPagado >= 0) {
         $request->merge(["Saldo" => floatval($payment->MontoTotal) - $montoTotalPagado]);
     } else {
         return response()->json('error');
     }
     $manager = new SalePaymentManager($payment, $request->only("Acuenta", "Saldo"));
     $manager->save();
     /*if(intval($request->input('Saldo_F'))>0){
                    $SaldosTemporales =$this->pendientAccountRepo->find2($request->input('Saldo_F'));
                    if($SaldosTemporales!=null){
                    $request->merge(['Saldo'=>floatval($SaldosTemporales->Saldo)+floatval($pagoTemporal)]);
                    $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();
                   }
                
       }+*/
     //if(intval($request->input('detCash_id'))==true){
     $detcash = $this->detCashRepo->find($request->input("detCash_id"));
     $cash = $this->cashRepo->find($detcash->cash_id);
     $request->merge(["ingresos" => floatval($cash->ingresos) - floatval($pagoTemporal)]);
     $request->merge(['montoBruto' => floatval($cash->montoBruto) - floatval($pagoTemporal)]);
     $request->merge(['fechaInicio' => $cash->fechaInicio]);
     $request->merge(['fechaFin' => $cash->fechaFin]);
     $request->merge(['montoInicial' => $cash->montoInicial]);
     $request->merge(['gastos' => $cash->gastos]);
     $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();
     $detcash->delete();
     //}
     //no se
     //if(intval($request->input("cashMonthly_id"))>0){
     //   $cashMontl =$this->cashMonthlyRepo->find($request->input("cashMonthly_id"));
     // $cashMontl->delete();
     // }
     \DB::commit();
     return response()->json(['estado' => true, 'nombre' => $payment->nombre]);
 }
Example #8
0
 public function edit(Request $request)
 {
     $cash = $this->cashRepo->find($request->id);
     $manager = new CashManager($cash, $request->all());
     $manager->save();
     return response()->json(['estado' => true, 'nombre' => $cash->nombre]);
 }
 public function destroyPagos2(Request $request)
 {
     //var_dump($request->tipo);die();
     \DB::beginTransaction();
     $idCompra = "";
     if ($request->input('tipo') == 'Caja') {
         $detCash = $this->detCashRepo->find($request->id);
         $caja = $this->cashRepo->find($detCash->cash_id);
         if ($caja->estado == 1) {
             $idCompra = $detCash->expense_id;
             $request->merge(['gastos' => floatval($caja->gastos) - floatval($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();
             $detCash->delete();
         } else {
             return response()->json(['estado' => true, 'nota' => 'Caja Cerrada']);
         }
     } else {
         $cashMonthly = $this->cashMonthlyRepo->find($request->id);
         $idCompra = $cashMonthly->expense_id;
         $cashMonthly->delete();
     }
     $otherPhead = $this->expenseRepo->find($idCompra);
     $request->merge(["montoPagado" => floatval($otherPhead->montoPagado) - floatval($request->input("monto"))]);
     $request->merge(["Saldo" => floatval($otherPhead->Saldo) + floatval($request->input("monto"))]);
     $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();
     //Event::fire('update.brand',$brand->all());
     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]);
 }