Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Log::info('Iniciando proceso de actualizacion de referencia de ventas');
     $sales = Sales::where('transaction_id', '-1')->get();
     foreach ($sales as $sale) {
         $ventasPorAplicar = DB::table('contabilidad_sales')->select('*')->whereRaw('credit_debit = ? and reference = ? ', ['credit', $sale->reference])->where('transaction_id', '<>', '-1')->groupBy('reference')->get();
         if (count($ventasPorAplicar) > 0) {
             // se encontraron referencias de venta nuevas
             foreach ($ventasPorAplicar as $ventaPorAplicar) {
                 $depositoAplicacionAnterior = DepositoAplicacion::where('venta_id', $sale->id)->get();
                 foreach ($depositoAplicacionAnterior as $depositoAplicacion) {
                     echo $depositoAplicacion->cantidad . ' ' . $depositoAplicacion->deposito_id . ' -- ' . $ventaPorAplicar->ammount . '-- ' . $ventaPorAplicar->ammount_applied . '-------';
                     if ($depositoAplicacion->estatus == 1) {
                         $deposito = new DepositoAplicacion(['deposito_id' => $depositoAplicacion->deposito_id, 'venta_id' => $ventaPorAplicar->id, 'estatus' => $depositoAplicacion->estatus, 'usuario_id' => $depositoAplicacion->usuario_id, 'cantidad' => $depositoAplicacion->cantidad]);
                         $ventaPorAplicar->ammount_applied = $depositoAplicacion->cantidad + ($ventaPorAplicar->ammount - $ventaPorAplicar->ammount_applied);
                     } else {
                         if (abs($depositoAplicacion->cantidad) >= $ventaPorAplicar->ammount - $ventaPorAplicar->ammount_applied) {
                             $ventaPorAplicar->ammount_applied = $depositoAplicacion->ammount;
                             $depositoAplicacion->cantidad = $depositoAplicacion->cantidad - ($ventaPorAplicar->ammount - $ventaPorAplicar->ammount_applied);
                         } else {
                             $ventaPorAplicar->ammount_applied = $ventaPorAplicar->ammount - $ventaPorAplicar->ammount_applied - $depositoAplicacion->cantidad;
                             $depositoAplicacion->cantidad = 0;
                         }
                         $deposito = new DepositoAplicacion(['deposito_id' => $depositoAplicacion->deposito_id, 'venta_id' => $ventaPorAplicar->id, 'estatus' => $depositoAplicacion->estatus, 'usuario_id' => $depositoAplicacion->usuario_id, 'cantidad' => -1 * ($ventaPorAplicar->ammount_applied - $ventaPorAplicar->ammount)]);
                     }
                     $deposito->save();
                     ${$ventaPorAplicar}->update();
                     $depositoAplicacion->delete();
                 }
             }
         }
     }
     Log::info('Finalizando proceso de actualizacion de referencia de ventas');
 }
Пример #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Log::info('Iniciando proceso de lectura de ventas');
     $disk = Storage::disk("sales");
     $files = $disk->allfiles();
     foreach ($files as $file) {
         Log::info('Lectura de archivos para procesar');
         $sales_log = SalesLog::where("file_name", $file)->first();
         if (!isset($sales_log)) {
             Log::info('Procesando archivo ' . $file);
             $contents = $disk->get($file);
             $count = 0;
             $description = '';
             $op_location = '';
             $cl_location = '';
             $rows = str_getcsv($contents, "\n");
             //parse the rows
             foreach ($rows as $row) {
                 $datas = str_getcsv($row, '|');
                 if (count($datas) == 17) {
                     $sales = new Sales(['transaction_id' => $datas[0], 'reference' => $datas[1], 'ra_start_date' => $datas[2], 'ra_end_date' => $datas[3], 'factura_uuid' => $datas[4], 'ammount' => $datas[5], 'ammount_applied' => 0, 'credit_debit' => $datas[6], 'payment_method' => $datas[7], 'ra_total' => $datas[8], 'customer_number' => $datas[9], 'op_location' => $datas[10], 'cl_location' => $datas[11], 'gl_account' => $datas[12], 'concept' => $datas[13], 'description' => $datas[14], 'date' => $datas[15], 'factura_number' => $datas[16]]);
                     $sales->save();
                     $count++;
                     $op_location = $datas[10];
                     $cl_location = $datas[11];
                     $description = $datas[14];
                     $payment_method = PaymentMethod::where("payment_method", $datas[7])->first();
                     if (!isset($payment_method)) {
                         Log::info('Agregando nuevo metodo de pago ' . $datas[7]);
                         $payment_method_ = new PaymentMethod(['payment_method' => $datas[7]]);
                         $payment_method_->save();
                     }
                 }
             }
             $sales_log_ = new SalesLog(['file_name' => $file, 'process' => $count, 'description' => $description, 'op_location' => $op_location, 'cl_location' => $cl_location]);
             $sales_log_->save();
             Log::info('Archivo procesado ' . $file . ' renglones procesados ' . $count);
         }
     }
     Log::info('Finalizando proceso de lectura de ventas');
 }
Пример #3
0
 public function index()
 {
     if (Sentinel::check()) {
         if (Sentinel::hasAccess('pendientes.view')) {
             $usuario = User::find($this->user_auth->id);
             $oficinas = array();
             foreach ($usuario->plazas as $plazas) {
                 array_push($oficinas, $plazas->Oficina);
             }
             DB::enableQueryLog();
             $ventasPendientes = Sales::select('*', DB::raw('SUM(ammount) as ammount, SUM(ammount_applied) as ammount_applied '))->whereRaw('credit_debit = ?  ', ['credit'])->groupBy('reference')->get();
             return view('contabilidad::Earrings.index', compact("ventasPendientes"));
         } else {
             alert()->error('No tiene permisos para acceder a esta area.', 'Oops!')->persistent('Cerrar');
             return back();
         }
     } else {
         return redirect('login');
     }
 }
Пример #4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function guardarReferencias(DepositoReferenciasRequest $request)
 {
     $depositoRef = json_decode($request->deposito);
     $deposito = new Deposito(['banco' => $depositoRef->{'banco'}, 'fecha' => $depositoRef->{'fecha'}, 'monto' => $depositoRef->{'monto'}, 'moneda' => $depositoRef->{'moneda'}, 'cuenta_contable' => $depositoRef->{'cuenta_contable'}, 'complementaria' => $depositoRef->{'complementaria'}, 'tipo_pago' => $depositoRef->{'tipo_pago'}, 'folio' => $depositoRef->{'folio'}, 'global' => isset($depositoRef->{'global'}) ? true : false, 'usuario_id' => $depositoRef->{'usuario_id'}, 'comban' => isset($depositoRef->{'comban'}) ? $depositoRef->{'comban'} : "", 'estatus' => 0]);
     $deposito->save();
     $referencias = json_decode($request->referencias);
     foreach ($referencias as $key => $value) {
         if ($value->isNew) {
             $ventas = Sales::where('reference', $value->id)->where('credit_debit', 'credit')->get();
             $montoAplicar = $value->monto;
             if (count($ventas) > 0) {
                 // si se encontraron ventas con referencia ingresada
                 foreach ($ventas as $venta) {
                     //si el monto de la venta es mayor al monto aplicado
                     //entonces aplicamos
                     if ($venta->ammount > $venta->ammount_applied) {
                         $montoRestante = $venta->ammount - $venta->ammount_applied;
                         // si el monto a aplicar es mayor al monto aplicado descontamos del monto a aplicar
                         if ($montoAplicar > $montoRestante) {
                             $monto = $montoRestante;
                             $montoAplicar = $montoAplicar - $montoRestante;
                         } else {
                             $monto = $montoAplicar;
                             $montoAplicar = 0;
                         }
                         if ($monto > 0) {
                             $depositoAplicacion = new DepositoAplicacion(['venta_id' => $venta->id, 'deposito_id' => $deposito->id, 'usuario_id' => $this->user_auth->id, 'cantidad' => $monto]);
                             $venta->ammount_applied = $venta->ammount_applied + $monto;
                             $depositoAplicacion->save();
                         }
                         $venta->update();
                     }
                 }
             } else {
                 $ventaNueva = new Sales(['transaction_id' => '-1', 'reference' => $value->id, 'ra_start_date' => Carbon::now(), 'ra_end_date' => Carbon::now(), 'factura_uuid' => "", 'ammount' => 0, 'ammount_applied' => $montoAplicar, 'credit_debit' => 'credit', 'payment_method' => '', 'ra_total' => 0, 'customer_number' => '', 'op_location' => '', 'cl_location' => '', 'gl_account' => '', 'concept' => '', 'description' => '', 'date' => Carbon::now(), 'factura_number' => '']);
                 $ventaNueva->save();
                 $depositoAplicacion = new DepositoAplicacion(['venta_id' => $ventaNueva->id, 'deposito_id' => $deposito->id, 'usuario_id' => $this->user_auth->id, 'cantidad' => $montoAplicar]);
                 $depositoAplicacion->save();
             }
         }
     }
     flash()->success('Las referencias de venta se han almacenado correctamente.');
     $deposito = new Deposito();
     $cuentas = Cuentas::cuentasArray($this->user_auth->id);
     $cuentasDls = Cuentas::cuentasDolaresArray();
     return view('contabilidad::Deposits.index', compact('deposito', 'cuentas', 'cuentasDls'));
 }